Commit 53767f1dd0186dbb19e33854173ba68778b22aa7

Authored by Victor Costa
1 parent c9306125

Fix tests

test/functional/gamification_plugin_points_controller_test.rb
@@ -23,6 +23,7 @@ class GamificationPluginPointsControllerTest < ActionController::TestCase @@ -23,6 +23,7 @@ class GamificationPluginPointsControllerTest < ActionController::TestCase
23 end 23 end
24 24
25 should "should create gamification_plugin_point_categorizations for general rules" do 25 should "should create gamification_plugin_point_categorizations for general rules" do
  26 + GamificationPlugin::PointsCategorization.destroy_all
26 count = GamificationPlugin::PointsType.count 27 count = GamificationPlugin::PointsType.count
27 assert_difference('GamificationPlugin::PointsCategorization.count', count) do 28 assert_difference('GamificationPlugin::PointsCategorization.count', count) do
28 post :create, identifier: '' 29 post :create, identifier: ''
test/test_helper.rb
@@ -4,8 +4,9 @@ def create_point_rule_definition(rule_name, profile = nil, config = {}) @@ -4,8 +4,9 @@ def create_point_rule_definition(rule_name, profile = nil, config = {})
4 rule = load_point_rule(rule_name, config) 4 rule = load_point_rule(rule_name, config)
5 point_type = GamificationPlugin::PointsType.find_by_name rule_name 5 point_type = GamificationPlugin::PointsType.find_by_name rule_name
6 point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil? 6 point_type = GamificationPlugin::PointsType.create name: rule_name, description: rule['description'] if point_type.nil?
7 - GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, profile: profile, weight: rule[:default_weight] 7 + categorization = GamificationPlugin::PointsCategorization.create point_type_id: point_type.id, profile: profile, weight: rule[:default_weight]
8 GamificationPlugin.gamification_set_rules(@environment) 8 GamificationPlugin.gamification_set_rules(@environment)
  9 + categorization
9 end 10 end
10 11
11 def create_all_point_rules 12 def create_all_point_rules
test/unit/article_follower_test.rb
@@ -58,13 +58,14 @@ class ArticleFollowerTest < ActiveSupport::TestCase @@ -58,13 +58,14 @@ class ArticleFollowerTest < ActiveSupport::TestCase
58 should 'subtract merit points to article author when a user unfollow an article' do 58 should 'subtract merit points to article author when a user unfollow an article' do
59 create_point_rule_definition('follower') 59 create_point_rule_definition('follower')
60 article = create(TextArticle, :profile_id => community.id, :author => person) 60 article = create(TextArticle, :profile_id => community.id, :author => person)
61 - score_points = person.score_points.count  
62 - points = person.points  
63 - article.person_followers << person  
64 - assert_equal score_points + 1, person.score_points.count  
65 - ArticleFollower.last.destroy  
66 - assert_equal score_points + 2, person.score_points.count  
67 - assert_equal points, person.points 61 + assert_no_difference 'person.points' do
  62 + assert_difference 'person.score_points.count' do
  63 + article.person_followers << fast_create(Person)
  64 + end
  65 + assert_difference 'person.score_points.count' do
  66 + ArticleFollower.last.destroy
  67 + end
  68 + end
68 end 69 end
69 70
70 should 'subtract merit points to article when a user unfollow an article' do 71 should 'subtract merit points to article when a user unfollow an article' do
test/unit/article_test.rb
@@ -121,19 +121,18 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -121,19 +121,18 @@ class ArticleTest &lt; ActiveSupport::TestCase
121 # community related tests 121 # community related tests
122 should 'add merit community points to author when create a new article on community' do 122 should 'add merit community points to author when create a new article on community' do
123 community = fast_create(Community) 123 community = fast_create(Community)
124 - create_point_rule_definition('article_author', community) 124 + rule = create_point_rule_definition('article_author', community)
125 create(TextArticle, profile_id: community.id, author_id: person.id) 125 create(TextArticle, profile_id: community.id, author_id: person.id)
126 - assert_equal 1, person.score_points.count 126 + assert_equal rule.weight, person.points_by_profile(community.identifier)
127 assert person.score_points.first.action.present? 127 assert person.score_points.first.action.present?
128 end 128 end
129 129
130 should 'subtract merit points to author when destroy an article on community' do 130 should 'subtract merit points to author when destroy an article on community' do
131 community = fast_create(Community) 131 community = fast_create(Community)
132 - create_point_rule_definition('article_author', community) 132 + rule = create_point_rule_definition('article_author', community)
133 article = create(TextArticle, profile_id: community.id, author_id: person.id) 133 article = create(TextArticle, profile_id: community.id, author_id: person.id)
134 - assert_equal 1, person.score_points.count 134 + assert_equal rule.weight, person.points_by_profile(community.identifier)
135 article.destroy 135 article.destroy
136 - assert_equal 2, person.score_points.count  
137 assert_equal 0, person.points 136 assert_equal 0, person.points
138 end 137 end
139 138
@@ -162,7 +161,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -162,7 +161,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
162 161
163 should 'add merit points to community when create a new article on community' do 162 should 'add merit points to community when create a new article on community' do
164 community = fast_create(Community) 163 community = fast_create(Community)
165 - create_point_rule_definition('article_community', community) 164 + create_point_rule_definition('article_community')
166 assert_difference 'community.score_points.count' do 165 assert_difference 'community.score_points.count' do
167 create(TextArticle, :profile_id => community.id, :author => person) 166 create(TextArticle, :profile_id => community.id, :author => person)
168 end 167 end
test/unit/comment_test.rb
@@ -157,20 +157,19 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -157,20 +157,19 @@ class CommentTest &lt; ActiveSupport::TestCase
157 should 'add merit community points to author when create a new comment in a community' do 157 should 'add merit community points to author when create a new comment in a community' do
158 community = fast_create(Community) 158 community = fast_create(Community)
159 article = create(TextArticle, profile_id: community.id, author_id: person.id) 159 article = create(TextArticle, profile_id: community.id, author_id: person.id)
160 - create_point_rule_definition('comment_author', article.profile) 160 + rule = create_point_rule_definition('comment_author', article.profile)
161 create(Comment, :source => article, :author_id => person.id) 161 create(Comment, :source => article, :author_id => person.id)
162 - assert_equal 1, person.score_points.count 162 + assert_equal rule.weight, person.points_by_profile(article.profile.identifier)
163 end 163 end
164 164
165 should 'subtract merit community points from author when destroy a community comment' do 165 should 'subtract merit community points from author when destroy a community comment' do
166 community = fast_create(Community) 166 community = fast_create(Community)
167 - article = create(TextArticle, profile_id: community.id, author_id: person.id)  
168 - create_point_rule_definition('comment_author', article.profile) 167 + article = create(TextArticle, profile_id: community.id, author_id: fast_create(Person).id)
  168 + rule = create_point_rule_definition('comment_author', article.profile)
169 comment = create(Comment, :source => article, :author_id => person.id) 169 comment = create(Comment, :source => article, :author_id => person.id)
170 - assert_equal 1, person.score_points.count 170 + assert_equal rule.weight, person.points_by_profile(article.profile.identifier)
171 comment.destroy 171 comment.destroy
172 - assert_equal 2, person.score_points.count  
173 - assert_equal 0, person.points 172 + assert_equal 0, person.points_by_profile(article.profile.identifier)
174 end 173 end
175 174
176 should 'add merit communty points to comment owner when an user like his comment inside a community' do 175 should 'add merit communty points to comment owner when an user like his comment inside a community' do
@@ -193,7 +192,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -193,7 +192,7 @@ class CommentTest &lt; ActiveSupport::TestCase
193 Vote.create!(:voter => person, :voteable => comment, :vote => 1) 192 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
194 193
195 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 194 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
196 - assert_difference 'comment.author.points', -1*c.weight do 195 + assert_difference 'comment.author.points_by_profile(community.identifier)', -1*c.weight do
197 Vote.where(:voteable_id => comment.id).destroy_all 196 Vote.where(:voteable_id => comment.id).destroy_all
198 end 197 end
199 end 198 end
@@ -218,7 +217,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -218,7 +217,7 @@ class CommentTest &lt; ActiveSupport::TestCase
218 Vote.create!(:voter => person, :voteable => comment, :vote => -1) 217 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
219 218
220 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 219 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
221 - assert_difference 'comment.author.points', c.weight do 220 + assert_difference 'comment.author.points_by_profile(community.identifier)', c.weight do
222 Vote.where(:voteable_id => comment.id).destroy_all 221 Vote.where(:voteable_id => comment.id).destroy_all
223 end 222 end
224 end 223 end
@@ -226,8 +225,8 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -226,8 +225,8 @@ class CommentTest &lt; ActiveSupport::TestCase
226 should 'add merit community points to article author when create a new comment inside a community' do 225 should 'add merit community points to article author when create a new comment inside a community' do
227 community = fast_create(Community) 226 community = fast_create(Community)
228 article = create(TextArticle, profile_id: community.id, author_id: author.id) 227 article = create(TextArticle, profile_id: community.id, author_id: author.id)
229 - create_point_rule_definition('comment_article_author', community)  
230 - assert_difference 'author.score_points.count' do 228 + rule = create_point_rule_definition('comment_article_author', community)
  229 + assert_difference 'author.points_by_profile(community.identifier)', rule.weight do
231 create(Comment, :source => article, :author_id => author.id) 230 create(Comment, :source => article, :author_id => author.id)
232 end 231 end
233 end 232 end