Commit 86405d39f4d709638c95bd47973360674fab3c91

Authored by Victor Costa
1 parent 6284311d

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 8 settings = GamificationPlugin.settings(environment)
9 9 score = self.points
10 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 12 return last_level if score < rule[:points].to_i
13 13 last_level = rule[:level] || i+1
14 14 end
... ...
test/unit/profile_test.rb
... ... @@ -21,6 +21,19 @@ class ProfileTest &lt; ActiveSupport::TestCase
21 21 assert_equal 2, profile.gamification_plugin_calculate_level
22 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 37 should 'calculate profile last level' do
25 38 profile.stubs(:points).returns(35)
26 39 assert_equal 3, profile.gamification_plugin_calculate_level
... ...