Commit fae4fffee060c7315f9951c92bc41e3528ee4f1c
1 parent
04a4dd14
Exists in
master
and in
28 other branches
ActionItem7: initial comatose integration work
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@206 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
13 changed files
with
136 additions
and
9 deletions
Show diff stats
... | ... | @@ -0,0 +1,13 @@ |
1 | +class ContentViewerController < ApplicationController | |
2 | + | |
3 | + def view_page | |
4 | + path = params[:page].clone | |
5 | + path.unshift(params[:profile]) | |
6 | + @path = path.join('/') | |
7 | + @page = Comatose::Page.find_by_path(@path) | |
8 | + if @page.nil? | |
9 | + render :action => 'not_found', :status => 404 | |
10 | + end | |
11 | + end | |
12 | + | |
13 | +end | ... | ... |
app/models/profile.rb
... | ... | @@ -3,6 +3,14 @@ |
3 | 3 | # which by default is the one returned by VirtualCommunity:default. |
4 | 4 | class Profile < ActiveRecord::Base |
5 | 5 | |
6 | + after_create do |profile| | |
7 | + homepage = Comatose::Page.new | |
8 | + homepage.title = profile.name | |
9 | + homepage.parent = Comatose::Page.root | |
10 | + homepage.slug = profile.identifier | |
11 | + homepage.save! | |
12 | + end | |
13 | + | |
6 | 14 | act_as_flexible_template |
7 | 15 | |
8 | 16 | # Valid identifiers must match this format. |
... | ... | @@ -33,7 +41,7 @@ class Profile < ActiveRecord::Base |
33 | 41 | self[:identifier] = value |
34 | 42 | end |
35 | 43 | |
36 | - validates_presence_of :identifier | |
44 | + validates_presence_of :identifier, :name | |
37 | 45 | validates_format_of :identifier, :with => IDENTIFIER_FORMAT |
38 | 46 | validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS |
39 | 47 | ... | ... |
app/models/user.rb
... | ... | @@ -5,7 +5,7 @@ require 'digest/sha1' |
5 | 5 | class User < ActiveRecord::Base |
6 | 6 | |
7 | 7 | after_create do |user| |
8 | - Person.create!(:identifier => user.login, :user_id => user.id) | |
8 | + Person.create!(:identifier => user.login, :name => user.login, :user_id => user.id) | |
9 | 9 | end |
10 | 10 | |
11 | 11 | has_one :person | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +<%= @page.to_html %> | ... | ... |
config/routes.rb
... | ... | @@ -15,6 +15,7 @@ ActionController::Routing::Routes.draw do |map| |
15 | 15 | |
16 | 16 | # user account controller |
17 | 17 | map.connect 'account/:action', :controller => 'account' |
18 | + map.connect 'doc', :controller => 'doc' | |
18 | 19 | |
19 | 20 | # administrative tasks for a virtual community |
20 | 21 | map.connect 'admin/:controller/:action/:id' |
... | ... | @@ -22,9 +23,8 @@ ActionController::Routing::Routes.draw do |map| |
22 | 23 | # profile customization for profiles |
23 | 24 | map.connect 'customize/:profile/:controller/:action/:id' |
24 | 25 | |
25 | - # Allow downloading Web Service WSDL as a file with an extension | |
26 | - # instead of a file named 'wsdl' | |
27 | - map.connect ':controller/service.wsdl', :action => 'wsdl' | |
26 | + # content viewwing: | |
27 | + map.connect ':profile/*page', :controller => 'content_viewer', :action => 'view_page' | |
28 | 28 | |
29 | 29 | # Install the default route as the lowest priority. |
30 | 30 | map.connect ':controller/:action/:id' | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +module Comatose | |
2 | + class Page < ActiveRecord::Base | |
3 | + set_table_name 'comatose_pages' | |
4 | + acts_as_versioned :if_changed => [:title, :slug, :keywords, :body] | |
5 | + end | |
6 | +end | |
7 | + | |
8 | +class AddComatoseSupport < ActiveRecord::Migration | |
9 | + | |
10 | + # Schema for Comatose version 0.7+ | |
11 | + def self.up | |
12 | + create_table :comatose_pages do |t| | |
13 | + t.column "parent_id", :integer | |
14 | + t.column "full_path", :text, :default => '' | |
15 | + t.column "title", :string, :limit => 255 | |
16 | + t.column "slug", :string, :limit => 255 | |
17 | + t.column "keywords", :string, :limit => 255 | |
18 | + t.column "body", :text | |
19 | + t.column "filter_type", :string, :limit => 25, :default => "Textile" | |
20 | + t.column "author", :string, :limit => 255 | |
21 | + t.column "position", :integer, :default => 0 | |
22 | + t.column "version", :integer | |
23 | + t.column "updated_on", :datetime | |
24 | + t.column "created_on", :datetime | |
25 | + end | |
26 | + Comatose::Page.create_versioned_table | |
27 | + puts "Creating the default 'Home Page'..." | |
28 | + Comatose::Page.create( :title=>'Home Page', :body=>"h1. Welcome\n\nYour content goes here...", :author=>'System' ) | |
29 | + end | |
30 | + | |
31 | + def self.down | |
32 | + Comatose::Page.drop_versioned_table | |
33 | + drop_table :comatose_pages | |
34 | + end | |
35 | + | |
36 | +end | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +require File.dirname(__FILE__) + '/../test_helper' | |
2 | +require 'content_viewer_controller' | |
3 | + | |
4 | +# Re-raise errors caught by the controller. | |
5 | +class ContentViewerController; def rescue_action(e) raise e end; end | |
6 | + | |
7 | +class ContentViewerControllerTest < Test::Unit::TestCase | |
8 | + | |
9 | + fixtures :domains, :virtual_communities, :users, :profiles | |
10 | + | |
11 | + def setup | |
12 | + @controller = ContentViewerController.new | |
13 | + @request = ActionController::TestRequest.new | |
14 | + @response = ActionController::TestResponse.new | |
15 | + end | |
16 | + | |
17 | + def test_should_display_homepage | |
18 | + uses_host 'anhetegua.net' | |
19 | + Profile.create!(:identifier => 'aprofile', :name => "A profile") | |
20 | + get :view_page, :profile => 'aprofile', :page => [] | |
21 | + assert_response :success | |
22 | + end | |
23 | + | |
24 | + def test_should_get_not_found_error_for_unexisting_page | |
25 | + uses_host 'anhetegua.net' | |
26 | + get :view_page, :profile => 'ze', :page => ['some_unexisting_page'] | |
27 | + assert_response 404 | |
28 | + end | |
29 | + | |
30 | + def test_should_get_not_found_error_for_unexisting_profile | |
31 | + Profile.delete_all | |
32 | + uses_host 'anhetegua' | |
33 | + get :view_page, :profile => 'some_unexisting_profile', :page => [] | |
34 | + assert_response 404 | |
35 | + end | |
36 | + | |
37 | +end | ... | ... |
test/integration/routing_test.rb
... | ... | @@ -3,11 +3,19 @@ require "#{File.dirname(__FILE__)}/../test_helper" |
3 | 3 | class RoutingTest < ActionController::IntegrationTest |
4 | 4 | |
5 | 5 | def test_features_controller |
6 | - assert_routing('admin/features', :controller => 'features', :action => 'index') | |
6 | + assert_routing('/admin/features', :controller => 'features', :action => 'index') | |
7 | 7 | end |
8 | 8 | |
9 | 9 | def test_account_controller |
10 | - assert_routing('account', :controller => 'account', :action => 'index') | |
10 | + assert_routing('/account', :controller => 'account', :action => 'index') | |
11 | + end | |
12 | + | |
13 | + def test_content_viewer_controller_for_profile_root | |
14 | + assert_routing('/ze', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze', :page => []) | |
15 | + end | |
16 | + | |
17 | + def test_content_viewer_controller_for_page_inside_profile | |
18 | + assert_routing('/ze/work/2007', :controller => 'content_viewer', :action => 'view_page', :profile => 'ze', :page => ['work', "2007"]) | |
11 | 19 | end |
12 | 20 | |
13 | 21 | end | ... | ... |
test/unit/profile_test.rb
1 | 1 | require File.dirname(__FILE__) + '/../test_helper' |
2 | 2 | |
3 | 3 | class ProfileTest < Test::Unit::TestCase |
4 | - fixtures :profiles, :virtual_communities, :users | |
4 | + fixtures :profiles, :virtual_communities, :users, :comatose_pages | |
5 | 5 | |
6 | 6 | def test_identifier_validation |
7 | 7 | p = Profile.new |
... | ... | @@ -46,4 +46,21 @@ class ProfileTest < Test::Unit::TestCase |
46 | 46 | end |
47 | 47 | end |
48 | 48 | |
49 | + # when a profile called a page named after it must also be created. | |
50 | + def test_should_create_homepage_when_creating_profile | |
51 | + Profile.create!(:identifier => 'newprofile', :name => 'New Profile') | |
52 | + page = Comatose::Page.find_by_path('newprofile') | |
53 | + assert_not_nil page | |
54 | + assert_equal 'New Profile', page.title | |
55 | + end | |
56 | + | |
57 | + def test_name_should_be_mandatory | |
58 | + p = Profile.new | |
59 | + p.valid? | |
60 | + assert p.errors.invalid?(:name) | |
61 | + p.name = 'a very unprobable name' | |
62 | + p.valid? | |
63 | + assert !p.errors.invalid?(:name) | |
64 | + end | |
65 | + | |
49 | 66 | end | ... | ... |
test/unit/user_test.rb
... | ... | @@ -4,7 +4,7 @@ class UserTest < Test::Unit::TestCase |
4 | 4 | # Be sure to include AuthenticatedTestHelper in test/test_helper.rb instead. |
5 | 5 | # Then, you can remove it from this and the functional test. |
6 | 6 | include AuthenticatedTestHelper |
7 | - fixtures :users | |
7 | + fixtures :users, :comatose_pages | |
8 | 8 | |
9 | 9 | def test_should_create_user |
10 | 10 | assert_difference User, :count do | ... | ... |