Commit cc9cebd9957b41045787db143b09bf58c3f613c5
Exists in
master
and in
29 other branches
Merge branch 'enterprises' into 'master'
Only shows visible and enabled enterprises on environment statistics block See merge request !441
Showing
4 changed files
with
25 additions
and
1 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
@@ -1989,4 +1989,14 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1989,4 +1989,14 @@ class ProfileTest < ActiveSupport::TestCase | ||
1989 | assert_equal true, profile.disable | 1989 | assert_equal true, profile.disable |
1990 | assert_equal false, profile.visible? | 1990 | assert_equal false, profile.visible? |
1991 | end | 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 | end | 2002 | end |