From 62912d1e617a23c27bf5cdd6ccaac038816a80c7 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Wed, 16 Sep 2009 16:09:08 -0300 Subject: [PATCH] ActionItem1237: fixing profile_count --- app/models/people_block.rb | 4 ++++ app/models/profile_list_block.rb | 4 ++-- test/unit/people_block_test.rb | 14 +++++++++++--- test/unit/profile_list_block_test.rb | 34 +++++++++++++++++++++++++++++----- 4 files changed, 46 insertions(+), 10 deletions(-) diff --git a/app/models/people_block.rb b/app/models/people_block.rb index 783938c..88a226d 100644 --- a/app/models/people_block.rb +++ b/app/models/people_block.rb @@ -28,4 +28,8 @@ class PeopleBlock < ProfileListBlock end end + def profile_count + owner.people.count(:conditions => {:public_profile => true}) + end + end diff --git a/app/models/profile_list_block.rb b/app/models/profile_list_block.rb index 8268d7f..392b6fa 100644 --- a/app/models/profile_list_block.rb +++ b/app/models/profile_list_block.rb @@ -89,8 +89,8 @@ class ProfileListBlock < Block title.gsub('{#}', profile_count.to_s) end - def profile_count #defined in children - 0 + def profile_count + owner.profiles.count(:conditions => {:public_profile => true}) end end diff --git a/test/unit/people_block_test.rb b/test/unit/people_block_test.rb index 92647e9..88c2b8c 100644 --- a/test/unit/people_block_test.rb +++ b/test/unit/people_block_test.rb @@ -24,9 +24,8 @@ class PeopleBlockTest < ActiveSupport::TestCase end should 'list people' do - owner = mock - owner.expects(:id).returns(99) - Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => 99, :public_profile => true}, :limit => 6, :order => 'random()').returns([]) + owner = Environment.create!(:name => 'test environment') + Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => owner.id, :public_profile => true}, :limit => 6, :order => 'random()').returns([]) block = PeopleBlock.new block.expects(:owner).returns(owner).at_least_once block.content @@ -41,4 +40,13 @@ class PeopleBlockTest < ActiveSupport::TestCase instance_eval(&block.footer) end + should 'count number of public people' do + env = Environment.create!(:name => 'test environment') + private_p = create_user('private', {:environment => env}, {:public_profile => false}) + public_p = create_user('public', {:environment => env}, {:public_profile => true}) + + env.boxes.first.blocks << block = PeopleBlock.new + assert_equal 1, block.profile_count + end + end diff --git a/test/unit/profile_list_block_test.rb b/test/unit/profile_list_block_test.rb index a4585c5..9583f93 100644 --- a/test/unit/profile_list_block_test.rb +++ b/test/unit/profile_list_block_test.rb @@ -24,7 +24,7 @@ class ProfileListBlockTest < Test::Unit::TestCase person2 = create_user('testperson2').person person3 = create_user('testperson3').person - owner = create_user('mytestuser').person + owner = Environment.create!(:name => 'test env') block = ProfileListBlock.new owner.boxes.first.blocks << block block.save! @@ -68,12 +68,36 @@ class ProfileListBlockTest < Test::Unit::TestCase end should 'provide view_title' do - p = ProfileListBlock.new(:title => 'Title from block') - assert_equal 'Title from block', p.view_title + env = Environment.create!(:name => 'test env') + block = ProfileListBlock.new(:title => 'Title from block') + env.boxes.first.blocks << block + block.save! + assert_equal 'Title from block', block.view_title end should 'provide view title with variables' do - p = ProfileListBlock.new(:title => '{#} members') - assert_equal '0 members', p.view_title + env = Environment.create!(:name => 'test env') + block = ProfileListBlock.new(:title => '{#} members') + env.boxes.first.blocks << block + block.save! + assert_equal '0 members', block.view_title + end + + should 'count number of public profiles' do + env = Environment.create!(:name => 'test env') + block = ProfileListBlock.new + env.boxes.first.blocks << block + block.save! + + priv_p = create_user('private', {:environment => env}, {:public_profile => false}) + pub_p = create_user('public', {:environment => env}, {:public_profile => true}) + + priv_c = Community.create!(:name => 'com 1', :public_profile => false, :environment => env) + pub_c = Community.create!(:name => 'com 2', :public_profile => true , :environment => env) + + priv_e = Enterprise.create!(:name => 'ent 1', :identifier => 'ent1', :public_profile => false , :environment => env) + pub_e = Enterprise.create!(:name => 'ent 2', :identifier => 'ent2', :public_profile => true , :environment => env) + + assert_equal 3, block.profile_count end end -- libgit2 0.21.2