diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb index c8efe42..ecea407 100644 --- a/app/models/communities_block.rb +++ b/app/models/communities_block.rb @@ -33,7 +33,11 @@ class CommunitiesBlock < ProfileListBlock end def profile_count - owner.communities(:public_profile => true).count + if owner.kind_of?(Environment) + owner.communities.count(:conditions => { :public_profile => true }) + else + owner.communities(:public_profile => true).count + end end def profile_finder diff --git a/app/models/enterprises_block.rb b/app/models/enterprises_block.rb index deb9077..13d1df0 100644 --- a/app/models/enterprises_block.rb +++ b/app/models/enterprises_block.rb @@ -29,7 +29,12 @@ class EnterprisesBlock < ProfileListBlock end def profile_count - owner.enterprises(:public_profile => true).count + if owner.kind_of?(Environment) + owner.enterprises.count(:conditions => { :public_profile => true }) + else + owner.enterprises(:public_profile => true).count + end + end def profile_finder diff --git a/app/models/friends_block.rb b/app/models/friends_block.rb index 0abe221..858586f 100644 --- a/app/models/friends_block.rb +++ b/app/models/friends_block.rb @@ -30,7 +30,7 @@ class FriendsBlock < ProfileListBlock end def profile_count - owner.friends.count + owner.friends.count(:conditions => { :public_profile => true }) end end diff --git a/app/models/members_block.rb b/app/models/members_block.rb index f1dcc72..aea9eef 100644 --- a/app/models/members_block.rb +++ b/app/models/members_block.rb @@ -20,7 +20,7 @@ class MembersBlock < ProfileListBlock end def profile_count - owner.members.count + owner.members.select {|member| member.public_profile? }.count end def profile_finder diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index 53bd68e..5671c6f 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -102,7 +102,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase assert_equal 2, block.profile_count end - should 'not count non-public communities' do + should 'not count non-public profile communities' do user = create_user('testuser').person community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) @@ -117,4 +117,15 @@ class CommunitiesBlockTest < Test::Unit::TestCase assert_equal 1, block.profile_count end + should 'not count non-public environment communities' do + community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) + + community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) + + block = CommunitiesBlock.new + block.expects(:owner).at_least_once.returns(Environment.default) + + 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 066a9f6..43ea17c 100644 --- a/test/unit/enterprises_block_test.rb +++ b/test/unit/enterprises_block_test.rb @@ -114,7 +114,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase assert_equal 2, block.profile_count end - should 'not count non-public enterprises' do + should 'not count non-public person enterprises' do user = create_user('testuser').person ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true) @@ -131,4 +131,16 @@ class EnterprisesBlockTest < Test::Unit::TestCase assert_equal 1, block.profile_count end + should 'not count non-public environment enterprises' do + env = Environment.create!(:name => 'test_env') + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :public_profile => true) + + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :public_profile => false) + + block = EnterprisesBlock.new + block.expects(:owner).at_least_once.returns(env) + + assert_equal 1, block.profile_count + end + end diff --git a/test/unit/friends_block_test.rb b/test/unit/friends_block_test.rb index ad6778d..e8dc55d 100644 --- a/test/unit/friends_block_test.rb +++ b/test/unit/friends_block_test.rb @@ -62,4 +62,17 @@ class FriendsBlockTest < ActiveSupport::TestCase assert_equal 3, block.profile_count end + should 'count number of public people' do + owner = create_user('testuser1').person + private_p = create_user('private', {}, {:public_profile => false}).person + public_p = create_user('public', {}, {:public_profile => true}).person + + owner.add_friend(private_p) + owner.add_friend(public_p) + + block = FriendsBlock.new + block.expects(:owner).returns(owner) + + assert_equal 1, block.profile_count + end end diff --git a/test/unit/members_block_test.rb b/test/unit/members_block_test.rb index 3048729..8816984 100644 --- a/test/unit/members_block_test.rb +++ b/test/unit/members_block_test.rb @@ -60,11 +60,30 @@ class MembersBlockTest < Test::Unit::TestCase member2 = mock; member2.stubs(:id).returns(2) member3 = mock; member3.stubs(:id).returns(3) + member1.stubs(:public_profile?).returns(true) + member2.stubs(:public_profile?).returns(true) + member3.stubs(:public_profile?).returns(true) + owner.expects(:members).returns([member1, member2, member3]) block = MembersBlock.new block.expects(:owner).returns(owner) assert_equal 3, block.profile_count end + + should 'not count non-public community members' do + community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default) + + private_p = create_user('private', {}, {:public_profile => false}).person + public_p = create_user('public', {}, {:public_profile => true}).person + + community.add_member(private_p) + community.add_member(public_p) + + block = MembersBlock.new + block.expects(:owner).at_least_once.returns(community) + + assert_equal 1, block.profile_count + end end -- libgit2 0.21.2