From 614c64ab4ea059f713185cc981af353da918057b Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 7 Sep 2007 19:44:35 +0000 Subject: [PATCH] ActionItem8: changing routing scheme --- app/models/profile.rb | 5 +++-- config/routes.rb | 27 ++++++++++++++++++--------- test/integration/activate_enterprise_test.rb | 6 +++--- test/integration/edit_enterprise_test.rb | 12 ++++++------ test/integration/register_enterprise_test.rb | 10 +++++----- test/integration/routing_test.rb | 2 +- test/integration/search_enterprise_test.rb | 4 ++-- test/unit/person_test.rb | 2 +- test/unit/profile_test.rb | 17 +++++++++++++++++ 9 files changed, 56 insertions(+), 29 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index e8774f6..f5c8e6a 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -21,9 +21,10 @@ class Profile < ActiveRecord::Base # These names cannot be used as identifiers for Profiles RESERVED_IDENTIFIERS = %w[ admin - customize - cms system + myprofile + profile + cms community ] diff --git a/config/routes.rb b/config/routes.rb index aa14a37..e2b286f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -19,22 +19,31 @@ ActionController::Routing::Routes.draw do |map| # user account controller map.connect 'account/:action', :controller => 'account' - # profile customization - map.connect 'customize/:profile/edit_template/:action/:id', :controller => 'edit_template' - - # content administration + ###################################################### + ## Controllers that are profile-specific (for profile admins ) + ###################################################### + # profile customization - "My profile" + map.connect 'myprofile', :controller => 'myprofile' + map.connect 'myprofile/:profile/:controller/:action/:id', :controller => /(edit_template|enterprise)/ + # content administration map.connect 'cms/:profile/:action/:id', :controller => 'cms' + ###################################################### + ## Controllers that are used by environment admin + ###################################################### # administrative tasks for a virtual community - map.connect 'admin', :controller => 'admin_panel', :action => 'index' - map.connect 'admin/:controller/:action/:id' + map.connect 'admin', :controller => 'admin_panel' + map.connect 'admin/:controller/:action/:id', :controller => /(admin_panel|features|manage_tags)/ + ###################################################### + ## Controllers that are used by system admin + ###################################################### + # administrative tasks for a virtual community + map.connect 'system', :controller => 'system' + map.connect 'system/:controller/:action/:id' # *content viewing* # XXX this route must come last so other tasks have priority over it. map.connect ':profile/*page', :controller => 'content_viewer', :action => 'view_page' - # no default route - # map.connect ':controller/:action/:id' - end diff --git a/test/integration/activate_enterprise_test.rb b/test/integration/activate_enterprise_test.rb index 1c175c5..6494db1 100644 --- a/test/integration/activate_enterprise_test.rb +++ b/test/integration/activate_enterprise_test.rb @@ -6,14 +6,14 @@ class ActivateEnterpriseTest < ActionController::IntegrationTest def test_activate_approved_enterprise login('ze', 'test') - get '/admin/enterprise' + get '/myprofile/ze/enterprise' assert_response :redirect follow_redirect! assert_response :success - assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/activate/5'} + assert_tag :tag => 'a', :attributes => {:href => '/myprofile/ze/enterprise/activate/5'} - post '/admin/enterprise/activate/5' + post '/myprofile/ze/enterprise/activate/5' assert_response :redirect follow_redirect! diff --git a/test/integration/edit_enterprise_test.rb b/test/integration/edit_enterprise_test.rb index 503c1fb..7eb0929 100644 --- a/test/integration/edit_enterprise_test.rb +++ b/test/integration/edit_enterprise_test.rb @@ -3,30 +3,30 @@ require "#{File.dirname(__FILE__)}/../test_helper" class EditEnterpriseTest < ActionController::IntegrationTest all_fixtures def test_edit_an_enterprise - get '/admin/enterprise' + get '/myprofile/ze/enterprise' assert_response :redirect login('ze', 'test') - get '/admin/enterprise' + get '/myprofile/ze/enterprise' assert_response :redirect follow_redirect! assert_response :success - assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/edit/5'} + assert_tag :tag => 'a', :attributes => {:href => '/myprofile/ze/enterprise/edit/5'} - get '/admin/enterprise/edit/5' + get '/myprofile/ze/enterprise/edit/5' assert_response :success assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} - post '/admin/enterprise/update/5', :enterprise => {'name' => 'new_name' } + post '/myprofile/ze/enterprise/update/5', :enterprise => {'name' => 'new_name' } assert_response :redirect follow_redirect! assert_response :redirect follow_redirect! - assert_equal '/admin/enterprise/show/5', path + assert_equal '/myprofile/ze/enterprise/show/5', path end end diff --git a/test/integration/register_enterprise_test.rb b/test/integration/register_enterprise_test.rb index ee62d46..93bd434 100644 --- a/test/integration/register_enterprise_test.rb +++ b/test/integration/register_enterprise_test.rb @@ -4,24 +4,24 @@ class RegisterEnterpriseTest < ActionController::IntegrationTest all_fixtures def test_register_new_enterprise - get '/admin/enterprise' + get '/myprofile/ze/enterprise' assert_response :redirect login('ze','test') - get '/admin/enterprise' + get '/myprofile/ze/enterprise' assert_response :redirect follow_redirect! assert_response :success - assert_tag :tag => 'a', :attributes => {:href => '/admin/enterprise/register_form'} + assert_tag :tag => 'a', :attributes => {:href => '/myprofile/ze/enterprise/register_form'} - get '/admin/enterprise/register_form' + get '/myprofile/ze/enterprise/register_form' assert_response :success assert_tag :tag => 'input', :attributes => {:name => 'enterprise[name]'} assert_tag :tag => 'input', :attributes => {:name => 'enterprise[identifier]'} - post '/admin/enterprise/register', :enterprise => {'name' => 'new_enterprise', 'identifier' => 'enterprise_new'} + post '/myprofile/ze/enterprise/register', :enterprise => {'name' => 'new_enterprise', 'identifier' => 'enterprise_new'} assert_response :redirect follow_redirect! diff --git a/test/integration/routing_test.rb b/test/integration/routing_test.rb index 60312d6..4011ee6 100644 --- a/test/integration/routing_test.rb +++ b/test/integration/routing_test.rb @@ -26,7 +26,7 @@ class RoutingTest < ActionController::IntegrationTest end def test_edit_template - assert_routing('/customize/ze/edit_template', :controller => 'edit_template', :action => 'index', :profile => 'ze') + assert_routing('/myprofile/ze/edit_template', :controller => 'edit_template', :action => 'index', :profile => 'ze') end # virtual community administrative controllers (admin/*) diff --git a/test/integration/search_enterprise_test.rb b/test/integration/search_enterprise_test.rb index 7f287f9..fd17349 100644 --- a/test/integration/search_enterprise_test.rb +++ b/test/integration/search_enterprise_test.rb @@ -5,14 +5,14 @@ class SearchEnterpriseTest < ActionController::IntegrationTest def test_search_by_name_or_tag login('ze', 'test') - get '/admin/enterprise' + get '/myprofile/ze/enterprise' assert_response :redirect follow_redirect! assert_response :success assert_tag :tag => 'input', :attributes => {'name', 'query'} - get '/admin/enterprise/search', :query => 'bla' + get '/myprofile/ze/enterprise/search', :query => 'bla' assert_response :success end end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 94a72f7..e7d645a 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -13,7 +13,7 @@ class PersonTest < Test::Unit::TestCase end def test_can_associate_to_a_profile - pr = Profile.new(:identifier => 'profile', :name => 'profile') + pr = Profile.new(:identifier => 'mytestprofile', :name => 'My test profile') assert pr.save pe = User.create(:login => 'person', :email => 'person@test.net', :password => 'dhoe', :password_confirmation => 'dhoe').person assert pe.save diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index c4c7994..0b74489 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -104,4 +104,21 @@ class ProfileTest < Test::Unit::TestCase assert_nil Profile.new.info end + def test_should_avoid_reserved_identifiers + assert_invalid_identifier 'admin' + assert_invalid_identifier 'system' + assert_invalid_identifier 'myprofile' + assert_invalid_identifier 'profile' + assert_invalid_identifier 'cms' + assert_invalid_identifier 'community' + end + + private + + def assert_invalid_identifier(id) + profile = Profile.new(:identifier => id) + assert !profile.valid? + assert profile.errors.invalid?(:identifier) + end + end -- libgit2 0.21.2