Commit e8a3a54e2ff1f5115a7f79d9fc044df988c5d6d1
1 parent
7cc3998c
Exists in
master
and in
29 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 | 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
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
... | ... | @@ -1973,4 +1973,14 @@ class ProfileTest < ActiveSupport::TestCase |
1973 | 1973 | assert_equal true, profile.disable |
1974 | 1974 | assert_equal false, profile.visible? |
1975 | 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 | 1987 | \ No newline at end of file | ... | ... |