From 30b741ffb0103459663273c3321ea1f2a52e7491 Mon Sep 17 00:00:00 2001 From: Joenio Costa Date: Mon, 31 Aug 2009 18:36:27 -0300 Subject: [PATCH] ActionItem1238: Noosfero can not count communities (and enterprises too) --- app/models/communities_block.rb | 2 +- app/models/enterprises_block.rb | 2 +- app/models/person.rb | 8 ++++---- test/unit/communities_block_test.rb | 19 +++++++++++++++++-- test/unit/enterprises_block_test.rb | 17 +++++++++++++++++ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb index 09811bd..c8efe42 100644 --- a/app/models/communities_block.rb +++ b/app/models/communities_block.rb @@ -33,7 +33,7 @@ class CommunitiesBlock < ProfileListBlock end def profile_count - owner.communities.count + owner.communities(:public_profile => true).count end def profile_finder diff --git a/app/models/enterprises_block.rb b/app/models/enterprises_block.rb index ae616ae..deb9077 100644 --- a/app/models/enterprises_block.rb +++ b/app/models/enterprises_block.rb @@ -29,7 +29,7 @@ class EnterprisesBlock < ProfileListBlock end def profile_count - owner.enterprises.count + owner.enterprises(:public_profile => true).count end def profile_finder diff --git a/app/models/person.rb b/app/models/person.rb index aa301e8..c35e11f 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -128,14 +128,14 @@ class Person < Profile :select => 'profiles.*').uniq end - def enterprise_memberships - memberships(:type => Enterprise.name) + def enterprise_memberships(conditions = {}) + memberships({:type => Enterprise.name}.merge(conditions)) end alias :enterprises :enterprise_memberships - def community_memberships - memberships(:type => Community.name) + def community_memberships(conditions = {}) + memberships({:type => Community.name}.merge(conditions)) end alias :communities :community_memberships diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index 24f0df0..53bd68e 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -90,10 +90,10 @@ class CommunitiesBlockTest < Test::Unit::TestCase should 'count number of owner communities' do user = create_user('testuser').person - community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default) + community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) community1.add_member(user) - community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default) + community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => true) community2.add_member(user) block = CommunitiesBlock.new @@ -102,4 +102,19 @@ class CommunitiesBlockTest < Test::Unit::TestCase assert_equal 2, block.profile_count end + should 'not count non-public communities' do + user = create_user('testuser').person + + community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) + community_public.add_member(user) + + community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) + community_private.add_member(user) + + block = CommunitiesBlock.new + block.expects(:owner).at_least_once.returns(user) + + assert_equal 1, block.profile_count + end + end diff --git a/test/unit/enterprises_block_test.rb b/test/unit/enterprises_block_test.rb index b59ca59..066a9f6 100644 --- a/test/unit/enterprises_block_test.rb +++ b/test/unit/enterprises_block_test.rb @@ -114,4 +114,21 @@ class EnterprisesBlockTest < Test::Unit::TestCase assert_equal 2, block.profile_count end + should 'not count non-public enterprises' do + user = create_user('testuser').person + + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true) + ent1.expects(:closed?).returns(false) + ent1.add_member(user) + + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default, :public_profile => false) + ent2.expects(:closed?).returns(false) + ent2.add_member(user) + + block = EnterprisesBlock.new + block.expects(:owner).at_least_once.returns(user) + + assert_equal 1, block.profile_count + end + end -- libgit2 0.21.2