Commit 30b741ffb0103459663273c3321ea1f2a52e7491

Authored by Joenio Costa
Committed by Antonio Terceiro
1 parent 5f957438

ActionItem1238: Noosfero can not count communities (and enterprises too)

app/models/communities_block.rb
... ... @@ -33,7 +33,7 @@ class CommunitiesBlock < ProfileListBlock
33 33 end
34 34  
35 35 def profile_count
36   - owner.communities.count
  36 + owner.communities(:public_profile => true).count
37 37 end
38 38  
39 39 def profile_finder
... ...
app/models/enterprises_block.rb
... ... @@ -29,7 +29,7 @@ class EnterprisesBlock < ProfileListBlock
29 29 end
30 30  
31 31 def profile_count
32   - owner.enterprises.count
  32 + owner.enterprises(:public_profile => true).count
33 33 end
34 34  
35 35 def profile_finder
... ...
app/models/person.rb
... ... @@ -128,14 +128,14 @@ class Person < Profile
128 128 :select => 'profiles.*').uniq
129 129 end
130 130  
131   - def enterprise_memberships
132   - memberships(:type => Enterprise.name)
  131 + def enterprise_memberships(conditions = {})
  132 + memberships({:type => Enterprise.name}.merge(conditions))
133 133 end
134 134  
135 135 alias :enterprises :enterprise_memberships
136 136  
137   - def community_memberships
138   - memberships(:type => Community.name)
  137 + def community_memberships(conditions = {})
  138 + memberships({:type => Community.name}.merge(conditions))
139 139 end
140 140  
141 141 alias :communities :community_memberships
... ...
test/unit/communities_block_test.rb
... ... @@ -90,10 +90,10 @@ class CommunitiesBlockTest < Test::Unit::TestCase
90 90 should 'count number of owner communities' do
91 91 user = create_user('testuser').person
92 92  
93   - community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default)
  93 + community1 = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
94 94 community1.add_member(user)
95 95  
96   - community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default)
  96 + community2 = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => true)
97 97 community2.add_member(user)
98 98  
99 99 block = CommunitiesBlock.new
... ... @@ -102,4 +102,19 @@ 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
  106 + user = create_user('testuser').person
  107 +
  108 + community_public = Community.create!(:name => 'tcommunity 1', :identifier => 'comm1', :environment => Environment.default, :public_profile => true)
  109 + community_public.add_member(user)
  110 +
  111 + community_private = Community.create!(:name => ' community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false)
  112 + community_private.add_member(user)
  113 +
  114 + block = CommunitiesBlock.new
  115 + block.expects(:owner).at_least_once.returns(user)
  116 +
  117 + assert_equal 1, block.profile_count
  118 + end
  119 +
105 120 end
... ...
test/unit/enterprises_block_test.rb
... ... @@ -114,4 +114,21 @@ 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
  118 + user = create_user('testuser').person
  119 +
  120 + ent1 = Enterprise.create!(:name => 'test enterprise 1', :identifier => 'ent1', :environment => Environment.default, :public_profile => true)
  121 + ent1.expects(:closed?).returns(false)
  122 + ent1.add_member(user)
  123 +
  124 + ent2 = Enterprise.create!(:name => 'test enterprise 2', :identifier => 'ent2', :environment => Environment.default, :public_profile => false)
  125 + ent2.expects(:closed?).returns(false)
  126 + ent2.add_member(user)
  127 +
  128 + block = EnterprisesBlock.new
  129 + block.expects(:owner).at_least_once.returns(user)
  130 +
  131 + assert_equal 1, block.profile_count
  132 + end
  133 +
117 134 end
... ...