Commit 7aa7a2f403416b5f7c527fd60758317d02fc0644
1 parent
a8aed5d9
Exists in
master
and in
1 other branch
Fix relevant_commenter badge
Showing
2 changed files
with
15 additions
and
2 deletions
Show diff stats
lib/merit/badge_rules.rb
| ... | ... | @@ -22,9 +22,10 @@ module Merit |
| 22 | 22 | :value => lambda { |article| article.author.present? ? article.author.articles.count : 0 } |
| 23 | 23 | }, |
| 24 | 24 | :relevant_commenter => { |
| 25 | - :action => 'vote_plugin_profile#vote', | |
| 25 | + :action => 'vote#create', | |
| 26 | 26 | :default_threshold => 5, |
| 27 | - :value => lambda { |voteable| voteable.kind_of?(Comment) ? voteable.votes.count : 0 } | |
| 27 | + :to => lambda {|vote| vote.voteable.author}, | |
| 28 | + :value => lambda { |vote| vote.voteable.kind_of?(Comment) ? Vote.for_voteable(vote.voteable).where('vote > 0').count : 0 } | |
| 28 | 29 | } |
| 29 | 30 | } |
| 30 | 31 | ... | ... |
test/unit/comment_test.rb
| ... | ... | @@ -31,6 +31,18 @@ class CommentTest < ActiveSupport::TestCase |
| 31 | 31 | assert_equal 'comment_author', person.badges.first.name |
| 32 | 32 | end |
| 33 | 33 | |
| 34 | + should 'add badge to author when users vote in his comment' do | |
| 35 | + GamificationPlugin::Badge.create!(:owner => environment, :name => 'relevant_commenter') | |
| 36 | + GamificationPlugin.gamification_set_rules(environment) | |
| 37 | + | |
| 38 | + comment = create(Comment, :source => article, :author_id => person.id) | |
| 39 | + 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) } | |
| 40 | + Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1) | |
| 41 | + assert_equal [], person.badges | |
| 42 | + Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) | |
| 43 | + assert_equal 'relevant_commenter', person.reload.badges.first.name | |
| 44 | + end | |
| 45 | + | |
| 34 | 46 | should 'add merit points to comment owner when an user like his comment' do |
| 35 | 47 | comment = create(Comment, :source => article, :author_id => person.id) |
| 36 | 48 | ... | ... |