Commit b10edbe8045f7d375611db2f2c86b2930bd3fcda

Authored by Hugo Melo
1 parent 51c91662

Add more article tests

Showing 1 changed file with 52 additions and 92 deletions   Show diff stats
test/unit/article_test.rb
@@ -137,97 +137,57 @@ class ArticleTest < ActiveSupport::TestCase @@ -137,97 +137,57 @@ class ArticleTest < ActiveSupport::TestCase
137 assert_equal 0, person.points 137 assert_equal 0, person.points
138 end 138 end
139 139
140 - #should 'add merit badge to author when create 5 new articles on community' do  
141 - #GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)  
142 - #GamificationPlugin.gamification_set_rules(environment)  
143 -  
144 - #5.times { create(TextArticle, :profile_id => person.id, :author => person) }  
145 - #assert_equal 'article_author', person.badges.first.name  
146 - #assert_equal 1, person.badges.first.level  
147 - #end  
148 -  
149 - #should 'add merit badge level 2 to author when create 10 new articles on community' do  
150 - #GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)  
151 - #GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10})  
152 - #GamificationPlugin.gamification_set_rules(environment)  
153 -  
154 - #10.times { create(TextArticle, :profile_id => person.id, :author => person) }  
155 - #assert_equal ['article_author'], person.badges.map(&:name).uniq  
156 - #assert_equal [1, 2], person.badges.map(&:level)  
157 - #end  
158 -  
159 - #should 'add merit points to community article owner when an user like it on community' do  
160 - #create_point_rule_definition('vote_voteable_author')  
161 - #community = fast_create(Community)  
162 - #article = create(TextArticle, :name => 'Test', :profile => community, :author => person)  
163 -  
164 - #c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first  
165 - #assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do  
166 - #Vote.create!(:voter => person, :voteable => article, :vote => 1)  
167 - #end  
168 - #end  
169 -  
170 - #should 'add merit points to article when an user like it on community' do  
171 - #create_point_rule_definition('vote_voteable')  
172 - #article = create(TextArticle, :name => 'Test', :profile => person, :author => person)  
173 - #article = article.reload  
174 -  
175 - #c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).first  
176 - #assert_difference 'article.points(:category => c.id.to_s)', c.weight do  
177 - #Vote.create!(:voter => person, :voteable => article, :vote => 1)  
178 - #end  
179 - #end  
180 -  
181 - #should 'add merit points to community when create a new article on community' do  
182 - #create_point_rule_definition('article_community')  
183 - #community = fast_create(Community)  
184 - #assert_difference 'community.score_points.count' do  
185 - #create(TextArticle, :profile_id => community.id, :author => person)  
186 - #end  
187 - #end  
188 -  
189 - #should 'add merit points to voter when he likes an article on community' do  
190 - #create_point_rule_definition('vote_voter')  
191 - #article = create(TextArticle, :name => 'Test', :profile => person, :author => person)  
192 -  
193 - #c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first  
194 - #assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do  
195 - #Vote.create!(:voter => person, :voteable => article, :vote => 1)  
196 - #end  
197 - #end  
198 -  
199 - #should 'add merit points to voter when he dislikes an article on community' do  
200 - #create_point_rule_definition('vote_voter')  
201 - #article = create(TextArticle, :name => 'Test', :profile => person, :author => person)  
202 -  
203 - #c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first  
204 - #assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do  
205 - #Vote.create!(:voter => person, :voteable => article, :vote => -1)  
206 - #end  
207 - #end  
208 -  
209 - #should 'add badge to author when users like his article on community' do  
210 - #GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received')  
211 - #GamificationPlugin.gamification_set_rules(environment)  
212 -  
213 - #article = create(TextArticle, :name => 'Test', :profile => person, :author => person)  
214 - #4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) }  
215 - #Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)  
216 - #assert_equal [], person.badges  
217 - #Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)  
218 - #assert_equal 'positive_votes_received', person.reload.badges.first.name  
219 - #end  
220 -  
221 - #should 'add badge to author when users dislike his article on community' do  
222 - #GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received')  
223 - #GamificationPlugin.gamification_set_rules(environment)  
224 -  
225 - #article = create(TextArticle, :name => 'Test', :profile => person, :author => person)  
226 - #4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) }  
227 - #Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)  
228 - #assert_equal [], person.badges  
229 - #Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)  
230 - #assert_equal 'negative_votes_received', person.reload.badges.first.name  
231 - #end 140 + should 'add merit points to community article owner when an user like it on community' do
  141 + community = fast_create(Community)
  142 + create_point_rule_definition('vote_voteable_author', community)
  143 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  144 +
  145 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
  146 + assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
  147 + Vote.create!(:voter => person, :voteable => article, :vote => 1)
  148 + end
  149 + end
  150 +
  151 + should 'add merit points to article when an user like it on community' do
  152 + community = fast_create(Community)
  153 + create_point_rule_definition('vote_voteable', community)
  154 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  155 + article = article.reload
  156 +
  157 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).first
  158 + assert_difference 'article.points(:category => c.id.to_s)', c.weight do
  159 + Vote.create!(:voter => person, :voteable => article, :vote => 1)
  160 + end
  161 + end
  162 +
  163 + should 'add merit points to community when create a new article on community' do
  164 + community = fast_create(Community)
  165 + create_point_rule_definition('article_community', community)
  166 + assert_difference 'community.score_points.count' do
  167 + create(TextArticle, :profile_id => community.id, :author => person)
  168 + end
  169 + end
  170 +
  171 + should 'add merit points to voter when he likes an article on community' do
  172 + community = fast_create(Community)
  173 + create_point_rule_definition('vote_voter', community)
  174 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  175 +
  176 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
  177 + assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
  178 + Vote.create!(:voter => person, :voteable => article, :vote => 1)
  179 + end
  180 + end
  181 +
  182 + should 'add merit points to voter when he dislikes an article on community' do
  183 + community = fast_create(Community)
  184 + create_point_rule_definition('vote_voter', community)
  185 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  186 +
  187 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
  188 + assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
  189 + Vote.create!(:voter => person, :voteable => article, :vote => -1)
  190 + end
  191 + end
232 192
233 end 193 end