Commit 1d8bf349190a947ddaae7e55da7fcf433c92177f
Committed by
Antonio Terceiro
1 parent
75777888
Exists in
staging
and in
42 other branches
ActionItem1252: fixing profile_count
* Private profiles should not be counted
Showing
8 changed files
with
70 additions
and
6 deletions
Show diff stats
app/models/communities_block.rb
| @@ -33,7 +33,11 @@ class CommunitiesBlock < ProfileListBlock | @@ -33,7 +33,11 @@ class CommunitiesBlock < ProfileListBlock | ||
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | def profile_count | 35 | def profile_count |
| 36 | - owner.communities(:public_profile => true).count | 36 | + if owner.kind_of?(Environment) |
| 37 | + owner.communities.count(:conditions => { :public_profile => true }) | ||
| 38 | + else | ||
| 39 | + owner.communities(:public_profile => true).count | ||
| 40 | + end | ||
| 37 | end | 41 | end |
| 38 | 42 | ||
| 39 | def profile_finder | 43 | def profile_finder |
app/models/enterprises_block.rb
| @@ -29,7 +29,12 @@ class EnterprisesBlock < ProfileListBlock | @@ -29,7 +29,12 @@ class EnterprisesBlock < ProfileListBlock | ||
| 29 | end | 29 | end |
| 30 | 30 | ||
| 31 | def profile_count | 31 | def profile_count |
| 32 | - owner.enterprises(:public_profile => true).count | 32 | + if owner.kind_of?(Environment) |
| 33 | + owner.enterprises.count(:conditions => { :public_profile => true }) | ||
| 34 | + else | ||
| 35 | + owner.enterprises(:public_profile => true).count | ||
| 36 | + end | ||
| 37 | + | ||
| 33 | end | 38 | end |
| 34 | 39 | ||
| 35 | def profile_finder | 40 | def profile_finder |
app/models/friends_block.rb
| @@ -30,7 +30,7 @@ class FriendsBlock < ProfileListBlock | @@ -30,7 +30,7 @@ class FriendsBlock < ProfileListBlock | ||
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | def profile_count | 32 | def profile_count |
| 33 | - owner.friends.count | 33 | + owner.friends.count(:conditions => { :public_profile => true }) |
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | end | 36 | end |
app/models/members_block.rb
| @@ -20,7 +20,7 @@ class MembersBlock < ProfileListBlock | @@ -20,7 +20,7 @@ class MembersBlock < ProfileListBlock | ||
| 20 | end | 20 | end |
| 21 | 21 | ||
| 22 | def profile_count | 22 | def profile_count |
| 23 | - owner.members.count | 23 | + owner.members.select {|member| member.public_profile? }.count |
| 24 | end | 24 | end |
| 25 | 25 | ||
| 26 | def profile_finder | 26 | def profile_finder |
test/unit/communities_block_test.rb
| @@ -102,7 +102,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase | @@ -102,7 +102,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase | ||
| 102 | assert_equal 2, block.profile_count | 102 | assert_equal 2, block.profile_count |
| 103 | end | 103 | end |
| 104 | 104 | ||
| 105 | - should 'not count non-public communities' do | 105 | + should 'not count non-public profile communities' do |
| 106 | user = create_user('testuser').person | 106 | user = create_user('testuser').person |
| 107 | 107 | ||
| 108 | community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) | 108 | community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) |
| @@ -117,4 +117,15 @@ class CommunitiesBlockTest < Test::Unit::TestCase | @@ -117,4 +117,15 @@ class CommunitiesBlockTest < Test::Unit::TestCase | ||
| 117 | assert_equal 1, block.profile_count | 117 | assert_equal 1, block.profile_count |
| 118 | end | 118 | end |
| 119 | 119 | ||
| 120 | + should 'not count non-public environment communities' do | ||
| 121 | + community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true) | ||
| 122 | + | ||
| 123 | + community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) | ||
| 124 | + | ||
| 125 | + block = CommunitiesBlock.new | ||
| 126 | + block.expects(:owner).at_least_once.returns(Environment.default) | ||
| 127 | + | ||
| 128 | + assert_equal 1, block.profile_count | ||
| 129 | + end | ||
| 130 | + | ||
| 120 | end | 131 | end |
test/unit/enterprises_block_test.rb
| @@ -114,7 +114,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase | @@ -114,7 +114,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase | ||
| 114 | assert_equal 2, block.profile_count | 114 | assert_equal 2, block.profile_count |
| 115 | end | 115 | end |
| 116 | 116 | ||
| 117 | - should 'not count non-public enterprises' do | 117 | + should 'not count non-public person enterprises' do |
| 118 | user = create_user('testuser').person | 118 | user = create_user('testuser').person |
| 119 | 119 | ||
| 120 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true) | 120 | ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true) |
| @@ -131,4 +131,16 @@ class EnterprisesBlockTest < Test::Unit::TestCase | @@ -131,4 +131,16 @@ class EnterprisesBlockTest < Test::Unit::TestCase | ||
| 131 | assert_equal 1, block.profile_count | 131 | assert_equal 1, block.profile_count |
| 132 | end | 132 | end |
| 133 | 133 | ||
| 134 | + should 'not count non-public environment enterprises' do | ||
| 135 | + env = Environment.create!(:name => 'test_env') | ||
| 136 | + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => env, :public_profile => true) | ||
| 137 | + | ||
| 138 | + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => env, :public_profile => false) | ||
| 139 | + | ||
| 140 | + block = EnterprisesBlock.new | ||
| 141 | + block.expects(:owner).at_least_once.returns(env) | ||
| 142 | + | ||
| 143 | + assert_equal 1, block.profile_count | ||
| 144 | + end | ||
| 145 | + | ||
| 134 | end | 146 | end |
test/unit/friends_block_test.rb
| @@ -62,4 +62,17 @@ class FriendsBlockTest < ActiveSupport::TestCase | @@ -62,4 +62,17 @@ class FriendsBlockTest < ActiveSupport::TestCase | ||
| 62 | assert_equal 3, block.profile_count | 62 | assert_equal 3, block.profile_count |
| 63 | end | 63 | end |
| 64 | 64 | ||
| 65 | + should 'count number of public people' do | ||
| 66 | + owner = create_user('testuser1').person | ||
| 67 | + private_p = create_user('private', {}, {:public_profile => false}).person | ||
| 68 | + public_p = create_user('public', {}, {:public_profile => true}).person | ||
| 69 | + | ||
| 70 | + owner.add_friend(private_p) | ||
| 71 | + owner.add_friend(public_p) | ||
| 72 | + | ||
| 73 | + block = FriendsBlock.new | ||
| 74 | + block.expects(:owner).returns(owner) | ||
| 75 | + | ||
| 76 | + assert_equal 1, block.profile_count | ||
| 77 | + end | ||
| 65 | end | 78 | end |
test/unit/members_block_test.rb
| @@ -60,11 +60,30 @@ class MembersBlockTest < Test::Unit::TestCase | @@ -60,11 +60,30 @@ class MembersBlockTest < Test::Unit::TestCase | ||
| 60 | member2 = mock; member2.stubs(:id).returns(2) | 60 | member2 = mock; member2.stubs(:id).returns(2) |
| 61 | member3 = mock; member3.stubs(:id).returns(3) | 61 | member3 = mock; member3.stubs(:id).returns(3) |
| 62 | 62 | ||
| 63 | + member1.stubs(:public_profile?).returns(true) | ||
| 64 | + member2.stubs(:public_profile?).returns(true) | ||
| 65 | + member3.stubs(:public_profile?).returns(true) | ||
| 66 | + | ||
| 63 | owner.expects(:members).returns([member1, member2, member3]) | 67 | owner.expects(:members).returns([member1, member2, member3]) |
| 64 | 68 | ||
| 65 | block = MembersBlock.new | 69 | block = MembersBlock.new |
| 66 | block.expects(:owner).returns(owner) | 70 | block.expects(:owner).returns(owner) |
| 67 | assert_equal 3, block.profile_count | 71 | assert_equal 3, block.profile_count |
| 68 | end | 72 | end |
| 73 | + | ||
| 74 | + should 'not count non-public community members' do | ||
| 75 | + community = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default) | ||
| 76 | + | ||
| 77 | + private_p = create_user('private', {}, {:public_profile => false}).person | ||
| 78 | + public_p = create_user('public', {}, {:public_profile => true}).person | ||
| 79 | + | ||
| 80 | + community.add_member(private_p) | ||
| 81 | + community.add_member(public_p) | ||
| 82 | + | ||
| 83 | + block = MembersBlock.new | ||
| 84 | + block.expects(:owner).at_least_once.returns(community) | ||
| 85 | + | ||
| 86 | + assert_equal 1, block.profile_count | ||
| 87 | + end | ||
| 69 | end | 88 | end |
| 70 | 89 |