Commit 4503f6c538d6e71955ead838601d33ae74dd9669
1 parent
f683bce9
Exists in
master
and in
1 other branch
New badge for comments received
Showing
2 changed files
with
14 additions
and
0 deletions
Show diff stats
lib/merit/badge_rules.rb
... | ... | @@ -15,6 +15,12 @@ module Merit |
15 | 15 | :to => :author, |
16 | 16 | :value => lambda { |comment| comment.author.present? ? comment.author.comments.count : 0 } |
17 | 17 | }, |
18 | + :comment_received => { | |
19 | + :action => 'comment#create', | |
20 | + :default_threshold => 5, | |
21 | + :to => lambda {|comment| comment.source.author}, | |
22 | + :value => lambda { |comment| comment.source.author.present? ? Comment.where(:source_id => Article.where(:author_id => comment.source.author.id)).count : 0 } | |
23 | + }, | |
18 | 24 | :article_author => { |
19 | 25 | :action => 'article#create', |
20 | 26 | :default_threshold => 5, | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -32,6 +32,14 @@ class CommentTest < ActiveSupport::TestCase |
32 | 32 | assert_equal 'comment_author', person.badges.first.name |
33 | 33 | end |
34 | 34 | |
35 | + should 'add merit badge to source author when create 5 new comments' do | |
36 | + GamificationPlugin::Badge.create!(:owner => environment, :name => 'comment_received') | |
37 | + GamificationPlugin.gamification_set_rules(environment) | |
38 | + | |
39 | + 5.times { create(Comment, :source => article, :author_id => person.id) } | |
40 | + assert_equal 'comment_received', author.badges.first.name | |
41 | + end | |
42 | + | |
35 | 43 | should 'add badge to author when users like his comment' do |
36 | 44 | GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received') |
37 | 45 | GamificationPlugin.gamification_set_rules(environment) | ... | ... |