Commit b67299d0229ed8acbf035b94c77fe19812c97f1b
1 parent
17f41d4a
Exists in
master
Break down voted rule in positive and negative
Showing
4 changed files
with
44 additions
and
33 deletions
Show diff stats
lib/merit/point_rules.rb
... | ... | @@ -66,16 +66,27 @@ module Merit |
66 | 66 | condition: lambda {|article, profile| article.profile.present? and article.profile.community? }, |
67 | 67 | target_url: lambda {|article| article.url}, |
68 | 68 | }, |
69 | - vote_voteable_author: { | |
69 | + vote_voteable_author_positive: { | |
70 | 70 | action: 'vote#create', |
71 | 71 | undo_action: 'vote#destroy', |
72 | 72 | to: lambda {|vote| vote.voteable.author}, |
73 | - value: lambda {|vote| vote.vote}, | |
74 | - description: _('Author of a voted content'), | |
73 | + value: lambda {|vote| 1}, | |
74 | + description: _('Author of a content that receive a positive vote'), | |
75 | 75 | default_weight: 20, |
76 | 76 | target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, |
77 | 77 | target_url: lambda {|vote| vote.voteable.url}, |
78 | - condition: lambda {|vote, profile| vote.voter != vote.voteable.author } | |
78 | + condition: lambda {|vote, profile| vote.vote>0 && vote.voter != vote.voteable.author } | |
79 | + }, | |
80 | + vote_voteable_author_negative: { | |
81 | + action: 'vote#create', | |
82 | + undo_action: 'vote#destroy', | |
83 | + to: lambda {|vote| vote.voteable.author}, | |
84 | + value: lambda {|vote| 1}, | |
85 | + description: _('Author of a content that receive a negative vote'), | |
86 | + default_weight: -20, | |
87 | + target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, | |
88 | + target_url: lambda {|vote| vote.voteable.url}, | |
89 | + condition: lambda {|vote, profile| vote.vote<0 && vote.voter != vote.voteable.author } | |
79 | 90 | }, |
80 | 91 | vote_voteable: { |
81 | 92 | action: 'vote#create', | ... | ... |
script/export_ranking.rb
... | ... | @@ -18,8 +18,8 @@ profile_ids.each do |profile_id| |
18 | 18 | puts "Creating spreadsheet for #{profile_name}" |
19 | 19 | |
20 | 20 | CSV.open( "ranking_gamification_for_#{profile_name}.csv", 'w' ) do |csv| |
21 | - categories = [:article_author, :comment_author, :comment_article_author, :vote_voteable_author, :vote_voter, :follower, :followed_article_author] | |
22 | - categories_labels = ['autor do artigo', 'autor do comentário', 'comentário recebido no meu artigo', 'voto em meu conteúdo', 'voto realizado', 'seguir artigo', 'autor de artigo seguido'] | |
21 | + categories = [:article_author, :comment_author, :comment_article_author, :vote_voteable_author_positive, :vote_voteable_author_negative, :vote_voter, :follower, :followed_article_author] | |
22 | + categories_labels = ['autor do artigo', 'autor do comentário', 'comentário recebido no meu artigo', 'voto positivo em meu conteúdo', 'voto negativo em meu conteúdo', 'voto realizado', 'seguir artigo', 'autor de artigo seguido'] | |
23 | 23 | quantities_labels = ['quantidade de votos realizados', 'quantidade de amigos', 'votos positivos recebidos', 'votos negativos recebidos', 'quantidade de artigos', 'quantidade de comentários realizados', 'quantidade de comentários recebidos', 'quatidade de vezes que eu segui', 'quantidade de vezes que meus artigos foram seguidos'] |
24 | 24 | |
25 | 25 | csv << ['identifier', 'name', 'score'] + categories_labels + quantities_labels | ... | ... |
test/unit/article_test.rb
... | ... | @@ -45,11 +45,11 @@ class ArticleTest < ActiveSupport::TestCase |
45 | 45 | end |
46 | 46 | |
47 | 47 | should 'add merit points to community article owner when an user like it' do |
48 | - create_point_rule_definition('vote_voteable_author') | |
48 | + create_point_rule_definition('vote_voteable_author_positive') | |
49 | 49 | community = fast_create(Community) |
50 | 50 | article = create(TextArticle, :name => 'Test', :profile => community, :author => person) |
51 | 51 | |
52 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
52 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first | |
53 | 53 | assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do |
54 | 54 | Vote.create!(:voter => create_user.person, :voteable => article, :vote => 1) |
55 | 55 | end |
... | ... | @@ -138,10 +138,10 @@ class ArticleTest < ActiveSupport::TestCase |
138 | 138 | |
139 | 139 | should 'add merit points to community article owner when an user like it on community' do |
140 | 140 | community = fast_create(Community) |
141 | - create_point_rule_definition('vote_voteable_author', community) | |
141 | + create_point_rule_definition('vote_voteable_author_positive', community) | |
142 | 142 | article = create(TextArticle, :name => 'Test', :profile => community, :author => person) |
143 | 143 | |
144 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
144 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first | |
145 | 145 | assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do |
146 | 146 | Vote.create!(:voter => create_user.person, :voteable => article, :vote => 1) |
147 | 147 | end |
... | ... | @@ -217,11 +217,11 @@ class ArticleTest < ActiveSupport::TestCase |
217 | 217 | end |
218 | 218 | |
219 | 219 | should 'not add merit points to article author when he likes his article' do |
220 | - create_point_rule_definition('vote_voteable_author') | |
220 | + create_point_rule_definition('vote_voteable_author_positive') | |
221 | 221 | community = fast_create(Community) |
222 | 222 | article = create(TextArticle, :name => 'Test', :profile => community, :author => person) |
223 | 223 | |
224 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
224 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first | |
225 | 225 | assert_no_difference 'article.author.points(:category => c.id.to_s)' do |
226 | 226 | Vote.create!(:voter => person, :voteable => article, :vote => 1) |
227 | 227 | end | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -66,53 +66,53 @@ class CommentTest < ActiveSupport::TestCase |
66 | 66 | end |
67 | 67 | |
68 | 68 | should 'add merit points to comment owner when an user like his comment' do |
69 | - create_point_rule_definition('vote_voteable_author') | |
69 | + create_point_rule_definition('vote_voteable_author_positive') | |
70 | 70 | comment = create(Comment, :source => article, :author_id => person.id) |
71 | 71 | |
72 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
72 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first | |
73 | 73 | assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do |
74 | 74 | Vote.create!(:voter => create_user.person, :voteable => comment, :vote => 1) |
75 | 75 | end |
76 | 76 | end |
77 | 77 | |
78 | 78 | should 'not add merit points to comment owner when he likes his comment' do |
79 | - create_point_rule_definition('vote_voteable_author') | |
79 | + create_point_rule_definition('vote_voteable_author_positive') | |
80 | 80 | comment = create(Comment, :source => article, :author_id => person.id) |
81 | 81 | |
82 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
82 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first | |
83 | 83 | assert_difference 'comment.author.points(:category => c.id.to_s)', 0 do |
84 | 84 | Vote.create!(:voter => person, :voteable => comment, :vote => 1) |
85 | 85 | end |
86 | 86 | end |
87 | 87 | |
88 | 88 | should 'subtract merit points to comment owner when an user unlike his comment' do |
89 | - create_point_rule_definition('vote_voteable_author') | |
89 | + create_point_rule_definition('vote_voteable_author_positive') | |
90 | 90 | comment = create(Comment, :source => article, :author_id => author.id) |
91 | 91 | Vote.create!(:voter => create_user.person, :voteable => comment, :vote => 1) |
92 | 92 | |
93 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
93 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first | |
94 | 94 | assert_difference 'comment.author.points', -1*c.weight do |
95 | 95 | Vote.where(:voteable_id => comment.id).destroy_all |
96 | 96 | end |
97 | 97 | end |
98 | 98 | |
99 | 99 | should 'subtract merit points from comment owner when an user dislike his comment' do |
100 | - create_point_rule_definition('vote_voteable_author') | |
100 | + create_point_rule_definition('vote_voteable_author_negative') | |
101 | 101 | comment = create(Comment, :source => article, :author_id => person.id) |
102 | 102 | |
103 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
104 | - assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do | |
103 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).first | |
104 | + assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do | |
105 | 105 | Vote.create!(:voter => create_user.person, :voteable => comment, :vote => -1) |
106 | 106 | end |
107 | 107 | end |
108 | 108 | |
109 | 109 | should 'add merit points from comment owner when an user remove a dislike in his comment' do |
110 | - create_point_rule_definition('vote_voteable_author') | |
110 | + create_point_rule_definition('vote_voteable_author_negative') | |
111 | 111 | comment = create(Comment, :source => article, :author_id => author.id) |
112 | 112 | Vote.create!(:voter => create_user.person, :voteable => comment, :vote => -1) |
113 | 113 | |
114 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
115 | - assert_difference 'comment.author.points', c.weight do | |
114 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).first | |
115 | + assert_difference 'comment.author.points', -1*c.weight do | |
116 | 116 | Vote.where(:voteable_id => comment.id).destroy_all |
117 | 117 | end |
118 | 118 | end |
... | ... | @@ -192,10 +192,10 @@ class CommentTest < ActiveSupport::TestCase |
192 | 192 | should 'add merit communty points to comment owner when an user like his comment inside a community' do |
193 | 193 | community = fast_create(Community) |
194 | 194 | article = create(TextArticle, profile_id: community.id, author_id: person.id) |
195 | - create_point_rule_definition('vote_voteable_author', community) | |
195 | + create_point_rule_definition('vote_voteable_author_positive', community) | |
196 | 196 | comment = create(Comment, :source => article, :author_id => person.id) |
197 | 197 | |
198 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first | |
198 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).where(profile_id: article.profile.id).first | |
199 | 199 | assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do |
200 | 200 | Vote.create!(:voter => create_user.person, :voteable => comment, :vote => 1) |
201 | 201 | end |
... | ... | @@ -204,11 +204,11 @@ class CommentTest < ActiveSupport::TestCase |
204 | 204 | should 'subtract merit community points to comment owner when an user unlike his comment inside a community' do |
205 | 205 | community = fast_create(Community) |
206 | 206 | article = create(TextArticle, profile_id: community.id, author_id: person.id) |
207 | - create_point_rule_definition('vote_voteable_author', community) | |
207 | + create_point_rule_definition('vote_voteable_author_positive', community) | |
208 | 208 | comment = create(Comment, :source => article, :author_id => author.id) |
209 | 209 | Vote.create!(:voter => person, :voteable => comment, :vote => 1) |
210 | 210 | |
211 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
211 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first | |
212 | 212 | assert_difference 'comment.author.points_by_profile(community.identifier)', -1*c.weight do |
213 | 213 | Vote.where(:voteable_id => comment.id).destroy_all |
214 | 214 | end |
... | ... | @@ -217,11 +217,11 @@ class CommentTest < ActiveSupport::TestCase |
217 | 217 | should 'subtract merit community points from comment owner when an user dislike his comment inside a community' do |
218 | 218 | community = fast_create(Community) |
219 | 219 | article = create(TextArticle, profile_id: community.id, author_id: person.id) |
220 | - create_point_rule_definition('vote_voteable_author', community) | |
220 | + create_point_rule_definition('vote_voteable_author_negative', community) | |
221 | 221 | comment = create(Comment, :source => article, :author_id => person.id) |
222 | 222 | |
223 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first | |
224 | - assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do | |
223 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).where(profile_id: article.profile.id).first | |
224 | + assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do | |
225 | 225 | Vote.create!(:voter => create_user.person, :voteable => comment, :vote => -1) |
226 | 226 | end |
227 | 227 | end |
... | ... | @@ -229,11 +229,11 @@ class CommentTest < ActiveSupport::TestCase |
229 | 229 | should 'add merit community points from comment owner when an user remove a dislike in his comment inside a community' do |
230 | 230 | community = fast_create(Community) |
231 | 231 | article = create(TextArticle, profile_id: community.id, author_id: person.id) |
232 | - create_point_rule_definition('vote_voteable_author', community) | |
232 | + create_point_rule_definition('vote_voteable_author_negative', community) | |
233 | 233 | comment = create(Comment, :source => article, :author_id => author.id) |
234 | 234 | Vote.create!(:voter => person, :voteable => comment, :vote => -1) |
235 | 235 | |
236 | - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first | |
236 | + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).first | |
237 | 237 | assert_difference 'comment.author.points_by_profile(community.identifier)', c.weight do |
238 | 238 | Vote.where(:voteable_id => comment.id).destroy_all |
239 | 239 | end | ... | ... |