Commit a96e874cbd578722b3d799c571a9cb6abb008218
1 parent
74456fc1
Exists in
master
and in
29 other branches
ActionItem154: refactoring: unifying manage_communities and memberships controlles into the later
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1405 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
54 additions
and
87 deletions
Show diff stats
app/controllers/my_profile/manage_communities_controller.rb
... | ... | @@ -1,17 +0,0 @@ |
1 | -class ManageCommunitiesController < MyProfileController | |
2 | - | |
3 | - def index | |
4 | - @communities = profile.community_memberships | |
5 | - end | |
6 | - | |
7 | - def new | |
8 | - @community = Community.new(params[:community]) | |
9 | - if request.post? | |
10 | - if @community.save | |
11 | - @community.add_member(profile) | |
12 | - redirect_to :action => 'index' | |
13 | - end | |
14 | - end | |
15 | - end | |
16 | - | |
17 | -end |
app/controllers/my_profile/memberships_controller.rb
... | ... | @@ -12,4 +12,14 @@ class MembershipsController < MyProfileController |
12 | 12 | end |
13 | 13 | end |
14 | 14 | |
15 | + def new_community | |
16 | + @community = Community.new(params[:community]) | |
17 | + if request.post? | |
18 | + if @community.save | |
19 | + @community.add_member(profile) | |
20 | + redirect_to :action => 'index' | |
21 | + end | |
22 | + end | |
23 | + end | |
24 | + | |
15 | 25 | end | ... | ... |
app/views/manage_communities/index.rhtml
... | ... | @@ -1,12 +0,0 @@ |
1 | -<h1><%= _("%s's communities") % profile.name %></h1> | |
2 | - | |
3 | -<ul> | |
4 | - <% for community in @communities %> | |
5 | - <li> | |
6 | - <%= link_to community.name, community.url %> | |
7 | - <%= link_to _('(manage)'), community.admin_url %> | |
8 | - </li> | |
9 | - <% end %> | |
10 | -</ul> | |
11 | - | |
12 | -<%= link_to _('Create a new community'), :action => 'new' %> |
app/views/manage_communities/new.rhtml
... | ... | @@ -1,12 +0,0 @@ |
1 | -<% labelled_form_for :community, @community do |f| %> | |
2 | - | |
3 | - <%= f.text_field :name %> | |
4 | - | |
5 | - <%= f.text_area :description %> | |
6 | - | |
7 | - <% button_bar do %> | |
8 | - <%= submit_button(:save, _('Create')) %> | |
9 | - <%= button(:cancel, _('Cancel'), :action => 'index') %> | |
10 | - <% end %> | |
11 | - | |
12 | -<% end %> |
app/views/memberships/index.rhtml
... | ... | @@ -9,11 +9,20 @@ |
9 | 9 | <tr> |
10 | 10 | <th><%= _('Name') %></th> |
11 | 11 | <th><%= _('Type') %></th> |
12 | + <th><%= _('Actions') %></th> | |
12 | 13 | </tr> |
13 | 14 | <% for membership in @memberships %> |
14 | 15 | <tr> |
15 | 16 | <td><%= link_to membership.name, membership.url %></td> |
16 | 17 | <td><%= _(membership.class.name) %></td> |
18 | + <td> | |
19 | + <%= link_to _('Manage'), membership.admin_url %> | |
20 | + </td> | |
17 | 21 | </tr> |
18 | 22 | <% end %> |
19 | 23 | </table> |
24 | + | |
25 | +<% button_bar do %> | |
26 | + <%= button(:add, _('Register a new Enterprise'), :controller => 'enterprise_registration') %> | |
27 | + <%= button(:add, _('Create a new community'), :action => 'new_community') %> | |
28 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +<%= error_messages_for :community %> | |
2 | + | |
3 | + | |
4 | +<% labelled_form_for :community, @community do |f| %> | |
5 | + | |
6 | + <%= f.text_field :name %> | |
7 | + | |
8 | + <%= f.text_area :description %> | |
9 | + | |
10 | + <% button_bar do %> | |
11 | + <%= submit_button(:save, _('Create')) %> | |
12 | + <%= button(:cancel, _('Cancel'), :action => 'index') %> | |
13 | + <% end %> | |
14 | + | |
15 | +<% end %> | ... | ... |
test/functional/manage_communities_controller_test.rb
... | ... | @@ -1,46 +0,0 @@ |
1 | -require File.dirname(__FILE__) + '/../test_helper' | |
2 | -require 'manage_communities_controller' | |
3 | - | |
4 | -# Re-raise errors caught by the controller. | |
5 | -class ManageCommunitiesController; def rescue_action(e) raise e end; end | |
6 | - | |
7 | -class ManageCommunitiesControllerTest < Test::Unit::TestCase | |
8 | - | |
9 | - def setup | |
10 | - @controller = ManageCommunitiesController.new | |
11 | - @request = ActionController::TestRequest.new | |
12 | - @response = ActionController::TestResponse.new | |
13 | - | |
14 | - @profile = create_user('mytestuser').person | |
15 | - end | |
16 | - attr_reader :profile | |
17 | - | |
18 | - should 'present new community form' do | |
19 | - get :new, :profile => profile.identifier | |
20 | - assert_response :success | |
21 | - assert_template 'new' | |
22 | - end | |
23 | - | |
24 | - should 'be able to create a new community' do | |
25 | - assert_difference Community, :count do | |
26 | - post :new, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} | |
27 | - assert_response :redirect | |
28 | - assert_redirected_to :action => 'index' | |
29 | - | |
30 | - assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" | |
31 | - end | |
32 | - end | |
33 | - | |
34 | - should 'list current communities' do | |
35 | - get :index, :profile => profile.identifier | |
36 | - assert_kind_of Array, assigns(:communities) | |
37 | - assert_response :success | |
38 | - assert_template 'index' | |
39 | - end | |
40 | - | |
41 | - should 'link to new community creation' do | |
42 | - get :index, :profile => profile.identifier | |
43 | - assert_tag :tag => 'a', :attributes => { :href => '/myprofile/mytestuser/manage_communities/new' } | |
44 | - end | |
45 | - | |
46 | -end |
test/functional/memberships_controller_test.rb
... | ... | @@ -39,5 +39,25 @@ class MembershipsControllerTest < Test::Unit::TestCase |
39 | 39 | assert profile.memberships.include?(community), 'profile should be actually added to the community' |
40 | 40 | end |
41 | 41 | |
42 | + should 'present new community form' do | |
43 | + get :new_community, :profile => profile.identifier | |
44 | + assert_response :success | |
45 | + assert_template 'new_community' | |
46 | + end | |
47 | + | |
48 | + should 'be able to create a new community' do | |
49 | + assert_difference Community, :count do | |
50 | + post :new_community, :profile => profile.identifier, :community => { :name => 'My shiny new community', :description => 'This is a community devoted to anything interesting we find in the internet '} | |
51 | + assert_response :redirect | |
52 | + assert_redirected_to :action => 'index' | |
53 | + | |
54 | + assert Community.find_by_identifier('my-shiny-new-community').members.include?(profile), "Creator user should be added as member of the community just created" | |
55 | + end | |
56 | + end | |
57 | + | |
58 | + should 'link to new community creation in index' do | |
59 | + get :index, :profile => profile.identifier | |
60 | + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/#{profile.identifier}/memberships/new_community" } | |
61 | + end | |
42 | 62 | |
43 | 63 | end | ... | ... |