Commit e025bc82ead969b49937e0733c7647d7bcd42ae1
1 parent
614c64ab
Exists in
master
and in
29 other branches
ActionItem8: organizing the routes and making the necessary changes to the application
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@423 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
6 changed files
with
50 additions
and
14 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -77,14 +77,26 @@ module ApplicationHelper |
77 | 77 | content_tag('div', @virtual_community.name, :id => 'virtual_community_identification') |
78 | 78 | end |
79 | 79 | |
80 | + # TODO: test this helper | |
81 | + # TODO: remove the absolute path | |
80 | 82 | def link_to_cms(text, profile = nil, options = {}) |
81 | 83 | profile ||= current_user.login |
82 | - link_to text, "/cms/#{profile}", options | |
84 | + link_to text, cms_path(:profile => profile), options | |
83 | 85 | end |
84 | 86 | |
85 | 87 | def link_to_profile(text, profile = nil, options = {}) |
86 | 88 | profile ||= current_user.login |
87 | - link_to text, "/#{profile}", options | |
89 | + link_to text, profile_path(:profile => profile) , options | |
90 | + end | |
91 | + | |
92 | + def link_to_homepage(text, profile = nil, options = {}) | |
93 | + profile ||= current_user.login | |
94 | + link_to text, homepage_path(:profile => profile) , options | |
95 | + end | |
96 | + | |
97 | + def link_to_myprofile(text, url = {}, profile = nil, options = {}) | |
98 | + profile ||= current_user.login | |
99 | + link_to text, { :profile => profile }.merge(url), options | |
88 | 100 | end |
89 | 101 | |
90 | 102 | # TODO: add the actual links |
... | ... | @@ -92,10 +104,10 @@ module ApplicationHelper |
92 | 104 | def user_links |
93 | 105 | links = [ |
94 | 106 | ( link_to(_('My account'), { :controller => 'account' }) ), |
95 | - ( link_to_profile(_('My home page')) ), | |
107 | + ( link_to_homepage(_('My home page')) ), | |
96 | 108 | ( link_to_cms(_('Manage content')) ), |
97 | 109 | ( link_to (_('Manage layout')), :controller => 'edit_template' ), |
98 | - ( link_to(_('My enterprises'), { :controller => 'enterprise' }) ), | |
110 | + ( link_to_myprofile(_('My enterprises'), { :controller => 'enterprise' }) ), | |
99 | 111 | ].join("\n") |
100 | 112 | content_tag('span', links, :id => 'user_links') |
101 | 113 | end | ... | ... |
app/models/profile.rb
config/routes.rb
... | ... | @@ -23,27 +23,39 @@ ActionController::Routing::Routes.draw do |map| |
23 | 23 | ## Controllers that are profile-specific (for profile admins ) |
24 | 24 | ###################################################### |
25 | 25 | # profile customization - "My profile" |
26 | - map.connect 'myprofile', :controller => 'myprofile' | |
27 | - map.connect 'myprofile/:profile/:controller/:action/:id', :controller => /(edit_template|enterprise)/ | |
26 | + map.myprofile 'myprofile', :controller => 'myprofile' | |
27 | + map.myprofile 'myprofile/:profile/:controller/:action/:id', :controller => /(enterprise)/ | |
28 | 28 | # content administration |
29 | - map.connect 'cms/:profile/:action/:id', :controller => 'cms' | |
29 | + map.cms 'cms/:profile/:action/:id', :controller => 'cms' | |
30 | 30 | |
31 | 31 | ###################################################### |
32 | 32 | ## Controllers that are used by environment admin |
33 | 33 | ###################################################### |
34 | 34 | # administrative tasks for a virtual community |
35 | - map.connect 'admin', :controller => 'admin_panel' | |
36 | - map.connect 'admin/:controller/:action/:id', :controller => /(admin_panel|features|manage_tags)/ | |
35 | + map.admin 'admin', :controller => 'admin_panel' | |
36 | + map.admin 'admin/:controller/:action/:id', :controller => /(admin_panel|features|manage_tags|edit_template)/ | |
37 | 37 | |
38 | 38 | ###################################################### |
39 | 39 | ## Controllers that are used by system admin |
40 | 40 | ###################################################### |
41 | 41 | # administrative tasks for a virtual community |
42 | - map.connect 'system', :controller => 'system' | |
43 | - map.connect 'system/:controller/:action/:id' | |
42 | + map.system 'system', :controller => 'system' | |
43 | + map.system 'system/:controller/:action/:id', :controller => // | |
44 | 44 | |
45 | + | |
46 | + ###################################################### | |
47 | + ## Test controllers. | |
48 | + ## FIXME: this should not be needed | |
49 | + ###################################################### | |
50 | + map.connect 'test/:action/:id', :controller => 'test' | |
51 | + | |
52 | + ###################################################### | |
53 | + ## Public controllers | |
54 | + ###################################################### | |
55 | + | |
56 | + map.profile 'profile/:profile/:controller', :controller => 'profile' | |
45 | 57 | # *content viewing* |
46 | 58 | # XXX this route must come last so other tasks have priority over it. |
47 | - map.connect ':profile/*page', :controller => 'content_viewer', :action => 'view_page' | |
59 | + map.homepage ':profile/*page', :controller => 'content_viewer', :action => 'view_page' | |
48 | 60 | |
49 | 61 | end | ... | ... |
test/functional/enterprise_controller_test.rb
... | ... | @@ -13,9 +13,19 @@ class EnterpriseControllerTest < Test::Unit::TestCase |
13 | 13 | @response = ActionController::TestResponse.new |
14 | 14 | end |
15 | 15 | |
16 | + # FIXME: this should be generic | |
17 | + def get(action, params = {}) | |
18 | + super(action, {:profile => 'ze'}.merge(params)) | |
19 | + end | |
20 | + | |
21 | + # FIXME: this should be generic | |
22 | + def post(action, params = {}) | |
23 | + super(action, {:profile => 'ze'}.merge(params)) | |
24 | + end | |
25 | + | |
16 | 26 | def test_logged_with_one_enterprise_index |
17 | 27 | login_as 'ze' |
18 | - get :index | |
28 | + get :index, :profile => 'ze' | |
19 | 29 | assert_response :redirect |
20 | 30 | assert_redirected_to :action => 'show' |
21 | 31 | ... | ... |
test/integration/routing_test.rb
... | ... | @@ -26,7 +26,7 @@ class RoutingTest < ActionController::IntegrationTest |
26 | 26 | end |
27 | 27 | |
28 | 28 | def test_edit_template |
29 | - assert_routing('/myprofile/ze/edit_template', :controller => 'edit_template', :action => 'index', :profile => 'ze') | |
29 | + assert_routing('/admin/edit_template', :controller => 'edit_template', :action => 'index') | |
30 | 30 | end |
31 | 31 | |
32 | 32 | # virtual community administrative controllers (admin/*) | ... | ... |
test/unit/profile_test.rb