Commit 53767f1dd0186dbb19e33854173ba68778b22aa7
1 parent
c9306125
Exists in
master
and in
1 other branch
Fix tests
Showing
5 changed files
with
26 additions
and
25 deletions
Show diff stats
test/functional/gamification_plugin_points_controller_test.rb
... | ... | @@ -23,6 +23,7 @@ class GamificationPluginPointsControllerTest < ActionController::TestCase |
23 | 23 | end |
24 | 24 | |
25 | 25 | should "should create gamification_plugin_point_categorizations for general rules" do |
26 | + GamificationPlugin::PointsCategorization.destroy_all | |
26 | 27 | count = GamificationPlugin::PointsType.count |
27 | 28 | assert_difference('GamificationPlugin::PointsCategorization.count', count) do |
28 | 29 | post :create, identifier: '' | ... | ... |
test/test_helper.rb
... | ... | @@ -4,8 +4,9 @@ def create_point_rule_definition(rule_name, profile = nil, config = {}) |
4 | 4 | rule = load_point_rule(rule_name, config) |
5 | 5 | point_type = GamificationPlugin::PointsType.find_by_name rule_name |
6 | 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 | 8 | GamificationPlugin.gamification_set_rules(@environment) |
9 | + categorization | |
9 | 10 | end |
10 | 11 | |
11 | 12 | def create_all_point_rules | ... | ... |
test/unit/article_follower_test.rb
... | ... | @@ -58,13 +58,14 @@ class ArticleFollowerTest < ActiveSupport::TestCase |
58 | 58 | should 'subtract merit points to article author when a user unfollow an article' do |
59 | 59 | create_point_rule_definition('follower') |
60 | 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 | 69 | end |
69 | 70 | |
70 | 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 < ActiveSupport::TestCase |
121 | 121 | # community related tests |
122 | 122 | should 'add merit community points to author when create a new article on community' do |
123 | 123 | community = fast_create(Community) |
124 | - create_point_rule_definition('article_author', community) | |
124 | + rule = create_point_rule_definition('article_author', community) | |
125 | 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 | 127 | assert person.score_points.first.action.present? |
128 | 128 | end |
129 | 129 | |
130 | 130 | should 'subtract merit points to author when destroy an article on community' do |
131 | 131 | community = fast_create(Community) |
132 | - create_point_rule_definition('article_author', community) | |
132 | + rule = create_point_rule_definition('article_author', community) | |
133 | 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 | 135 | article.destroy |
136 | - assert_equal 2, person.score_points.count | |
137 | 136 | assert_equal 0, person.points |
138 | 137 | end |
139 | 138 | |
... | ... | @@ -162,7 +161,7 @@ class ArticleTest < ActiveSupport::TestCase |
162 | 161 | |
163 | 162 | should 'add merit points to community when create a new article on community' do |
164 | 163 | community = fast_create(Community) |
165 | - create_point_rule_definition('article_community', community) | |
164 | + create_point_rule_definition('article_community') | |
166 | 165 | assert_difference 'community.score_points.count' do |
167 | 166 | create(TextArticle, :profile_id => community.id, :author => person) |
168 | 167 | end | ... | ... |
test/unit/comment_test.rb
... | ... | @@ -157,20 +157,19 @@ class CommentTest < ActiveSupport::TestCase |
157 | 157 | should 'add merit community points to author when create a new comment in a community' do |
158 | 158 | community = fast_create(Community) |
159 | 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 | 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 | 163 | end |
164 | 164 | |
165 | 165 | should 'subtract merit community points from author when destroy a community comment' do |
166 | 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 | 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 | 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 | 173 | end |
175 | 174 | |
176 | 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 < ActiveSupport::TestCase |
193 | 192 | Vote.create!(:voter => person, :voteable => comment, :vote => 1) |
194 | 193 | |
195 | 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 | 196 | Vote.where(:voteable_id => comment.id).destroy_all |
198 | 197 | end |
199 | 198 | end |
... | ... | @@ -218,7 +217,7 @@ class CommentTest < ActiveSupport::TestCase |
218 | 217 | Vote.create!(:voter => person, :voteable => comment, :vote => -1) |
219 | 218 | |
220 | 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 | 221 | Vote.where(:voteable_id => comment.id).destroy_all |
223 | 222 | end |
224 | 223 | end |
... | ... | @@ -226,8 +225,8 @@ class CommentTest < ActiveSupport::TestCase |
226 | 225 | should 'add merit community points to article author when create a new comment inside a community' do |
227 | 226 | community = fast_create(Community) |
228 | 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 | 230 | create(Comment, :source => article, :author_id => author.id) |
232 | 231 | end |
233 | 232 | end | ... | ... |