From 53767f1dd0186dbb19e33854173ba68778b22aa7 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Wed, 28 Oct 2015 15:58:59 -0300 Subject: [PATCH] Fix tests --- test/functional/gamification_plugin_points_controller_test.rb | 1 + test/test_helper.rb | 3 ++- test/unit/article_follower_test.rb | 15 ++++++++------- test/unit/article_test.rb | 11 +++++------ test/unit/comment_test.rb | 21 ++++++++++----------- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/test/functional/gamification_plugin_points_controller_test.rb b/test/functional/gamification_plugin_points_controller_test.rb index 391b6b1..599d791 100644 --- a/test/functional/gamification_plugin_points_controller_test.rb +++ b/test/functional/gamification_plugin_points_controller_test.rb @@ -23,6 +23,7 @@ class GamificationPluginPointsControllerTest < ActionController::TestCase end should "should create gamification_plugin_point_categorizations for general rules" do + GamificationPlugin::PointsCategorization.destroy_all count = GamificationPlugin::PointsType.count assert_difference('GamificationPlugin::PointsCategorization.count', count) do post :create, identifier: '' diff --git a/test/test_helper.rb b/test/test_helper.rb index a1d68f8..f728fb7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,8 +4,9 @@ def create_point_rule_definition(rule_name, profile = nil, config = {}) rule = load_point_rule(rule_name, config) point_type = GamificationPlugin::PointsType.find_by_name rule_name point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? - GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, profile: profile, weight: rule[:default_weight] + categorization = GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, profile: profile, weight: rule[:default_weight] GamificationPlugin.gamification_set_rules(@environment) + categorization end def create_all_point_rules diff --git a/test/unit/article_follower_test.rb b/test/unit/article_follower_test.rb index 933a81d..d0fc416 100644 --- a/test/unit/article_follower_test.rb +++ b/test/unit/article_follower_test.rb @@ -58,13 +58,14 @@ class ArticleFollowerTest < ActiveSupport::TestCase should 'subtract merit points to article author when a user unfollow an article' do create_point_rule_definition('follower') article = create(TextArticle, :profile_id => community.id, :author => person) - score_points = person.score_points.count - points = person.points - article.person_followers << person - assert_equal score_points + 1, person.score_points.count - ArticleFollower.last.destroy - assert_equal score_points + 2, person.score_points.count - assert_equal points, person.points + assert_no_difference 'person.points' do + assert_difference 'person.score_points.count' do + article.person_followers << fast_create(Person) + end + assert_difference 'person.score_points.count' do + ArticleFollower.last.destroy + end + end end should 'subtract merit points to article when a user unfollow an article' do diff --git a/test/unit/article_test.rb b/test/unit/article_test.rb index df905ac..8faffc9 100644 --- a/test/unit/article_test.rb +++ b/test/unit/article_test.rb @@ -121,19 +121,18 @@ class ArticleTest < ActiveSupport::TestCase # community related tests should 'add merit community points to author when create a new article on community' do community = fast_create(Community) - create_point_rule_definition('article_author', community) + rule = create_point_rule_definition('article_author', community) create(TextArticle, profile_id: community.id, author_id: person.id) - assert_equal 1, person.score_points.count + assert_equal rule.weight, person.points_by_profile(community.identifier) assert person.score_points.first.action.present? end should 'subtract merit points to author when destroy an article on community' do community = fast_create(Community) - create_point_rule_definition('article_author', community) + rule = create_point_rule_definition('article_author', community) article = create(TextArticle, profile_id: community.id, author_id: person.id) - assert_equal 1, person.score_points.count + assert_equal rule.weight, person.points_by_profile(community.identifier) article.destroy - assert_equal 2, person.score_points.count assert_equal 0, person.points end @@ -162,7 +161,7 @@ class ArticleTest < ActiveSupport::TestCase should 'add merit points to community when create a new article on community' do community = fast_create(Community) - create_point_rule_definition('article_community', community) + create_point_rule_definition('article_community') assert_difference 'community.score_points.count' do create(TextArticle, :profile_id => community.id, :author => person) end diff --git a/test/unit/comment_test.rb b/test/unit/comment_test.rb index 0dc6eb3..169d55f 100644 --- a/test/unit/comment_test.rb +++ b/test/unit/comment_test.rb @@ -157,20 +157,19 @@ class CommentTest < ActiveSupport::TestCase should 'add merit community points to author when create a new comment in a community' do community = fast_create(Community) article = create(TextArticle, profile_id: community.id, author_id: person.id) - create_point_rule_definition('comment_author', article.profile) + rule = create_point_rule_definition('comment_author', article.profile) create(Comment, :source => article, :author_id => person.id) - assert_equal 1, person.score_points.count + assert_equal rule.weight, person.points_by_profile(article.profile.identifier) end should 'subtract merit community points from author when destroy a community comment' do community = fast_create(Community) - article = create(TextArticle, profile_id: community.id, author_id: person.id) - create_point_rule_definition('comment_author', article.profile) + article = create(TextArticle, profile_id: community.id, author_id: fast_create(Person).id) + rule = create_point_rule_definition('comment_author', article.profile) comment = create(Comment, :source => article, :author_id => person.id) - assert_equal 1, person.score_points.count + assert_equal rule.weight, person.points_by_profile(article.profile.identifier) comment.destroy - assert_equal 2, person.score_points.count - assert_equal 0, person.points + assert_equal 0, person.points_by_profile(article.profile.identifier) end should 'add merit communty points to comment owner when an user like his comment inside a community' do @@ -193,7 +192,7 @@ class CommentTest < ActiveSupport::TestCase Vote.create!(:voter => person, :voteable => comment, :vote => 1) c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first - assert_difference 'comment.author.points', -1*c.weight do + assert_difference 'comment.author.points_by_profile(community.identifier)', -1*c.weight do Vote.where(:voteable_id => comment.id).destroy_all end end @@ -218,7 +217,7 @@ class CommentTest < ActiveSupport::TestCase Vote.create!(:voter => person, :voteable => comment, :vote => -1) c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first - assert_difference 'comment.author.points', c.weight do + assert_difference 'comment.author.points_by_profile(community.identifier)', c.weight do Vote.where(:voteable_id => comment.id).destroy_all end end @@ -226,8 +225,8 @@ class CommentTest < ActiveSupport::TestCase should 'add merit community points to article author when create a new comment inside a community' do community = fast_create(Community) article = create(TextArticle, profile_id: community.id, author_id: author.id) - create_point_rule_definition('comment_article_author', community) - assert_difference 'author.score_points.count' do + rule = create_point_rule_definition('comment_article_author', community) + assert_difference 'author.points_by_profile(community.identifier)', rule.weight do create(Comment, :source => article, :author_id => author.id) end end -- libgit2 0.21.2