Commit cc9cebd9957b41045787db143b09bf58c3f613c5

Authored by Braulio Bhavamitra
2 parents c2fc6239 e8a3a54e

Merge branch 'enterprises' into 'master'

Only shows visible and enabled enterprises on environment statistics block

See merge request !441
app/models/profile.rb
... ... @@ -123,6 +123,7 @@ class Profile < ActiveRecord::Base
123 123 scope :visible, :conditions => { :visible => true }
124 124 scope :disabled, :conditions => { :visible => false }
125 125 scope :public, :conditions => { :visible => true, :public_profile => true }
  126 + scope :enabled, :conditions => { :enabled => true }
126 127  
127 128 # Subclasses must override this method
128 129 scope :more_popular
... ...
plugins/statistics/lib/statistics_block.rb
... ... @@ -85,7 +85,7 @@ class StatisticsBlock < Block
85 85  
86 86 def enterprises
87 87 if owner.kind_of?(Environment) || owner.kind_of?(Person)
88   - owner.enterprises.visible.count
  88 + owner.enterprises.visible.enabled.count
89 89 else
90 90 0
91 91 end
... ...
plugins/statistics/test/unit/statistics_block_test.rb
... ... @@ -126,6 +126,19 @@ class StatisticsBlockTest < ActiveSupport::TestCase
126 126 assert_equal 2, b.enterprises
127 127 end
128 128  
  129 + should 'return the amount of enabled enterprises' do
  130 + b = StatisticsBlock.new
  131 + e = fast_create(Environment)
  132 +
  133 + fast_create(Enterprise, :environment_id => e.id)
  134 + fast_create(Enterprise, :environment_id => e.id)
  135 + fast_create(Enterprise, :enabled => false, :environment_id => e.id)
  136 +
  137 + b.expects(:owner).at_least_once.returns(e)
  138 +
  139 + assert_equal 2, b.enterprises
  140 + end
  141 +
129 142 should 'categories return the amount of categories of the Environment' do
130 143 b = StatisticsBlock.new
131 144 e = fast_create(Environment)
... ...
test/unit/profile_test.rb
... ... @@ -1989,4 +1989,14 @@ class ProfileTest < ActiveSupport::TestCase
1989 1989 assert_equal true, profile.disable
1990 1990 assert_equal false, profile.visible?
1991 1991 end
  1992 +
  1993 + should 'fetch enabled profiles' do
  1994 + p1 = fast_create(Profile, :enabled => true)
  1995 + p2 = fast_create(Profile, :enabled => true)
  1996 + p3 = fast_create(Profile, :enabled => false)
  1997 +
  1998 + assert_includes Profile.enabled, p1
  1999 + assert_includes Profile.enabled, p2
  2000 + assert_not_includes Profile.enabled, p3
  2001 + end
1992 2002 end
... ...