Commit 306e49b89a39292faa693ba65577c7d9ced0fdbc

Authored by JoenioCosta
1 parent 2519b304

ActionItem384: member leave from community/enterprise

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1782 3f533792-8f58-4932-b0fe-aaf55b0a4547
test/functional/memberships_controller_test.rb
... ... @@ -122,6 +122,7 @@ class MembershipsControllerTest < Test::Unit::TestCase
122 122  
123 123 should 'present confirmation before leaving a profile' do
124 124 community = Community.create!(:name => 'my test community')
  125 + community.add_member(profile)
125 126 get :leave, :profile => profile.identifier, :id => community.id
126 127  
127 128 assert_response :success
... ... @@ -130,13 +131,15 @@ class MembershipsControllerTest < Test::Unit::TestCase
130 131  
131 132 should 'actually leave profile' do
132 133 community = Community.create!(:name => 'my test community')
  134 + community.add_member(profile)
  135 + assert_includes profile.memberships, community
133 136 post :leave, :profile => profile.identifier, :id => community.id, :confirmation => '1'
134 137  
135 138 assert_response :redirect
136 139 assert_redirected_to :action => 'index'
137 140  
138 141 profile.reload
139   - assert !profile.memberships.include?(community)
  142 + assert_not_includes profile.memberships, community
140 143 end
141 144  
142 145 end
... ...
test/unit/profile_test.rb
... ... @@ -461,8 +461,10 @@ class ProfileTest < Test::Unit::TestCase
461 461 p = create_user('myothertestuser').person
462 462  
463 463 c.add_member(p)
  464 + assert_includes c.members, p
464 465 c.remove_member(p)
465   - assert !c.members.include?(p)
  466 + c.reload
  467 + assert_not_includes c.members, p
466 468 end
467 469  
468 470 private
... ...
vendor/plugins/access_control/lib/acts_as_accessible.rb
... ... @@ -21,7 +21,7 @@ class ActiveRecord::Base
21 21  
22 22 def disaffiliate(accessor, roles)
23 23 roles = [roles] unless roles.kind_of?(Array)
24   - roles.map {|role| accessor.remove_role(role, self)}.any?
  24 + role_assignments.map{|ra|ra.destroy if roles.include?(ra.role) && ra.accessor == accessor}
25 25 end
26 26  
27 27 def members
... ...