diff --git a/lib/merit/badge_rules.rb b/lib/merit/badge_rules.rb index 8baa62e..e339a28 100644 --- a/lib/merit/badge_rules.rb +++ b/lib/merit/badge_rules.rb @@ -15,6 +15,12 @@ module Merit :to => :author, :value => lambda { |comment| comment.author.present? ? comment.author.comments.count : 0 } }, + :comment_received => { + :action => 'comment#create', + :default_threshold => 5, + :to => lambda {|comment| comment.source.author}, + :value => lambda { |comment| comment.source.author.present? ? Comment.where(:source_id => Article.where(:author_id => comment.source.author.id)).count : 0 } + }, :article_author => { :action => 'article#create', :default_threshold => 5, diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index e69e7fa..1581a84 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -32,6 +32,14 @@ class CommentTest < ActiveSupport::TestCase assert_equal 'comment_author', person.badges.first.name end + should 'add merit badge to source author when create 5 new comments' do + GamificationPlugin::Badge.create!(:owner => environment, :name => 'comment_received') + GamificationPlugin.gamification_set_rules(environment) + + 5.times { create(Comment, :source => article, :author_id => person.id) } + assert_equal 'comment_received', author.badges.first.name + end + should 'add badge to author when users like his comment' do GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received') GamificationPlugin.gamification_set_rules(environment) -- libgit2 0.21.2