diff --git a/app/models/profile.rb b/app/models/profile.rb index 2490118..6fcc62b 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -255,12 +255,12 @@ class Profile < ActiveRecord::Base end # Adds a person as member of this Profile. - # - # TODO if the subscription to the profile (closed Community, Enterprise etc) - # is not open, instead of affiliating directly this method should create a - # suitable task and assign it to the profile. def add_member(person) - self.affiliate(person, Profile::Roles.member) + if self.has_members? + self.affiliate(person, Profile::Roles.member) + else + raise _("%s can't has members") % self.class.name + end end def remove_member(person) diff --git a/test/unit/community_test.rb b/test/unit/community_test.rb index 5a9e2cc..5afb567 100644 --- a/test/unit/community_test.rb +++ b/test/unit/community_test.rb @@ -44,4 +44,24 @@ class CommunityTest < Test::Unit::TestCase assert_respond_to community, :contact_person end + should 'allow to add new members' do + c = Community.create!(:name => 'my test profile', :identifier => 'mytestprofile') + p = create_user('mytestuser').person + + c.add_member(p) + + assert c.members.include?(p), "Community should add the new member" + end + + should 'allow to remove members' do + c = Community.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') + p = create_user('myothertestuser').person + + c.add_member(p) + assert_includes c.members, p + c.remove_member(p) + c.reload + assert_not_includes c.members, p + end + end diff --git a/test/unit/enterprise_test.rb b/test/unit/enterprise_test.rb index de6dd7a..4d1708c 100644 --- a/test/unit/enterprise_test.rb +++ b/test/unit/enterprise_test.rb @@ -76,4 +76,24 @@ class EnterpriseTest < Test::Unit::TestCase assert_equal 5, e.blocks.size end + should 'allow to add new members' do + o = Enterprise.create!(:name => 'my test profile', :identifier => 'mytestprofile') + p = create_user('mytestuser').person + + o.add_member(p) + + assert o.members.include?(p), "Enterprise should add the new member" + end + + should 'allow to remove members' do + c = Enterprise.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') + p = create_user('myothertestuser').person + + c.add_member(p) + assert_includes c.members, p + c.remove_member(p) + c.reload + assert_not_includes c.members, p + end + end diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index cae9e44..ba0c5cf 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -161,5 +161,25 @@ class OrganizationTest < Test::Unit::TestCase assert_respond_to org, :closed assert_respond_to org, :closed? end + + should 'allow to add new members' do + o = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') + p = create_user('mytestuser').person + + o.add_member(p) + + assert o.members.include?(p), "Organization should add the new member" + end + should 'allow to remove members' do + c = Organization.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') + p = create_user('myothertestuser').person + + c.add_member(p) + assert_includes c.members, p + c.remove_member(p) + c.reload + assert_not_includes c.members, p + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 437c82b..54ba070 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -320,19 +320,18 @@ class ProfileTest < Test::Unit::TestCase end should 'create a homepage and a feed on creation' do - profile = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') + profile = Organization.create!(:name => 'my test profile', :identifier => 'mytestprofile') assert_kind_of Article, profile.home_page assert_kind_of RssFeed, profile.articles.find_by_path('feed') end - should 'allow to add new members' do + should 'raises when add members' do c = Profile.create!(:name => 'my test profile', :identifier => 'mytestprofile') p = create_user('mytestuser').person - - c.add_member(p) - - assert c.members.include?(p), "Profile should add the new member" + assert_raise RuntimeError do + c.add_member(p) + end end should 'allow to add administrators' do @@ -452,17 +451,6 @@ class ProfileTest < Test::Unit::TestCase assert_includes Enterprise.find(:all, :within => 2, :origin => [45, 45]), e end - should 'allow to remove members' do - c = Profile.create!(:name => 'my other test profile', :identifier => 'myothertestprofile') - p = create_user('myothertestuser').person - - c.add_member(p) - assert_includes c.members, p - c.remove_member(p) - c.reload - assert_not_includes c.members, p - end - should 'have a public profile by default' do assert_equal true, Profile.new.public_profile end -- libgit2 0.21.2