Commit f4edf6a1336efe73788b7beb0538df22ce496bb1
1 parent
32fdbb23
Exists in
master
and in
23 other branches
ActionItem42: implementing controller to manage membership of the profile in other profiles
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1381 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
90 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +class MembershipsController < MyProfileController | |
| 2 | + | |
| 3 | + def index | |
| 4 | + @memberships = profile.memberships | |
| 5 | + end | |
| 6 | + | |
| 7 | + def join | |
| 8 | + @to_join = Profile.find(params[:id]) | |
| 9 | + if request.post? && params[:confirmation] | |
| 10 | + @to_join.add_member(profile) | |
| 11 | + redirect_to @to_join.url | |
| 12 | + end | |
| 13 | + end | |
| 14 | + | |
| 15 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +<h1><%= _("%s's groups") % profile.name %></h1> | |
| 2 | + | |
| 3 | +<p> | |
| 4 | +<%= _('%s is a member of the following groups:') % profile.name %> | |
| 5 | +</p> | |
| 6 | + | |
| 7 | + | |
| 8 | +<table> | |
| 9 | + <tr> | |
| 10 | + <th><%= _('Name') %></th> | |
| 11 | + <th><%= _('Type') %></th> | |
| 12 | + </tr> | |
| 13 | +<% for membership in @memberships %> | |
| 14 | + <tr> | |
| 15 | + <td><%= link_to membership.name, membership.url %></td> | |
| 16 | + <td><%= _(membership.class.name) %></td> | |
| 17 | + </tr> | |
| 18 | +<% end %> | |
| 19 | +</table> | ... | ... |
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +<h1><%= _('Joining %s') % @to_join.name %></h1> | |
| 2 | + | |
| 3 | +<p> | |
| 4 | +<%= _('Are you sure you want to join %s?') % @to_join.name %> | |
| 5 | +</p> | |
| 6 | + | |
| 7 | +<% form_tag do %> | |
| 8 | + <%= hidden_field_tag(:confirmation, 1) %> | |
| 9 | + <%= submit_button(:ok, _("Yes, I want to join.") % @to_join.name) %> | |
| 10 | + <%= button(:cancel, _("No, I don't want."), :action => 'index') %> | |
| 11 | +<% end %> | ... | ... |
| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | |
| 2 | +require 'memberships_controller' | |
| 3 | + | |
| 4 | +# Re-raise errors caught by the controller. | |
| 5 | +class MembershipsController; def rescue_action(e) raise e end; end | |
| 6 | + | |
| 7 | +class MembershipsControllerTest < Test::Unit::TestCase | |
| 8 | + def setup | |
| 9 | + @controller = MembershipsController.new | |
| 10 | + @request = ActionController::TestRequest.new | |
| 11 | + @response = ActionController::TestResponse.new | |
| 12 | + | |
| 13 | + @profile = create_user('testuser').person | |
| 14 | + end | |
| 15 | + attr_reader :profile | |
| 16 | + | |
| 17 | + should 'list current memberships' do | |
| 18 | + get :index, :profile => profile.identifier | |
| 19 | + | |
| 20 | + assert_kind_of Array, assigns(:memberships) | |
| 21 | + end | |
| 22 | + | |
| 23 | + should 'present confirmation before joining a profile' do | |
| 24 | + community = Community.create!(:name => 'my test community') | |
| 25 | + get :join, :profile => profile.identifier, :id => community.id | |
| 26 | + | |
| 27 | + assert_response :success | |
| 28 | + assert_template 'join' | |
| 29 | + end | |
| 30 | + | |
| 31 | + should 'actually join profile' do | |
| 32 | + community = Community.create!(:name => 'my test community') | |
| 33 | + post :join, :profile => profile.identifier, :id => community.id, :confirmation => '1' | |
| 34 | + | |
| 35 | + assert_response :redirect | |
| 36 | + assert_redirected_to community.url | |
| 37 | + | |
| 38 | + profile.reload | |
| 39 | + assert profile.memberships.include?(community), 'profile should be actually added to the community' | |
| 40 | + end | |
| 41 | + | |
| 42 | + | |
| 43 | +end | ... | ... |