Commit 86405d39f4d709638c95bd47973360674fab3c91
1 parent
6284311d
Exists in
master
and in
1 other branch
Ignore levels with null value
Showing
2 changed files
with
14 additions
and
1 deletions
Show diff stats
lib/ext/profile.rb
| @@ -8,7 +8,7 @@ class Profile | @@ -8,7 +8,7 @@ class Profile | ||
| 8 | settings = GamificationPlugin.settings(environment) | 8 | settings = GamificationPlugin.settings(environment) |
| 9 | score = self.points | 9 | score = self.points |
| 10 | last_level = 0 | 10 | last_level = 0 |
| 11 | - (settings.get_setting(:rank_rules) || []).sort_by {|r| r[:points].to_i }.each_with_index do |rule, i| | 11 | + (settings.get_setting(:rank_rules) || []).reject{|r| r[:points].blank?}.sort_by {|r| r[:points].to_i }.each_with_index do |rule, i| |
| 12 | return last_level if score < rule[:points].to_i | 12 | return last_level if score < rule[:points].to_i |
| 13 | last_level = rule[:level] || i+1 | 13 | last_level = rule[:level] || i+1 |
| 14 | end | 14 | end |
test/unit/profile_test.rb
| @@ -21,6 +21,19 @@ class ProfileTest < ActiveSupport::TestCase | @@ -21,6 +21,19 @@ class ProfileTest < ActiveSupport::TestCase | ||
| 21 | assert_equal 2, profile.gamification_plugin_calculate_level | 21 | assert_equal 2, profile.gamification_plugin_calculate_level |
| 22 | end | 22 | end |
| 23 | 23 | ||
| 24 | + should 'calculate profile level ignoring blank values' do | ||
| 25 | + @settings.set_setting(:rank_rules, [ | ||
| 26 | + {:points => 10}, | ||
| 27 | + {:points => 20}, | ||
| 28 | + {:points => 30}, | ||
| 29 | + {:points => ""}, | ||
| 30 | + {:points => nil}, | ||
| 31 | + ]) | ||
| 32 | + @settings.save! | ||
| 33 | + profile.stubs(:points).returns(25) | ||
| 34 | + assert_equal 2, profile.gamification_plugin_calculate_level | ||
| 35 | + end | ||
| 36 | + | ||
| 24 | should 'calculate profile last level' do | 37 | should 'calculate profile last level' do |
| 25 | profile.stubs(:points).returns(35) | 38 | profile.stubs(:points).returns(35) |
| 26 | assert_equal 3, profile.gamification_plugin_calculate_level | 39 | assert_equal 3, profile.gamification_plugin_calculate_level |