Commit 0ee65a55b16910bea00ad348f2d535b04e7dec9b
Exists in
master
and in
1 other branch
Merge branch 'working' into 'master'
Avoid recursive loop saving profile See merge request !12
Showing
4 changed files
with
21 additions
and
9 deletions
Show diff stats
lib/merit/point_rules.rb
| ... | ... | @@ -61,7 +61,6 @@ module Merit |
| 61 | 61 | action: 'vote#create', |
| 62 | 62 | undo_action: 'vote#destroy', |
| 63 | 63 | to: lambda {|vote| vote.voteable.author}, |
| 64 | - profile: lambda {|vote| vote.voteable.profile}, | |
| 65 | 64 | value: lambda {|vote| vote.vote}, |
| 66 | 65 | description: _('Author of a voted content'), |
| 67 | 66 | default_weight: 20, |
| ... | ... | @@ -71,7 +70,6 @@ module Merit |
| 71 | 70 | action: 'vote#create', |
| 72 | 71 | undo_action: 'vote#destroy', |
| 73 | 72 | to: lambda {|vote| vote.voteable}, |
| 74 | - profile: lambda {|vote| vote.voteable.profile}, | |
| 75 | 73 | value: lambda {|vote| vote.vote}, |
| 76 | 74 | description: _('Voted content'), |
| 77 | 75 | default_weight: 30, |
| ... | ... | @@ -101,7 +99,6 @@ module Merit |
| 101 | 99 | value: 1, |
| 102 | 100 | description: _('Profile Completion'), |
| 103 | 101 | default_weight: 100, |
| 104 | - model_name: "User", | |
| 105 | 102 | condition: lambda {|person, profile| person.person? and person.profile_completion_score_condition }, |
| 106 | 103 | }, |
| 107 | 104 | follower: { |
| ... | ... | @@ -159,8 +156,10 @@ module Merit |
| 159 | 156 | [setting[:action], setting[:undo_action]].compact.zip([1, -1]).each do |action, signal| |
| 160 | 157 | options = {on: action, to: setting[:to], category: categorization.id.to_s} |
| 161 | 158 | options[:model_name] = setting[:model] unless setting[:model].nil? |
| 162 | - score lambda {|target| signal * calculate_score(target, categorization.weight, setting[:value])}, options do |target| | |
| 163 | - condition(setting, target, categorization.profile) | |
| 159 | + weight = categorization.weight | |
| 160 | + profile = categorization.profile | |
| 161 | + score lambda {|target| signal * calculate_score(target, weight, setting[:value])}, options do |target| | |
| 162 | + condition(setting, target, profile) | |
| 164 | 163 | end |
| 165 | 164 | end |
| 166 | 165 | end | ... | ... |
lib/merit/rank_observer.rb
| ... | ... | @@ -5,7 +5,7 @@ module Merit |
| 5 | 5 | merit = changed_data[:merit_object] |
| 6 | 6 | if merit.kind_of?(Merit::Score::Point) |
| 7 | 7 | profile = merit.score.sash.profile |
| 8 | - profile.update_attribute(:level, profile.gamification_plugin_calculate_level) if profile.present? | |
| 8 | + profile.update_column(:level, profile.gamification_plugin_calculate_level) if profile.present? | |
| 9 | 9 | end |
| 10 | 10 | end |
| 11 | 11 | end | ... | ... |
test/unit/profile_test.rb
| ... | ... | @@ -44,6 +44,18 @@ class ProfileTest < ActiveSupport::TestCase |
| 44 | 44 | assert_equal 1, profile.gamification_plugin_calculate_level |
| 45 | 45 | end |
| 46 | 46 | |
| 47 | + should 'update profile level when a profile action makes a score with zero point' do | |
| 48 | + #avoid loop when the score changes by zero and | |
| 49 | + person = create_user('testuser').person | |
| 50 | + Person.any_instance.stubs(:is_profile_complete?).returns(true) | |
| 51 | + create_point_rule_definition('profile_completion', nil, {value: 0}) | |
| 52 | + GamificationPlugin.gamification_set_rules(environment) | |
| 53 | + assert_equal 0, person.level | |
| 54 | + assert_nothing_raised do | |
| 55 | + person.save | |
| 56 | + end | |
| 57 | + end | |
| 58 | + | |
| 47 | 59 | should 'update profile level when the score changes' do |
| 48 | 60 | create_point_rule_definition('article_author') |
| 49 | 61 | community = fast_create(Community) | ... | ... |
views/gamification_plugin_badges/show.html.erb
| ... | ... | @@ -24,9 +24,10 @@ |
| 24 | 24 | |
| 25 | 25 | <p> |
| 26 | 26 | <b>Threshold:</b> |
| 27 | - <% @gamification_plugin_badge.custom_fields.is_a? Hash %> | |
| 28 | - <% @gamification_plugin_badge.custom_fields.keys.each do |key| %> | |
| 29 | - <div><%= _(key) + ': ' + @gamification_plugin_badge.custom_fields[key].fetch("threshold", "") %></div> | |
| 27 | + <% if @gamification_plugin_badge.custom_fields.is_a? Hash %> | |
| 28 | + <% @gamification_plugin_badge.custom_fields.keys.each do |key| %> | |
| 29 | + <div><%= _(key) + ': ' + @gamification_plugin_badge.custom_fields[key].fetch("threshold", "") %></div> | |
| 30 | + <% end %> | |
| 30 | 31 | <% end %> |
| 31 | 32 | </p> |
| 32 | 33 | ... | ... |