Commit 62912d1e617a23c27bf5cdd6ccaac038816a80c7
Committed by
Antonio Terceiro
1 parent
0d2e6dde
Exists in
master
and in
28 other branches
ActionItem1237: fixing profile_count
* fixing ProfileListBlock profile_count * making PeopleBlock count public people on profile_count
Showing
4 changed files
with
46 additions
and
10 deletions
Show diff stats
app/models/people_block.rb
app/models/profile_list_block.rb
@@ -89,8 +89,8 @@ class ProfileListBlock < Block | @@ -89,8 +89,8 @@ class ProfileListBlock < Block | ||
89 | title.gsub('{#}', profile_count.to_s) | 89 | title.gsub('{#}', profile_count.to_s) |
90 | end | 90 | end |
91 | 91 | ||
92 | - def profile_count #defined in children | ||
93 | - 0 | 92 | + def profile_count |
93 | + owner.profiles.count(:conditions => {:public_profile => true}) | ||
94 | end | 94 | end |
95 | 95 | ||
96 | end | 96 | end |
test/unit/people_block_test.rb
@@ -24,9 +24,8 @@ class PeopleBlockTest < ActiveSupport::TestCase | @@ -24,9 +24,8 @@ class PeopleBlockTest < ActiveSupport::TestCase | ||
24 | end | 24 | end |
25 | 25 | ||
26 | should 'list people' do | 26 | should 'list people' do |
27 | - owner = mock | ||
28 | - owner.expects(:id).returns(99) | ||
29 | - Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => 99, :public_profile => true}, :limit => 6, :order => 'random()').returns([]) | 27 | + owner = Environment.create!(:name => 'test environment') |
28 | + Person.expects(:find).with(:all, :select => 'id', :conditions => { :environment_id => owner.id, :public_profile => true}, :limit => 6, :order => 'random()').returns([]) | ||
30 | block = PeopleBlock.new | 29 | block = PeopleBlock.new |
31 | block.expects(:owner).returns(owner).at_least_once | 30 | block.expects(:owner).returns(owner).at_least_once |
32 | block.content | 31 | block.content |
@@ -41,4 +40,13 @@ class PeopleBlockTest < ActiveSupport::TestCase | @@ -41,4 +40,13 @@ class PeopleBlockTest < ActiveSupport::TestCase | ||
41 | instance_eval(&block.footer) | 40 | instance_eval(&block.footer) |
42 | end | 41 | end |
43 | 42 | ||
43 | + should 'count number of public people' do | ||
44 | + env = Environment.create!(:name => 'test environment') | ||
45 | + private_p = create_user('private', {:environment => env}, {:public_profile => false}) | ||
46 | + public_p = create_user('public', {:environment => env}, {:public_profile => true}) | ||
47 | + | ||
48 | + env.boxes.first.blocks << block = PeopleBlock.new | ||
49 | + assert_equal 1, block.profile_count | ||
50 | + end | ||
51 | + | ||
44 | end | 52 | end |
test/unit/profile_list_block_test.rb
@@ -24,7 +24,7 @@ class ProfileListBlockTest < Test::Unit::TestCase | @@ -24,7 +24,7 @@ class ProfileListBlockTest < Test::Unit::TestCase | ||
24 | person2 = create_user('testperson2').person | 24 | person2 = create_user('testperson2').person |
25 | person3 = create_user('testperson3').person | 25 | person3 = create_user('testperson3').person |
26 | 26 | ||
27 | - owner = create_user('mytestuser').person | 27 | + owner = Environment.create!(:name => 'test env') |
28 | block = ProfileListBlock.new | 28 | block = ProfileListBlock.new |
29 | owner.boxes.first.blocks << block | 29 | owner.boxes.first.blocks << block |
30 | block.save! | 30 | block.save! |
@@ -68,12 +68,36 @@ class ProfileListBlockTest < Test::Unit::TestCase | @@ -68,12 +68,36 @@ class ProfileListBlockTest < Test::Unit::TestCase | ||
68 | end | 68 | end |
69 | 69 | ||
70 | should 'provide view_title' do | 70 | should 'provide view_title' do |
71 | - p = ProfileListBlock.new(:title => 'Title from block') | ||
72 | - assert_equal 'Title from block', p.view_title | 71 | + env = Environment.create!(:name => 'test env') |
72 | + block = ProfileListBlock.new(:title => 'Title from block') | ||
73 | + env.boxes.first.blocks << block | ||
74 | + block.save! | ||
75 | + assert_equal 'Title from block', block.view_title | ||
73 | end | 76 | end |
74 | 77 | ||
75 | should 'provide view title with variables' do | 78 | should 'provide view title with variables' do |
76 | - p = ProfileListBlock.new(:title => '{#} members') | ||
77 | - assert_equal '0 members', p.view_title | 79 | + env = Environment.create!(:name => 'test env') |
80 | + block = ProfileListBlock.new(:title => '{#} members') | ||
81 | + env.boxes.first.blocks << block | ||
82 | + block.save! | ||
83 | + assert_equal '0 members', block.view_title | ||
84 | + end | ||
85 | + | ||
86 | + should 'count number of public profiles' do | ||
87 | + env = Environment.create!(:name => 'test env') | ||
88 | + block = ProfileListBlock.new | ||
89 | + env.boxes.first.blocks << block | ||
90 | + block.save! | ||
91 | + | ||
92 | + priv_p = create_user('private', {:environment => env}, {:public_profile => false}) | ||
93 | + pub_p = create_user('public', {:environment => env}, {:public_profile => true}) | ||
94 | + | ||
95 | + priv_c = Community.create!(:name => 'com 1', :public_profile => false, :environment => env) | ||
96 | + pub_c = Community.create!(:name => 'com 2', :public_profile => true , :environment => env) | ||
97 | + | ||
98 | + priv_e = Enterprise.create!(:name => 'ent 1', :identifier => 'ent1', :public_profile => false , :environment => env) | ||
99 | + pub_e = Enterprise.create!(:name => 'ent 2', :identifier => 'ent2', :public_profile => true , :environment => env) | ||
100 | + | ||
101 | + assert_equal 3, block.profile_count | ||
78 | end | 102 | end |
79 | end | 103 | end |