diff --git a/lib/merit/point_rules.rb b/lib/merit/point_rules.rb index ecf0d7b..780d0b5 100644 --- a/lib/merit/point_rules.rb +++ b/lib/merit/point_rules.rb @@ -54,7 +54,15 @@ module Merit :description => _('Point weight for a voted content'), :default_weight => 50 }, - # TODO comment_voter and article_voter + :vote_voter => { + :action => 'vote#create', + :undo_action => 'vote#destroy', + :to => lambda {|vote| vote.voter}, + :profile => lambda {|vote| vote.voter}, + :value => lambda {|vote| 1}, + :description => _('Point weight for a voter'), + :default_weight => 10 + }, } def weight(category) diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index 38ee176..9c654a0 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -59,4 +59,27 @@ class ArticleTest < ActiveSupport::TestCase end end + should 'add merit points to community when create a new article' do + community = fast_create(Community) + assert_difference 'community.score_points.count' do + create(Article, :profile_id => community.id, :author => person) + end + end + + should 'add merit points to voter when he likes an article' do + article = create(Article, :name => 'Test', :profile => person, :author => person) + + assert_difference 'article.author.points(:category => :vote_voter)', 10 do + Vote.create!(:voter => person, :voteable => article, :vote => 1) + end + end + + should 'add merit points to voter when he dislikes an article' do + article = create(Article, :name => 'Test', :profile => person, :author => person) + + assert_difference 'article.author.points(:category => :vote_voter)', 10 do + Vote.create!(:voter => person, :voteable => article, :vote => -1) + end + end + end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 474b040..1517877 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -4,11 +4,12 @@ class CommentTest < ActiveSupport::TestCase def setup @person = create_user('testuser').person - @article = create(TextileArticle, :profile_id => person.id) + @author = create_user('testauthoruser').person + @article = create(TextileArticle, :profile_id => person.id, :author_id => @author.id) @environment = Environment.default GamificationPlugin.gamification_set_rules(@environment) end - attr_accessor :person, :article, :environment + attr_accessor :person, :article, :environment, :author should 'add merit points to author when create a new comment' do create(Comment, :source => article, :author_id => person.id) @@ -52,7 +53,7 @@ class CommentTest < ActiveSupport::TestCase end should 'subtract merit points to comment owner when an user unlike his comment' do - comment = create(Comment, :source => article, :author_id => person.id) + comment = create(Comment, :source => article, :author_id => author.id) Vote.create!(:voter => person, :voteable => comment, :vote => 1) assert_difference 'comment.author.points', -50 do @@ -69,7 +70,7 @@ class CommentTest < ActiveSupport::TestCase end should 'add merit points from comment owner when an user remove a dislike in his comment' do - comment = create(Comment, :source => article, :author_id => person.id) + comment = create(Comment, :source => article, :author_id => author.id) Vote.create!(:voter => person, :voteable => comment, :vote => -1) assert_difference 'comment.author.points', 50 do @@ -77,4 +78,26 @@ class CommentTest < ActiveSupport::TestCase end end + should 'add merit points to article author when create a new comment' do + assert_difference 'author.score_points.count' do + create(Comment, :source => article, :author_id => person.id) + end + end + + should 'add merit points to voter when he likes a comment' do + comment = create(Comment, :source => article, :author_id => person.id) + + assert_difference 'comment.author.points(:category => :vote_voter)', 10 do + Vote.create!(:voter => person, :voteable => comment, :vote => 1) + end + end + + should 'add merit points to voter when he dislikes a comment' do + comment = create(Comment, :source => article, :author_id => person.id) + + assert_difference 'comment.author.points(:category => :vote_voter)', 10 do + Vote.create!(:voter => person, :voteable => comment, :vote => -1) + end + end + end -- libgit2 0.21.2