Commit 1d8bf349190a947ddaae7e55da7fcf433c92177f

Authored by Daniela Feitosa
Committed by Antonio Terceiro
1 parent 75777888

ActionItem1252: fixing profile_count

  * Private profiles should not be counted
app/models/communities_block.rb
... ... @@ -33,7 +33,11 @@ class CommunitiesBlock < ProfileListBlock
33 33 end
34 34  
35 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 41 end
38 42  
39 43 def profile_finder
... ...
app/models/enterprises_block.rb
... ... @@ -29,7 +29,12 @@ class EnterprisesBlock < ProfileListBlock
29 29 end
30 30  
31 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 38 end
34 39  
35 40 def profile_finder
... ...
app/models/friends_block.rb
... ... @@ -30,7 +30,7 @@ class FriendsBlock < ProfileListBlock
30 30 end
31 31  
32 32 def profile_count
33   - owner.friends.count
  33 + owner.friends.count(:conditions => { :public_profile => true })
34 34 end
35 35  
36 36 end
... ...
app/models/members_block.rb
... ... @@ -20,7 +20,7 @@ class MembersBlock < ProfileListBlock
20 20 end
21 21  
22 22 def profile_count
23   - owner.members.count
  23 + owner.members.select {|member| member.public_profile? }.count
24 24 end
25 25  
26 26 def profile_finder
... ...
test/unit/communities_block_test.rb
... ... @@ -102,7 +102,7 @@ class CommunitiesBlockTest < Test::Unit::TestCase
102 102 assert_equal 2, block.profile_count
103 103 end
104 104  
105   - should 'not count non-public communities' do
  105 + should 'not count non-public profile communities' do
106 106 user = create_user('testuser').person
107 107  
108 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 117 assert_equal 1, block.profile_count
118 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 131 end
... ...
test/unit/enterprises_block_test.rb
... ... @@ -114,7 +114,7 @@ class EnterprisesBlockTest < Test::Unit::TestCase
114 114 assert_equal 2, block.profile_count
115 115 end
116 116  
117   - should 'not count non-public enterprises' do
  117 + should 'not count non-public person enterprises' do
118 118 user = create_user('testuser').person
119 119  
120 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 131 assert_equal 1, block.profile_count
132 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 146 end
... ...
test/unit/friends_block_test.rb
... ... @@ -62,4 +62,17 @@ class FriendsBlockTest < ActiveSupport::TestCase
62 62 assert_equal 3, block.profile_count
63 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 78 end
... ...
test/unit/members_block_test.rb
... ... @@ -60,11 +60,30 @@ class MembersBlockTest < Test::Unit::TestCase
60 60 member2 = mock; member2.stubs(:id).returns(2)
61 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 67 owner.expects(:members).returns([member1, member2, member3])
64 68  
65 69 block = MembersBlock.new
66 70 block.expects(:owner).returns(owner)
67 71 assert_equal 3, block.profile_count
68 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 88 end
70 89  
... ...