From e8a3a54e2ff1f5115a7f79d9fc044df988c5d6d1 Mon Sep 17 00:00:00 2001 From: Eduardo Passos Date: Wed, 28 Jan 2015 18:16:35 -0300 Subject: [PATCH] show only visible and enabled enterprises --- app/models/profile.rb | 1 + plugins/statistics/lib/statistics_block.rb | 2 +- plugins/statistics/test/unit/statistics_block_test.rb | 13 +++++++++++++ test/unit/profile_test.rb | 12 +++++++++++- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/app/models/profile.rb b/app/models/profile.rb index 4e309de..5b5d237 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -123,6 +123,7 @@ class Profile < ActiveRecord::Base scope :visible, :conditions => { :visible => true } scope :disabled, :conditions => { :visible => false } scope :public, :conditions => { :visible => true, :public_profile => true } + scope :enabled, :conditions => { :enabled => true } # Subclasses must override this method scope :more_popular diff --git a/plugins/statistics/lib/statistics_block.rb b/plugins/statistics/lib/statistics_block.rb index 493c010..ec4bccc 100644 --- a/plugins/statistics/lib/statistics_block.rb +++ b/plugins/statistics/lib/statistics_block.rb @@ -85,7 +85,7 @@ class StatisticsBlock < Block def enterprises if owner.kind_of?(Environment) || owner.kind_of?(Person) - owner.enterprises.visible.count + owner.enterprises.visible.enabled.count else 0 end diff --git a/plugins/statistics/test/unit/statistics_block_test.rb b/plugins/statistics/test/unit/statistics_block_test.rb index ad7c28e..921d40a 100644 --- a/plugins/statistics/test/unit/statistics_block_test.rb +++ b/plugins/statistics/test/unit/statistics_block_test.rb @@ -126,6 +126,19 @@ class StatisticsBlockTest < ActiveSupport::TestCase assert_equal 2, b.enterprises end + should 'return the amount of enabled enterprises' do + b = StatisticsBlock.new + e = fast_create(Environment) + + fast_create(Enterprise, :environment_id => e.id) + fast_create(Enterprise, :environment_id => e.id) + fast_create(Enterprise, :enabled => false, :environment_id => e.id) + + b.expects(:owner).at_least_once.returns(e) + + assert_equal 2, b.enterprises + end + should 'categories return the amount of categories of the Environment' do b = StatisticsBlock.new e = fast_create(Environment) diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index 0e74868..c9a8c35 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -1973,4 +1973,14 @@ class ProfileTest < ActiveSupport::TestCase assert_equal true, profile.disable assert_equal false, profile.visible? end -end + + should 'fetch enabled profiles' do + p1 = fast_create(Profile, :enabled => true) + p2 = fast_create(Profile, :enabled => true) + p3 = fast_create(Profile, :enabled => false) + + assert_includes Profile.enabled, p1 + assert_includes Profile.enabled, p2 + assert_not_includes Profile.enabled, p3 + end +end \ No newline at end of file -- libgit2 0.21.2