diff --git a/app/controllers/content_viewer_controller.rb b/app/controllers/content_viewer_controller.rb new file mode 100644 index 0000000..859facc --- /dev/null +++ b/app/controllers/content_viewer_controller.rb @@ -0,0 +1,13 @@ +class ContentViewerController < ApplicationController + + def view_page + path = params[:page].clone + path.unshift(params[:profile]) + @path = path.join('/') + @page = Comatose::Page.find_by_path(@path) + if @page.nil? + render :action => 'not_found', :status => 404 + end + end + +end diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb new file mode 100644 index 0000000..2fcdbf6 --- /dev/null +++ b/app/helpers/content_viewer_helper.rb @@ -0,0 +1,2 @@ +module ContentViewerHelper +end diff --git a/app/models/profile.rb b/app/models/profile.rb index 1b0feaf..fc2bda1 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,6 +3,14 @@ # which by default is the one returned by VirtualCommunity:default. class Profile < ActiveRecord::Base + after_create do |profile| + homepage = Comatose::Page.new + homepage.title = profile.name + homepage.parent = Comatose::Page.root + homepage.slug = profile.identifier + homepage.save! + end + act_as_flexible_template # Valid identifiers must match this format. @@ -33,7 +41,7 @@ class Profile < ActiveRecord::Base self[:identifier] = value end - validates_presence_of :identifier + validates_presence_of :identifier, :name validates_format_of :identifier, :with => IDENTIFIER_FORMAT validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS diff --git a/app/models/user.rb b/app/models/user.rb index bcf450e..e77ffbb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,7 +5,7 @@ require 'digest/sha1' class User < ActiveRecord::Base after_create do |user| - Person.create!(:identifier => user.login, :user_id => user.id) + Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id) end has_one :person diff --git a/app/views/content_viewer/not_found.rhtml b/app/views/content_viewer/not_found.rhtml new file mode 100644 index 0000000..7520639 --- /dev/null +++ b/app/views/content_viewer/not_found.rhtml @@ -0,0 +1,2 @@ +

<%= _('There is not such page: %s') % (content_tag('tt', @path)) %>

+ diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml new file mode 100644 index 0000000..993f6a4 --- /dev/null +++ b/app/views/content_viewer/view_page.rhtml @@ -0,0 +1 @@ +<%= @page.to_html %> diff --git a/config/routes.rb b/config/routes.rb index 253f512..e1c489c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,6 +15,7 @@ ActionController::Routing::Routes.draw do |map| # user account controller map.connect 'account/:action', :controller => 'account' + map.connect 'doc', :controller => 'doc' # administrative tasks for a virtual community map.connect 'admin/:controller/:action/:id' @@ -22,9 +23,8 @@ ActionController::Routing::Routes.draw do |map| # profile customization for profiles map.connect 'customize/:profile/:controller/:action/:id' - # Allow downloading Web Service WSDL as a file with an extension - # instead of a file named 'wsdl' - map.connect ':controller/service.wsdl', :action => 'wsdl' + # content viewwing: + map.connect ':profile/*page', :controller => 'content_viewer', :action => 'view_page' # Install the default route as the lowest priority. map.connect ':controller/:action/:id' diff --git a/db/migrate/009_add_comatose_support.rb b/db/migrate/009_add_comatose_support.rb new file mode 100644 index 0000000..a88309d --- /dev/null +++ b/db/migrate/009_add_comatose_support.rb @@ -0,0 +1,36 @@ +module Comatose + class Page < ActiveRecord::Base + set_table_name 'comatose_pages' + acts_as_versioned :if_changed => [:title, :slug, :keywords, :body] + end +end + +class AddComatoseSupport < ActiveRecord::Migration + + # Schema for Comatose version 0.7+ + def self.up + create_table :comatose_pages do |t| + t.column "parent_id", :integer + t.column "full_path", :text, :default => '' + t.column "title", :string, :limit => 255 + t.column "slug", :string, :limit => 255 + t.column "keywords", :string, :limit => 255 + t.column "body", :text + t.column "filter_type", :string, :limit => 25, :default => "Textile" + t.column "author", :string, :limit => 255 + t.column "position", :integer, :default => 0 + t.column "version", :integer + t.column "updated_on", :datetime + t.column "created_on", :datetime + end + Comatose::Page.create_versioned_table + puts "Creating the default 'Home Page'..." + Comatose::Page.create( :title=>'Home Page', :body=>"h1. Welcome\n\nYour content goes here...", :author=>'System' ) + end + + def self.down + Comatose::Page.drop_versioned_table + drop_table :comatose_pages + end + +end diff --git a/test/fixtures/comatose_pages.yml b/test/fixtures/comatose_pages.yml new file mode 100644 index 0000000..d1ec923 --- /dev/null +++ b/test/fixtures/comatose_pages.yml @@ -0,0 +1,3 @@ +root: + id: 1 + title: Root page diff --git a/test/functional/content_viewer_controller_test.rb b/test/functional/content_viewer_controller_test.rb new file mode 100644 index 0000000..c047f7c --- /dev/null +++ b/test/functional/content_viewer_controller_test.rb @@ -0,0 +1,37 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'content_viewer_controller' + +# Re-raise errors caught by the controller. +class ContentViewerController; def rescue_action(e) raise e end; end + +class ContentViewerControllerTest < Test::Unit::TestCase + + fixtures :domains, :virtual_communities, :users, :profiles + + def setup + @controller = ContentViewerController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + def test_should_display_homepage + uses_host 'anhetegua.net' + Profile.create!(:identifier => 'aprofile', :name => "A profile") + get :view_page, :profile => 'aprofile', :page => [] + assert_response :success + end + + def test_should_get_not_found_error_for_unexisting_page + uses_host 'anhetegua.net' + get :view_page, :profile => 'ze', :page => ['some_unexisting_page'] + assert_response 404 + end + + def test_should_get_not_found_error_for_unexisting_profile + Profile.delete_all + uses_host 'anhetegua' + get :view_page, :profile => 'some_unexisting_profile', :page => [] + assert_response 404 + end + +end diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 8785bf8..c9f8e14 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -3,11 +3,19 @@ require "#{File.dirname(__FILE__)}/../test_helper" class RoutingTest < ActionController::IntegrationTest def test_features_controller - assert_routing('admin/features', :controller => 'features', :action => 'index') + assert_routing('/admin/features', :controller => 'features', :action => 'index') end def test_account_controller - assert_routing('account', :controller => 'account', :action => 'index') + assert_routing('/account', :controller => 'account', :action => 'index') + end + + def test_content_viewer_controller_for_profile_root + assert_routing('/ze', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze', :page => []) + end + + def test_content_viewer_controller_for_page_inside_profile + assert_routing('/ze/work/2007', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze', :page => ['work', "2007"]) end end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 12958e3..a3b5b04 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../test_helper' class ProfileTest < Test::Unit::TestCase - fixtures :profiles, :virtual_communities, :users + fixtures :profiles, :virtual_communities, :users, :comatose_pages def test_identifier_validation p = Profile.new @@ -46,4 +46,21 @@ class ProfileTest < Test::Unit::TestCase end end + # when a profile called a page named after it must also be created. + def test_should_create_homepage_when_creating_profile + Profile.create!(:identifier => 'newprofile', :name => 'New Profile') + page = Comatose::Page.find_by_path('newprofile') + assert_not_nil page + assert_equal 'New Profile', page.title + end + + def test_name_should_be_mandatory + p = Profile.new + p.valid? + assert p.errors.invalid?(:name) + p.name = 'a very unprobable name' + p.valid? + assert !p.errors.invalid?(:name) + end + end diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb index eaecbcf..5738a71 100644 --- a/test/unit/user_test.rb +++ b/test/unit/user_test.rb @@ -4,7 +4,7 @@ class UserTest < Test::Unit::TestCase # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead. # Then, you can remove it from this and the functional test. include AuthenticatedTestHelper - fixtures :users + fixtures :users, :comatose_pages def test_should_create_user assert_difference User, :count do -- libgit2 0.21.2