point_rules_test.rb
1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_relative "../test_helper"
class PointRulesTest < ActiveSupport::TestCase
def setup
@environment = Environment.default
GamificationPlugin.gamification_set_rules(@environment)
@point_rules = Merit::PointRules.new(@environment)
end
attr_accessor :environment, :point_rules
should 'not define rules when environment is nil' do
point_rules = Merit::PointRules.new
assert point_rules.defined_rules.blank?
end
should 'define rules when environment is present' do
assert point_rules.defined_rules.present?
end
should 'return target url for a point related to article creation' do
person = create_user('testuser').person
create_point_rule_definition('article_author')
article = create(TextArticle, :profile_id => person.id, :author => person)
process_delayed_job_queue
url = Merit::PointRules.target_url(person.score_points.last)
assert_equal article.url, url
end
should 'return target url for a point related to comment creation' do
person = create_user('testuser').person
create_point_rule_definition('comment_author')
article = create(Article, :profile_id => person.id, :author => person)
comment = create(Comment, :source_id => article.id, :author => person)
process_delayed_job_queue
url = Merit::PointRules.target_url(person.score_points.last)
assert_equal comment.url, url
end
end