Commit 614c64ab4ea059f713185cc981af353da918057b
1 parent
9c9f424b
Exists in
master
and in
29 other branches
ActionItem8: changing routing scheme
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@422 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
9 changed files
with
56 additions
and
29 deletions
Show diff stats
app/models/profile.rb
@@ -21,9 +21,10 @@ class Profile < ActiveRecord::Base | @@ -21,9 +21,10 @@ class Profile < ActiveRecord::Base | ||
21 | # These names cannot be used as identifiers for Profiles | 21 | # These names cannot be used as identifiers for Profiles |
22 | RESERVED_IDENTIFIERS = %w[ | 22 | RESERVED_IDENTIFIERS = %w[ |
23 | admin | 23 | admin |
24 | - customize | ||
25 | - cms | ||
26 | system | 24 | system |
25 | + myprofile | ||
26 | + profile | ||
27 | + cms | ||
27 | community | 28 | community |
28 | ] | 29 | ] |
29 | 30 |
config/routes.rb
@@ -19,22 +19,31 @@ ActionController::Routing::Routes.draw do |map| | @@ -19,22 +19,31 @@ ActionController::Routing::Routes.draw do |map| | ||
19 | # user account controller | 19 | # user account controller |
20 | map.connect 'account/:action', :controller => 'account' | 20 | map.connect 'account/:action', :controller => 'account' |
21 | 21 | ||
22 | - # profile customization | ||
23 | - map.connect 'customize/:profile/edit_template/:action/:id', :controller => 'edit_template' | ||
24 | - | ||
25 | - # content administration | 22 | + ###################################################### |
23 | + ## Controllers that are profile-specific (for profile admins ) | ||
24 | + ###################################################### | ||
25 | + # profile customization - "My profile" | ||
26 | + map.connect 'myprofile', :controller => 'myprofile' | ||
27 | + map.connect 'myprofile/:profile/:controller/:action/:id', :controller => /(edit_template|enterprise)/ | ||
28 | + # content administration | ||
26 | map.connect 'cms/:profile/:action/:id', :controller => 'cms' | 29 | map.connect 'cms/:profile/:action/:id', :controller => 'cms' |
27 | 30 | ||
31 | + ###################################################### | ||
32 | + ## Controllers that are used by environment admin | ||
33 | + ###################################################### | ||
28 | # administrative tasks for a virtual community | 34 | # administrative tasks for a virtual community |
29 | - map.connect 'admin', :controller => 'admin_panel', :action => 'index' | ||
30 | - map.connect 'admin/:controller/:action/:id' | 35 | + map.connect 'admin', :controller => 'admin_panel' |
36 | + map.connect 'admin/:controller/:action/:id', :controller => /(admin_panel|features|manage_tags)/ | ||
31 | 37 | ||
38 | + ###################################################### | ||
39 | + ## Controllers that are used by system admin | ||
40 | + ###################################################### | ||
41 | + # administrative tasks for a virtual community | ||
42 | + map.connect 'system', :controller => 'system' | ||
43 | + map.connect 'system/:controller/:action/:id' | ||
32 | 44 | ||
33 | # *content viewing* | 45 | # *content viewing* |
34 | # XXX this route must come last so other tasks have priority over it. | 46 | # XXX this route must come last so other tasks have priority over it. |
35 | map.connect ':profile/*page', :controller => 'content_viewer', :action => 'view_page' | 47 | map.connect ':profile/*page', :controller => 'content_viewer', :action => 'view_page' |
36 | 48 | ||
37 | - # no default route | ||
38 | - # map.connect ':controller/:action/:id' | ||
39 | - | ||
40 | end | 49 | end |
test/integration/activate_enterprise_test.rb
@@ -6,14 +6,14 @@ class ActivateEnterpriseTest < ActionController::IntegrationTest | @@ -6,14 +6,14 @@ class ActivateEnterpriseTest < ActionController::IntegrationTest | ||
6 | def test_activate_approved_enterprise | 6 | def test_activate_approved_enterprise |
7 | login('ze', 'test') | 7 | login('ze', 'test') |
8 | 8 | ||
9 | - get '/admin/enterprise' | 9 | + get '/myprofile/ze/enterprise' |
10 | assert_response :redirect | 10 | assert_response :redirect |
11 | 11 | ||
12 | follow_redirect! | 12 | follow_redirect! |
13 | assert_response :success | 13 | assert_response :success |
14 | - assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/activate/5'} | 14 | + assert_tag :tag => 'a', :attributes => {:href => '/myprofile/ze/enterprise/activate/5'} |
15 | 15 | ||
16 | - post '/admin/enterprise/activate/5' | 16 | + post '/myprofile/ze/enterprise/activate/5' |
17 | assert_response :redirect | 17 | assert_response :redirect |
18 | 18 | ||
19 | follow_redirect! | 19 | follow_redirect! |
test/integration/edit_enterprise_test.rb
@@ -3,30 +3,30 @@ require "#{File.dirname(__FILE__)}/../test_helper" | @@ -3,30 +3,30 @@ require "#{File.dirname(__FILE__)}/../test_helper" | ||
3 | class EditEnterpriseTest < ActionController::IntegrationTest | 3 | class EditEnterpriseTest < ActionController::IntegrationTest |
4 | all_fixtures | 4 | all_fixtures |
5 | def test_edit_an_enterprise | 5 | def test_edit_an_enterprise |
6 | - get '/admin/enterprise' | 6 | + get '/myprofile/ze/enterprise' |
7 | assert_response :redirect | 7 | assert_response :redirect |
8 | 8 | ||
9 | login('ze', 'test') | 9 | login('ze', 'test') |
10 | 10 | ||
11 | - get '/admin/enterprise' | 11 | + get '/myprofile/ze/enterprise' |
12 | assert_response :redirect | 12 | assert_response :redirect |
13 | 13 | ||
14 | follow_redirect! | 14 | follow_redirect! |
15 | assert_response :success | 15 | assert_response :success |
16 | - assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/edit/5'} | 16 | + assert_tag :tag => 'a', :attributes => {:href => '/myprofile/ze/enterprise/edit/5'} |
17 | 17 | ||
18 | - get '/admin/enterprise/edit/5' | 18 | + get '/myprofile/ze/enterprise/edit/5' |
19 | assert_response :success | 19 | assert_response :success |
20 | assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} | 20 | assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} |
21 | 21 | ||
22 | - post '/admin/enterprise/update/5', :enterprise => {'name' => 'new_name' } | 22 | + post '/myprofile/ze/enterprise/update/5', :enterprise => {'name' => 'new_name' } |
23 | assert_response :redirect | 23 | assert_response :redirect |
24 | 24 | ||
25 | follow_redirect! | 25 | follow_redirect! |
26 | assert_response :redirect | 26 | assert_response :redirect |
27 | 27 | ||
28 | follow_redirect! | 28 | follow_redirect! |
29 | - assert_equal '/admin/enterprise/show/5', path | 29 | + assert_equal '/myprofile/ze/enterprise/show/5', path |
30 | 30 | ||
31 | end | 31 | end |
32 | end | 32 | end |
test/integration/register_enterprise_test.rb
@@ -4,24 +4,24 @@ class RegisterEnterpriseTest < ActionController::IntegrationTest | @@ -4,24 +4,24 @@ class RegisterEnterpriseTest < ActionController::IntegrationTest | ||
4 | all_fixtures | 4 | all_fixtures |
5 | 5 | ||
6 | def test_register_new_enterprise | 6 | def test_register_new_enterprise |
7 | - get '/admin/enterprise' | 7 | + get '/myprofile/ze/enterprise' |
8 | assert_response :redirect | 8 | assert_response :redirect |
9 | 9 | ||
10 | login('ze','test') | 10 | login('ze','test') |
11 | 11 | ||
12 | - get '/admin/enterprise' | 12 | + get '/myprofile/ze/enterprise' |
13 | assert_response :redirect | 13 | assert_response :redirect |
14 | 14 | ||
15 | follow_redirect! | 15 | follow_redirect! |
16 | assert_response :success | 16 | assert_response :success |
17 | - assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/register_form'} | 17 | + assert_tag :tag => 'a', :attributes => {:href => '/myprofile/ze/enterprise/register_form'} |
18 | 18 | ||
19 | - get '/admin/enterprise/register_form' | 19 | + get '/myprofile/ze/enterprise/register_form' |
20 | assert_response :success | 20 | assert_response :success |
21 | assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} | 21 | assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} |
22 | assert_tag :tag => 'input', :attributes => {:name => 'enterprise[identifier]'} | 22 | assert_tag :tag => 'input', :attributes => {:name => 'enterprise[identifier]'} |
23 | 23 | ||
24 | - post '/admin/enterprise/register', :enterprise => {'name' => 'new_enterprise', 'identifier' => 'enterprise_new'} | 24 | + post '/myprofile/ze/enterprise/register', :enterprise => {'name' => 'new_enterprise', 'identifier' => 'enterprise_new'} |
25 | assert_response :redirect | 25 | assert_response :redirect |
26 | 26 | ||
27 | follow_redirect! | 27 | follow_redirect! |
test/integration/routing_test.rb
@@ -26,7 +26,7 @@ class RoutingTest < ActionController::IntegrationTest | @@ -26,7 +26,7 @@ class RoutingTest < ActionController::IntegrationTest | ||
26 | end | 26 | end |
27 | 27 | ||
28 | def test_edit_template | 28 | def test_edit_template |
29 | - assert_routing('/customize/ze/edit_template', :controller => 'edit_template', :action => 'index', :profile => 'ze') | 29 | + assert_routing('/myprofile/ze/edit_template', :controller => 'edit_template', :action => 'index', :profile => 'ze') |
30 | end | 30 | end |
31 | 31 | ||
32 | # virtual community administrative controllers (admin/*) | 32 | # virtual community administrative controllers (admin/*) |
test/integration/search_enterprise_test.rb
@@ -5,14 +5,14 @@ class SearchEnterpriseTest < ActionController::IntegrationTest | @@ -5,14 +5,14 @@ class SearchEnterpriseTest < ActionController::IntegrationTest | ||
5 | 5 | ||
6 | def test_search_by_name_or_tag | 6 | def test_search_by_name_or_tag |
7 | login('ze', 'test') | 7 | login('ze', 'test') |
8 | - get '/admin/enterprise' | 8 | + get '/myprofile/ze/enterprise' |
9 | assert_response :redirect | 9 | assert_response :redirect |
10 | 10 | ||
11 | follow_redirect! | 11 | follow_redirect! |
12 | assert_response :success | 12 | assert_response :success |
13 | assert_tag :tag => 'input', :attributes => {'name', 'query'} | 13 | assert_tag :tag => 'input', :attributes => {'name', 'query'} |
14 | 14 | ||
15 | - get '/admin/enterprise/search', :query => 'bla' | 15 | + get '/myprofile/ze/enterprise/search', :query => 'bla' |
16 | assert_response :success | 16 | assert_response :success |
17 | end | 17 | end |
18 | end | 18 | end |
test/unit/person_test.rb
@@ -13,7 +13,7 @@ class PersonTest < Test::Unit::TestCase | @@ -13,7 +13,7 @@ class PersonTest < Test::Unit::TestCase | ||
13 | end | 13 | end |
14 | 14 | ||
15 | def test_can_associate_to_a_profile | 15 | def test_can_associate_to_a_profile |
16 | - pr = Profile.new(:identifier => 'profile', :name => 'profile') | 16 | + pr = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile') |
17 | assert pr.save | 17 | assert pr.save |
18 | pe = User.create(:login => 'person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person | 18 | pe = User.create(:login => 'person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person |
19 | assert pe.save | 19 | assert pe.save |
test/unit/profile_test.rb
@@ -104,4 +104,21 @@ class ProfileTest < Test::Unit::TestCase | @@ -104,4 +104,21 @@ class ProfileTest < Test::Unit::TestCase | ||
104 | assert_nil Profile.new.info | 104 | assert_nil Profile.new.info |
105 | end | 105 | end |
106 | 106 | ||
107 | + def test_should_avoid_reserved_identifiers | ||
108 | + assert_invalid_identifier 'admin' | ||
109 | + assert_invalid_identifier 'system' | ||
110 | + assert_invalid_identifier 'myprofile' | ||
111 | + assert_invalid_identifier 'profile' | ||
112 | + assert_invalid_identifier 'cms' | ||
113 | + assert_invalid_identifier 'community' | ||
114 | + end | ||
115 | + | ||
116 | + private | ||
117 | + | ||
118 | + def assert_invalid_identifier(id) | ||
119 | + profile = Profile.new(:identifier => id) | ||
120 | + assert !profile.valid? | ||
121 | + assert profile.errors.invalid?(:identifier) | ||
122 | + end | ||
123 | + | ||
107 | end | 124 | end |