diff --git a/lib/merit/point_rules.rb b/lib/merit/point_rules.rb index c5371a6..d0490da 100644 --- a/lib/merit/point_rules.rb +++ b/lib/merit/point_rules.rb @@ -66,16 +66,27 @@ module Merit condition: lambda {|article, profile| article.profile.present? and article.profile.community? }, target_url: lambda {|article| article.url}, }, - vote_voteable_author: { + vote_voteable_author_positive: { action: 'vote#create', undo_action: 'vote#destroy', to: lambda {|vote| vote.voteable.author}, - value: lambda {|vote| vote.vote}, - description: _('Author of a voted content'), + value: lambda {|vote| 1}, + description: _('Author of a content that receive a positive vote'), default_weight: 20, target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, target_url: lambda {|vote| vote.voteable.url}, - condition: lambda {|vote, profile| vote.voter != vote.voteable.author } + condition: lambda {|vote, profile| vote.vote>0 && vote.voter != vote.voteable.author } + }, + vote_voteable_author_negative: { + action: 'vote#create', + undo_action: 'vote#destroy', + to: lambda {|vote| vote.voteable.author}, + value: lambda {|vote| 1}, + description: _('Author of a content that receive a negative vote'), + default_weight: -20, + target_profile: lambda {|vote| vote.voteable.present? ? vote.voteable.profile : nil }, + target_url: lambda {|vote| vote.voteable.url}, + condition: lambda {|vote, profile| vote.vote<0 && vote.voter != vote.voteable.author } }, vote_voteable: { action: 'vote#create', diff --git a/script/export_ranking.rb b/script/export_ranking.rb index 836156a..4569c43 100644 --- a/script/export_ranking.rb +++ b/script/export_ranking.rb @@ -18,8 +18,8 @@ profile_ids.each do |profile_id| puts "Creating spreadsheet for #{profile_name}" CSV.open( "ranking_gamification_for_#{profile_name}.csv", 'w' ) do |csv| - categories = [:article_author, :comment_author, :comment_article_author, :vote_voteable_author, :vote_voter, :follower, :followed_article_author] - 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'] + categories = [:article_author, :comment_author, :comment_article_author, :vote_voteable_author_positive, :vote_voteable_author_negative, :vote_voter, :follower, :followed_article_author] + 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'] 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'] csv << ['identifier', 'name', 'score'] + categories_labels + quantities_labels diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index c21d1d9..70a62b3 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -45,11 +45,11 @@ class ArticleTest < ActiveSupport::TestCase end should 'add merit points to community article owner when an user like it' do - create_point_rule_definition('vote_voteable_author') + create_point_rule_definition('vote_voteable_author_positive') community = fast_create(Community) article = create(TextArticle, :name => 'Test', :profile => community, :author => person) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do Vote.create!(:voter => create_user.person, :voteable => article, :vote => 1) end @@ -138,10 +138,10 @@ class ArticleTest < ActiveSupport::TestCase should 'add merit points to community article owner when an user like it on community' do community = fast_create(Community) - create_point_rule_definition('vote_voteable_author', community) + create_point_rule_definition('vote_voteable_author_positive', community) article = create(TextArticle, :name => 'Test', :profile => community, :author => person) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do Vote.create!(:voter => create_user.person, :voteable => article, :vote => 1) end @@ -217,11 +217,11 @@ class ArticleTest < ActiveSupport::TestCase end should 'not add merit points to article author when he likes his article' do - create_point_rule_definition('vote_voteable_author') + create_point_rule_definition('vote_voteable_author_positive') community = fast_create(Community) article = create(TextArticle, :name => 'Test', :profile => community, :author => person) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first assert_no_difference 'article.author.points(:category => c.id.to_s)' do Vote.create!(:voter => person, :voteable => article, :vote => 1) end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index cde76bf..ea79f39 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -66,53 +66,53 @@ class CommentTest < ActiveSupport::TestCase end should 'add merit points to comment owner when an user like his comment' do - create_point_rule_definition('vote_voteable_author') + create_point_rule_definition('vote_voteable_author_positive') comment = create(Comment, :source => article, :author_id => person.id) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do Vote.create!(:voter => create_user.person, :voteable => comment, :vote => 1) end end should 'not add merit points to comment owner when he likes his comment' do - create_point_rule_definition('vote_voteable_author') + create_point_rule_definition('vote_voteable_author_positive') comment = create(Comment, :source => article, :author_id => person.id) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first assert_difference 'comment.author.points(:category => c.id.to_s)', 0 do Vote.create!(:voter => person, :voteable => comment, :vote => 1) end end should 'subtract merit points to comment owner when an user unlike his comment' do - create_point_rule_definition('vote_voteable_author') + create_point_rule_definition('vote_voteable_author_positive') comment = create(Comment, :source => article, :author_id => author.id) Vote.create!(:voter => create_user.person, :voteable => comment, :vote => 1) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first assert_difference 'comment.author.points', -1*c.weight do Vote.where(:voteable_id => comment.id).destroy_all end end should 'subtract merit points from comment owner when an user dislike his comment' do - create_point_rule_definition('vote_voteable_author') + create_point_rule_definition('vote_voteable_author_negative') comment = create(Comment, :source => article, :author_id => person.id) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first - assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).first + assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do Vote.create!(:voter => create_user.person, :voteable => comment, :vote => -1) end end should 'add merit points from comment owner when an user remove a dislike in his comment' do - create_point_rule_definition('vote_voteable_author') + create_point_rule_definition('vote_voteable_author_negative') comment = create(Comment, :source => article, :author_id => author.id) Vote.create!(:voter => create_user.person, :voteable => comment, :vote => -1) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first - assert_difference 'comment.author.points', c.weight do + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).first + assert_difference 'comment.author.points', -1*c.weight do Vote.where(:voteable_id => comment.id).destroy_all end end @@ -192,10 +192,10 @@ class CommentTest < ActiveSupport::TestCase should 'add merit communty points to comment owner when an user like his comment inside a community' do community = fast_create(Community) article = create(TextArticle, profile_id: community.id, author_id: person.id) - create_point_rule_definition('vote_voteable_author', community) + create_point_rule_definition('vote_voteable_author_positive', community) comment = create(Comment, :source => article, :author_id => person.id) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).where(profile_id: article.profile.id).first assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do Vote.create!(:voter => create_user.person, :voteable => comment, :vote => 1) end @@ -204,11 +204,11 @@ class CommentTest < ActiveSupport::TestCase should 'subtract merit community points to comment owner when an user unlike his comment inside a community' do community = fast_create(Community) article = create(TextArticle, profile_id: community.id, author_id: person.id) - create_point_rule_definition('vote_voteable_author', community) + create_point_rule_definition('vote_voteable_author_positive', community) comment = create(Comment, :source => article, :author_id => author.id) Vote.create!(:voter => person, :voteable => comment, :vote => 1) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_positive).first assert_difference 'comment.author.points_by_profile(community.identifier)', -1*c.weight do Vote.where(:voteable_id => comment.id).destroy_all end @@ -217,11 +217,11 @@ class CommentTest < ActiveSupport::TestCase should 'subtract merit community points from comment owner when an user dislike his comment inside a community' do community = fast_create(Community) article = create(TextArticle, profile_id: community.id, author_id: person.id) - create_point_rule_definition('vote_voteable_author', community) + create_point_rule_definition('vote_voteable_author_negative', community) comment = create(Comment, :source => article, :author_id => person.id) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first - assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).where(profile_id: article.profile.id).first + assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do Vote.create!(:voter => create_user.person, :voteable => comment, :vote => -1) end end @@ -229,11 +229,11 @@ class CommentTest < ActiveSupport::TestCase should 'add merit community points from comment owner when an user remove a dislike in his comment inside a community' do community = fast_create(Community) article = create(TextArticle, profile_id: community.id, author_id: person.id) - create_point_rule_definition('vote_voteable_author', community) + create_point_rule_definition('vote_voteable_author_negative', community) comment = create(Comment, :source => article, :author_id => author.id) Vote.create!(:voter => person, :voteable => comment, :vote => -1) - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author_negative).first assert_difference 'comment.author.points_by_profile(community.identifier)', c.weight do Vote.where(:voteable_id => comment.id).destroy_all end -- libgit2 0.21.2