Commit b8a7be040a9d9a5f052ed2d572d5a48cc2026415
1 parent
692bbc33
Exists in
master
and in
22 other branches
ActionItem165: just add member if profile has_members is true
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1842 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
70 additions
and
22 deletions
Show diff stats
app/models/profile.rb
| @@ -255,12 +255,12 @@ class Profile < ActiveRecord::Base | @@ -255,12 +255,12 @@ class Profile < ActiveRecord::Base | ||
| 255 | end | 255 | end |
| 256 | 256 | ||
| 257 | # Adds a person as member of this Profile. | 257 | # Adds a person as member of this Profile. |
| 258 | - # | ||
| 259 | - # TODO if the subscription to the profile (closed Community, Enterprise etc) | ||
| 260 | - # is not open, instead of affiliating directly this method should create a | ||
| 261 | - # suitable task and assign it to the profile. | ||
| 262 | def add_member(person) | 258 | def add_member(person) |
| 263 | - self.affiliate(person, Profile::Roles.member) | 259 | + if self.has_members? |
| 260 | + self.affiliate(person, Profile::Roles.member) | ||
| 261 | + else | ||
| 262 | + raise _("%s can't has members") % self.class.name | ||
| 263 | + end | ||
| 264 | end | 264 | end |
| 265 | 265 | ||
| 266 | def remove_member(person) | 266 | def remove_member(person) |
test/unit/community_test.rb
| @@ -44,4 +44,24 @@ class CommunityTest < Test::Unit::TestCase | @@ -44,4 +44,24 @@ class CommunityTest < Test::Unit::TestCase | ||
| 44 | assert_respond_to community, :contact_person | 44 | assert_respond_to community, :contact_person |
| 45 | end | 45 | end |
| 46 | 46 | ||
| 47 | + should 'allow to add new members' do | ||
| 48 | + c = Community.create!(:name => 'my test profile', :identifier => 'mytestprofile') | ||
| 49 | + p = create_user('mytestuser').person | ||
| 50 | + | ||
| 51 | + c.add_member(p) | ||
| 52 | + | ||
| 53 | + assert c.members.include?(p), "Community should add the new member" | ||
| 54 | + end | ||
| 55 | + | ||
| 56 | + should 'allow to remove members' do | ||
| 57 | + c = Community.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') | ||
| 58 | + p = create_user('myothertestuser').person | ||
| 59 | + | ||
| 60 | + c.add_member(p) | ||
| 61 | + assert_includes c.members, p | ||
| 62 | + c.remove_member(p) | ||
| 63 | + c.reload | ||
| 64 | + assert_not_includes c.members, p | ||
| 65 | + end | ||
| 66 | + | ||
| 47 | end | 67 | end |
test/unit/enterprise_test.rb
| @@ -76,4 +76,24 @@ class EnterpriseTest < Test::Unit::TestCase | @@ -76,4 +76,24 @@ class EnterpriseTest < Test::Unit::TestCase | ||
| 76 | assert_equal 5, e.blocks.size | 76 | assert_equal 5, e.blocks.size |
| 77 | end | 77 | end |
| 78 | 78 | ||
| 79 | + should 'allow to add new members' do | ||
| 80 | + o = Enterprise.create!(:name => 'my test profile', :identifier => 'mytestprofile') | ||
| 81 | + p = create_user('mytestuser').person | ||
| 82 | + | ||
| 83 | + o.add_member(p) | ||
| 84 | + | ||
| 85 | + assert o.members.include?(p), "Enterprise should add the new member" | ||
| 86 | + end | ||
| 87 | + | ||
| 88 | + should 'allow to remove members' do | ||
| 89 | + c = Enterprise.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') | ||
| 90 | + p = create_user('myothertestuser').person | ||
| 91 | + | ||
| 92 | + c.add_member(p) | ||
| 93 | + assert_includes c.members, p | ||
| 94 | + c.remove_member(p) | ||
| 95 | + c.reload | ||
| 96 | + assert_not_includes c.members, p | ||
| 97 | + end | ||
| 98 | + | ||
| 79 | end | 99 | end |
test/unit/organization_test.rb
| @@ -161,5 +161,25 @@ class OrganizationTest < Test::Unit::TestCase | @@ -161,5 +161,25 @@ class OrganizationTest < Test::Unit::TestCase | ||
| 161 | assert_respond_to org, :closed | 161 | assert_respond_to org, :closed |
| 162 | assert_respond_to org, :closed? | 162 | assert_respond_to org, :closed? |
| 163 | end | 163 | end |
| 164 | + | ||
| 165 | + should 'allow to add new members' do | ||
| 166 | + o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') | ||
| 167 | + p = create_user('mytestuser').person | ||
| 168 | + | ||
| 169 | + o.add_member(p) | ||
| 170 | + | ||
| 171 | + assert o.members.include?(p), "Organization should add the new member" | ||
| 172 | + end | ||
| 164 | 173 | ||
| 174 | + should 'allow to remove members' do | ||
| 175 | + c = Organization.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') | ||
| 176 | + p = create_user('myothertestuser').person | ||
| 177 | + | ||
| 178 | + c.add_member(p) | ||
| 179 | + assert_includes c.members, p | ||
| 180 | + c.remove_member(p) | ||
| 181 | + c.reload | ||
| 182 | + assert_not_includes c.members, p | ||
| 183 | + end | ||
| 184 | + | ||
| 165 | end | 185 | end |
test/unit/profile_test.rb
| @@ -320,19 +320,18 @@ class ProfileTest < Test::Unit::TestCase | @@ -320,19 +320,18 @@ class ProfileTest < Test::Unit::TestCase | ||
| 320 | end | 320 | end |
| 321 | 321 | ||
| 322 | should 'create a homepage and a feed on creation' do | 322 | should 'create a homepage and a feed on creation' do |
| 323 | - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 323 | + profile = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') |
| 324 | 324 | ||
| 325 | assert_kind_of Article, profile.home_page | 325 | assert_kind_of Article, profile.home_page |
| 326 | assert_kind_of RssFeed, profile.articles.find_by_path('feed') | 326 | assert_kind_of RssFeed, profile.articles.find_by_path('feed') |
| 327 | end | 327 | end |
| 328 | 328 | ||
| 329 | - should 'allow to add new members' do | 329 | + should 'raises when add members' do |
| 330 | c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') | 330 | c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') |
| 331 | p = create_user('mytestuser').person | 331 | p = create_user('mytestuser').person |
| 332 | - | ||
| 333 | - c.add_member(p) | ||
| 334 | - | ||
| 335 | - assert c.members.include?(p), "Profile should add the new member" | 332 | + assert_raise RuntimeError do |
| 333 | + c.add_member(p) | ||
| 334 | + end | ||
| 336 | end | 335 | end |
| 337 | 336 | ||
| 338 | should 'allow to add administrators' do | 337 | should 'allow to add administrators' do |
| @@ -452,17 +451,6 @@ class ProfileTest < Test::Unit::TestCase | @@ -452,17 +451,6 @@ class ProfileTest < Test::Unit::TestCase | ||
| 452 | assert_includes Enterprise.find(:all, :within => 2, :origin => [45, 45]), e | 451 | assert_includes Enterprise.find(:all, :within => 2, :origin => [45, 45]), e |
| 453 | end | 452 | end |
| 454 | 453 | ||
| 455 | - should 'allow to remove members' do | ||
| 456 | - c = Profile.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') | ||
| 457 | - p = create_user('myothertestuser').person | ||
| 458 | - | ||
| 459 | - c.add_member(p) | ||
| 460 | - assert_includes c.members, p | ||
| 461 | - c.remove_member(p) | ||
| 462 | - c.reload | ||
| 463 | - assert_not_includes c.members, p | ||
| 464 | - end | ||
| 465 | - | ||
| 466 | should 'have a public profile by default' do | 454 | should 'have a public profile by default' do |
| 467 | assert_equal true, Profile.new.public_profile | 455 | assert_equal true, Profile.new.public_profile |
| 468 | end | 456 | end |