Commit 63c14bfafefdc494c33403aec5d0ecf17161be7e
1 parent
624926b0
Exists in
master
and in
1 other branch
Add points when an user vote a content
Showing
3 changed files
with
59 additions
and
5 deletions
Show diff stats
lib/merit/point_rules.rb
@@ -54,7 +54,15 @@ module Merit | @@ -54,7 +54,15 @@ module Merit | ||
54 | :description => _('Point weight for a voted content'), | 54 | :description => _('Point weight for a voted content'), |
55 | :default_weight => 50 | 55 | :default_weight => 50 |
56 | }, | 56 | }, |
57 | - # TODO comment_voter and article_voter | 57 | + :vote_voter => { |
58 | + :action => 'vote#create', | ||
59 | + :undo_action => 'vote#destroy', | ||
60 | + :to => lambda {|vote| vote.voter}, | ||
61 | + :profile => lambda {|vote| vote.voter}, | ||
62 | + :value => lambda {|vote| 1}, | ||
63 | + :description => _('Point weight for a voter'), | ||
64 | + :default_weight => 10 | ||
65 | + }, | ||
58 | } | 66 | } |
59 | 67 | ||
60 | def weight(category) | 68 | def weight(category) |
test/unit/article_test.rb
@@ -59,4 +59,27 @@ class ArticleTest < ActiveSupport::TestCase | @@ -59,4 +59,27 @@ class ArticleTest < ActiveSupport::TestCase | ||
59 | end | 59 | end |
60 | end | 60 | end |
61 | 61 | ||
62 | + should 'add merit points to community when create a new article' do | ||
63 | + community = fast_create(Community) | ||
64 | + assert_difference 'community.score_points.count' do | ||
65 | + create(Article, :profile_id => community.id, :author => person) | ||
66 | + end | ||
67 | + end | ||
68 | + | ||
69 | + should 'add merit points to voter when he likes an article' do | ||
70 | + article = create(Article, :name => 'Test', :profile => person, :author => person) | ||
71 | + | ||
72 | + assert_difference 'article.author.points(:category => :vote_voter)', 10 do | ||
73 | + Vote.create!(:voter => person, :voteable => article, :vote => 1) | ||
74 | + end | ||
75 | + end | ||
76 | + | ||
77 | + should 'add merit points to voter when he dislikes an article' do | ||
78 | + article = create(Article, :name => 'Test', :profile => person, :author => person) | ||
79 | + | ||
80 | + assert_difference 'article.author.points(:category => :vote_voter)', 10 do | ||
81 | + Vote.create!(:voter => person, :voteable => article, :vote => -1) | ||
82 | + end | ||
83 | + end | ||
84 | + | ||
62 | end | 85 | end |
test/unit/comment_test.rb
@@ -4,11 +4,12 @@ class CommentTest < ActiveSupport::TestCase | @@ -4,11 +4,12 @@ class CommentTest < ActiveSupport::TestCase | ||
4 | 4 | ||
5 | def setup | 5 | def setup |
6 | @person = create_user('testuser').person | 6 | @person = create_user('testuser').person |
7 | - @article = create(TextileArticle, :profile_id => person.id) | 7 | + @author = create_user('testauthoruser').person |
8 | + @article = create(TextileArticle, :profile_id => person.id, :author_id => @author.id) | ||
8 | @environment = Environment.default | 9 | @environment = Environment.default |
9 | GamificationPlugin.gamification_set_rules(@environment) | 10 | GamificationPlugin.gamification_set_rules(@environment) |
10 | end | 11 | end |
11 | - attr_accessor :person, :article, :environment | 12 | + attr_accessor :person, :article, :environment, :author |
12 | 13 | ||
13 | should 'add merit points to author when create a new comment' do | 14 | should 'add merit points to author when create a new comment' do |
14 | create(Comment, :source => article, :author_id => person.id) | 15 | create(Comment, :source => article, :author_id => person.id) |
@@ -52,7 +53,7 @@ class CommentTest < ActiveSupport::TestCase | @@ -52,7 +53,7 @@ class CommentTest < ActiveSupport::TestCase | ||
52 | end | 53 | end |
53 | 54 | ||
54 | should 'subtract merit points to comment owner when an user unlike his comment' do | 55 | should 'subtract merit points to comment owner when an user unlike his comment' do |
55 | - comment = create(Comment, :source => article, :author_id => person.id) | 56 | + comment = create(Comment, :source => article, :author_id => author.id) |
56 | Vote.create!(:voter => person, :voteable => comment, :vote => 1) | 57 | Vote.create!(:voter => person, :voteable => comment, :vote => 1) |
57 | 58 | ||
58 | assert_difference 'comment.author.points', -50 do | 59 | assert_difference 'comment.author.points', -50 do |
@@ -69,7 +70,7 @@ class CommentTest < ActiveSupport::TestCase | @@ -69,7 +70,7 @@ class CommentTest < ActiveSupport::TestCase | ||
69 | end | 70 | end |
70 | 71 | ||
71 | should 'add merit points from comment owner when an user remove a dislike in his comment' do | 72 | should 'add merit points from comment owner when an user remove a dislike in his comment' do |
72 | - comment = create(Comment, :source => article, :author_id => person.id) | 73 | + comment = create(Comment, :source => article, :author_id => author.id) |
73 | Vote.create!(:voter => person, :voteable => comment, :vote => -1) | 74 | Vote.create!(:voter => person, :voteable => comment, :vote => -1) |
74 | 75 | ||
75 | assert_difference 'comment.author.points', 50 do | 76 | assert_difference 'comment.author.points', 50 do |
@@ -77,4 +78,26 @@ class CommentTest < ActiveSupport::TestCase | @@ -77,4 +78,26 @@ class CommentTest < ActiveSupport::TestCase | ||
77 | end | 78 | end |
78 | end | 79 | end |
79 | 80 | ||
81 | + should 'add merit points to article author when create a new comment' do | ||
82 | + assert_difference 'author.score_points.count' do | ||
83 | + create(Comment, :source => article, :author_id => person.id) | ||
84 | + end | ||
85 | + end | ||
86 | + | ||
87 | + should 'add merit points to voter when he likes a comment' do | ||
88 | + comment = create(Comment, :source => article, :author_id => person.id) | ||
89 | + | ||
90 | + assert_difference 'comment.author.points(:category => :vote_voter)', 10 do | ||
91 | + Vote.create!(:voter => person, :voteable => comment, :vote => 1) | ||
92 | + end | ||
93 | + end | ||
94 | + | ||
95 | + should 'add merit points to voter when he dislikes a comment' do | ||
96 | + comment = create(Comment, :source => article, :author_id => person.id) | ||
97 | + | ||
98 | + assert_difference 'comment.author.points(:category => :vote_voter)', 10 do | ||
99 | + Vote.create!(:voter => person, :voteable => comment, :vote => -1) | ||
100 | + end | ||
101 | + end | ||
102 | + | ||
80 | end | 103 | end |