From 0999076c888067eed97a885dc8f70aa9f6568860 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Mon, 21 Jul 2008 15:36:23 +0000 Subject: [PATCH] ActionItem443: not listing private communities in communities block --- app/models/communities_block.rb | 2 +- test/unit/communities_block_test.rb | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/app/models/communities_block.rb b/app/models/communities_block.rb index 1c719ba..bf4845f 100644 --- a/app/models/communities_block.rb +++ b/app/models/communities_block.rb @@ -36,7 +36,7 @@ class CommunitiesBlock < ProfileListBlock def ids # FIXME when owner is an environment (i.e. listing communities globally # this can become SLOW) - block.owner.communities.map(&:id) + block.owner.communities.select(&:public_profile).map(&:id) end end diff --git a/test/unit/communities_block_test.rb b/test/unit/communities_block_test.rb index b965180..6632587 100644 --- a/test/unit/communities_block_test.rb +++ b/test/unit/communities_block_test.rb @@ -27,9 +27,9 @@ class CommunitiesBlockTest < Test::Unit::TestCase owner = mock block.expects(:owner).returns(owner) - member1 = mock; member1.stubs(:id).returns(1) - member2 = mock; member2.stubs(:id).returns(2) - member3 = mock; member3.stubs(:id).returns(3) + member1 = mock; member1.stubs(:id).returns(1); member1.stubs(:public_profile).returns(true) + member2 = mock; member2.stubs(:id).returns(2); member2.stubs(:public_profile).returns(true) + member3 = mock; member3.stubs(:id).returns(3); member3.stubs(:public_profile).returns(true) owner.expects(:communities).returns([member1, member2, member3]) @@ -71,4 +71,19 @@ class CommunitiesBlockTest < Test::Unit::TestCase assert_equal '', block.footer end + should 'not list non-public communities' do + user = create_user('testuser').person + + public_community = Community.create!(:name => 'test community 1', :identifier => 'comm1', :environment => Environment.default) + public_community.add_member(user) + + private_community = Community.create!(:name => 'test community 2', :identifier => 'comm2', :environment => Environment.default, :public_profile => false) + private_community.add_member(user) + + block = CommunitiesBlock.new + block.expects(:owner).returns(user) + + assert_equal [public_community], block.profiles + end + end -- libgit2 0.21.2