Commit e8a3a54e2ff1f5115a7f79d9fc044df988c5d6d1
1 parent
7cc3998c
Exists in
master
and in
22 other branches
show only visible and enabled enterprises
Created a scope to show only visible and enabled enterprises on environment statistics block. Bug fix from #2783
Showing
4 changed files
with
26 additions
and
2 deletions
Show diff stats
app/models/profile.rb
| @@ -123,6 +123,7 @@ class Profile < ActiveRecord::Base | @@ -123,6 +123,7 @@ class Profile < ActiveRecord::Base | ||
| 123 | scope :visible, :conditions => { :visible => true } | 123 | scope :visible, :conditions => { :visible => true } |
| 124 | scope :disabled, :conditions => { :visible => false } | 124 | scope :disabled, :conditions => { :visible => false } |
| 125 | scope :public, :conditions => { :visible => true, :public_profile => true } | 125 | scope :public, :conditions => { :visible => true, :public_profile => true } |
| 126 | + scope :enabled, :conditions => { :enabled => true } | ||
| 126 | 127 | ||
| 127 | # Subclasses must override this method | 128 | # Subclasses must override this method |
| 128 | scope :more_popular | 129 | scope :more_popular |
plugins/statistics/lib/statistics_block.rb
| @@ -85,7 +85,7 @@ class StatisticsBlock < Block | @@ -85,7 +85,7 @@ class StatisticsBlock < Block | ||
| 85 | 85 | ||
| 86 | def enterprises | 86 | def enterprises |
| 87 | if owner.kind_of?(Environment) || owner.kind_of?(Person) | 87 | if owner.kind_of?(Environment) || owner.kind_of?(Person) |
| 88 | - owner.enterprises.visible.count | 88 | + owner.enterprises.visible.enabled.count |
| 89 | else | 89 | else |
| 90 | 0 | 90 | 0 |
| 91 | end | 91 | end |
plugins/statistics/test/unit/statistics_block_test.rb
| @@ -126,6 +126,19 @@ class StatisticsBlockTest < ActiveSupport::TestCase | @@ -126,6 +126,19 @@ class StatisticsBlockTest < ActiveSupport::TestCase | ||
| 126 | assert_equal 2, b.enterprises | 126 | assert_equal 2, b.enterprises |
| 127 | end | 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 | should 'categories return the amount of categories of the Environment' do | 142 | should 'categories return the amount of categories of the Environment' do |
| 130 | b = StatisticsBlock.new | 143 | b = StatisticsBlock.new |
| 131 | e = fast_create(Environment) | 144 | e = fast_create(Environment) |
test/unit/profile_test.rb
| @@ -1973,4 +1973,14 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1973,4 +1973,14 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 1973 | assert_equal true, profile.disable | 1973 | assert_equal true, profile.disable |
| 1974 | assert_equal false, profile.visible? | 1974 | assert_equal false, profile.visible? |
| 1975 | end | 1975 | end |
| 1976 | -end | 1976 | + |
| 1977 | + should 'fetch enabled profiles' do | ||
| 1978 | + p1 = fast_create(Profile, :enabled => true) | ||
| 1979 | + p2 = fast_create(Profile, :enabled => true) | ||
| 1980 | + p3 = fast_create(Profile, :enabled => false) | ||
| 1981 | + | ||
| 1982 | + assert_includes Profile.enabled, p1 | ||
| 1983 | + assert_includes Profile.enabled, p2 | ||
| 1984 | + assert_not_includes Profile.enabled, p3 | ||
| 1985 | + end | ||
| 1986 | +end | ||
| 1977 | \ No newline at end of file | 1987 | \ No newline at end of file |