From 7aa7a2f403416b5f7c527fd60758317d02fc0644 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 31 Mar 2015 14:24:14 -0300 Subject: [PATCH] Fix relevant_commenter badge --- lib/merit/badge_rules.rb | 5 +++-- test/unit/comment_test.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/merit/badge_rules.rb b/lib/merit/badge_rules.rb index 7cf0366..eaf6378 100644 --- a/lib/merit/badge_rules.rb +++ b/lib/merit/badge_rules.rb @@ -22,9 +22,10 @@ module Merit :value => lambda { |article| article.author.present? ? article.author.articles.count : 0 } }, :relevant_commenter => { - :action => 'vote_plugin_profile#vote', + :action => 'vote#create', :default_threshold => 5, - :value => lambda { |voteable| voteable.kind_of?(Comment) ? voteable.votes.count : 0 } + :to => lambda {|vote| vote.voteable.author}, + :value => lambda { |vote| vote.voteable.kind_of?(Comment) ? Vote.for_voteable(vote.voteable).where('vote > 0').count : 0 } } } diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 6e68457..d1d8011 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -31,6 +31,18 @@ class CommentTest < ActiveSupport::TestCase assert_equal 'comment_author', person.badges.first.name end + should 'add badge to author when users vote in his comment' do + GamificationPlugin::Badge.create!(:owner => environment, :name => 'relevant_commenter') + GamificationPlugin.gamification_set_rules(environment) + + comment = create(Comment, :source => article, :author_id => person.id) + 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) } + Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1) + assert_equal [], person.badges + Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) + assert_equal 'relevant_commenter', person.reload.badges.first.name + end + should 'add merit points to comment owner when an user like his comment' do comment = create(Comment, :source => article, :author_id => person.id) -- libgit2 0.21.2