Commit 27f9186b0d4285c9557ae64c279259bf44469afc

Authored by Leandro Santos
1 parent 7e8e2832

refatoring unit tests

test/test_helper.rb
1 1 require_relative "../../../test/test_helper"
2 2  
3   -def create_merit_categorization
4   - c = fast_create(Community)
5   - Merit::PointRules::AVAILABLE_RULES.each do |name, setting|
6   - point_type = GamificationPlugin::PointsType.find_by_name name
7   - point_type = GamificationPlugin::PointsType.create name: name, description: setting['description'] if point_type.nil?
8   - profile = setting.fetch(:profile_action, true) ? c : nil
9   - GamificationPlugin::PointsCategorization.create! point_type_id: point_type.id, profile: profile, weight: setting[:default_weight]
  3 +def create_point_rule_definition(rule_name, profile = nil, config = {})
  4 + rule = load_point_rule(rule_name, config)
  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?
  7 + GamificationPlugin::PointsCategorization.create! point_type_id: point_type.id, profile: profile, weight: rule[:default_weight]
  8 + GamificationPlugin.gamification_set_rules(@environment)
  9 +end
  10 +
  11 +def create_all_point_rules
  12 + Merit::PointRules::AVAILABLE_RULES.map do |rule, config|
  13 + create_point_rule_definition(rule)
  14 + end
  15 +end
  16 +
  17 +def load_point_rule(rule_name, config)
  18 + rule_config = Merit::PointRules::AVAILABLE_RULES[rule_name.to_sym]
  19 + raise "Point rule '#{rule_name}' is not available" if rule_config.nil?
  20 + rule_config.merge!(config)
  21 + rule_config
  22 +end
  23 +
  24 +#person_points_debug(person)
  25 +def person_points_debug(person)
  26 + person.score_points.map do |sp|
  27 + puts 'Ponto:'
  28 + puts sp.inspect
  29 + puts sp.action.inspect
  30 + puts sp.score.inspect
  31 + puts GamificationPlugin::PointsCategorization.find(sp.score.category).inspect
  32 + puts GamificationPlugin::PointsCategorization.find(sp.score.category).point_type.inspect
10 33 end
11   - c
12   -end#
  34 +end
... ...
test/unit/api_test.rb
... ... @@ -7,7 +7,6 @@ class APITest < ActiveSupport::TestCase
7 7 login_api
8 8 environment = Environment.default
9 9 environment.enable_plugin(GamificationPlugin)
10   - @community = create_merit_categorization
11 10 GamificationPlugin.gamification_set_rules(@environment)
12 11 end
13 12  
... ...
test/unit/article_follower.rb
... ... @@ -5,21 +5,47 @@ class ArticleTest < ActiveSupport::TestCase
5 5 def setup
6 6 @person = create_user('testuser').person
7 7 @environment = Environment.default
8   - @community = create_merit_categorization
9   - GamificationPlugin.gamification_set_rules(@environment)
  8 + @community = fast_create(Community)
10 9 end
11 10  
12 11 attr_accessor :person, :environment, :community
13 12  
14 13 should 'add merit points to follower when it follows an article' do
15   - article = create(TextArticle, :profile_id => community.id, :author => person)
  14 + create_point_rule_definition('follower')
  15 + article = create(TextArticle, :profile_id => community.id, :author => create_user('someuser').person)
16 16 amount = person.score_points.count
17 17 article.person_followers << person
18   -puts person.score_points.first.action.inspect
  18 + article.reload
19 19 assert_equal amount + 1, person.score_points.count
20   - assert person.score_points.first.action.present?
  20 + last_point = person.score_points.last
  21 + assert_equal article.article_followers.last.id, last_point.action.target_id
21 22 end
22 23  
  24 + should "add merit points for article's author followed by an user" do
  25 + create_point_rule_definition('followed_article_author')
  26 + author = create_user('someuser').person
  27 + article = create(TextArticle, :profile_id => community.id, :author => author)
  28 + amount = author.score_points.count
  29 + article.person_followers << person
  30 + assert_equal amount + 1, author.score_points.count
  31 + last_point = author.score_points.last
  32 + assert_equal article.article_followers.last.id, last_point.action.target_id
  33 + end
  34 +
  35 + should "add merit points for article's author and person who follow an article at the same time" do
  36 + create_point_rule_definition('follower')
  37 + create_point_rule_definition('followed_article_author')
  38 + author = create_user('someuser').person
  39 + article = create(TextArticle, :profile_id => community.id, :author => author)
  40 + amount = author.score_points.count
  41 + article.person_followers << person
  42 + assert_equal amount + 1, author.score_points.count
  43 + last_point = author.score_points.last
  44 + assert_equal article.article_followers.last.id, last_point.action.target_id
  45 + assert_equal amount + 1, person.score_points.count
  46 + last_point = person.score_points.last
  47 + assert_equal article.article_followers.last.id, last_point.action.target_id
  48 + end
23 49 # should 'subtract merit points to author when destroy an article' do
24 50 # article = create(TextArticle, :profile_id => @community.id, :author => person)
25 51 # assert_equal 1, person.score_points.count
... ...
test/unit/article_test.rb
... ... @@ -5,20 +5,20 @@ class ArticleTest &lt; ActiveSupport::TestCase
5 5 def setup
6 6 @person = create_user('testuser').person
7 7 @environment = Environment.default
8   - @community = create_merit_categorization
9   - GamificationPlugin.gamification_set_rules(@environment)
10 8 end
11 9  
12   - attr_accessor :person, :environment, :community
  10 + attr_accessor :person, :environment
13 11  
14 12 should 'add merit points to author when create a new article' do
15   - create(TextArticle, :profile_id => community.id, :author => person)
  13 + create_point_rule_definition('article_author')
  14 + create(TextArticle, :profile_id => person.id, :author => person)
16 15 assert_equal 1, person.score_points.count
17 16 assert person.score_points.first.action.present?
18 17 end
19 18  
20 19 should 'subtract merit points to author when destroy an article' do
21   - article = create(TextArticle, :profile_id => @community.id, :author => person)
  20 + create_point_rule_definition('article_author')
  21 + article = create(TextArticle, :profile_id => person.id, :author => person)
22 22 assert_equal 1, person.score_points.count
23 23 article.destroy
24 24 assert_equal 2, person.score_points.count
... ... @@ -45,43 +45,50 @@ class ArticleTest &lt; ActiveSupport::TestCase
45 45 end
46 46  
47 47 should 'add merit points to community article owner when an user like it' do
48   - article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  48 + create_point_rule_definition('vote_voteable_author')
  49 + community = fast_create(Community)
  50 + article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
49 51  
50   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: @community.id).first
  52 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
51 53 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
52 54 Vote.create!(:voter => person, :voteable => article, :vote => 1)
53 55 end
54 56 end
55 57  
56 58 should 'add merit points to article when an user like it' do
57   - article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  59 + create_point_rule_definition('vote_voteable')
  60 + article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
58 61 article = article.reload
59 62  
60   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).where(profile_id: @community.id).first
  63 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).first
61 64 assert_difference 'article.points(:category => c.id.to_s)', c.weight do
62 65 Vote.create!(:voter => person, :voteable => article, :vote => 1)
63 66 end
64 67 end
65 68  
66 69 should 'add merit points to community when create a new article' do
  70 + create_point_rule_definition('article_community')
  71 + community = fast_create(Community)
67 72 assert_difference 'community.score_points.count' do
68   - create(TextArticle, :profile_id => @community.id, :author => person)
  73 + create(TextArticle, :profile_id => community.id, :author => person)
69 74 end
70 75 end
71 76  
72 77 should 'add merit points to voter when he likes an article' do
73   - article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  78 + create_point_rule_definition('vote_voter')
  79 + article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
74 80  
75   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: @community.id).first
  81 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
76 82 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
77 83 Vote.create!(:voter => person, :voteable => article, :vote => 1)
78 84 end
79 85 end
80 86  
81 87 should 'add merit points to voter when he dislikes an article' do
82   - article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  88 + create_point_rule_definition('vote_voter')
  89 + article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
83 90  
84   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: @community.id).first
  91 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
85 92 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
86 93 Vote.create!(:voter => person, :voteable => article, :vote => -1)
87 94 end
... ... @@ -111,4 +118,108 @@ class ArticleTest &lt; ActiveSupport::TestCase
111 118 assert_equal 'negative_votes_received', person.reload.badges.first.name
112 119 end
113 120  
  121 +# FIXME Put the tests above to works in profile context.
  122 +# They are the same tests of the general context
  123 +#
  124 +# should 'add merit points to author when create a new article' do
  125 +# create(TextArticle, :profile_id => community.id, :author => person)
  126 +# assert_equal 1, person.score_points.count
  127 +# assert person.score_points.first.action.present?
  128 +# end
  129 +#
  130 +# should 'subtract merit points to author when destroy an article' do
  131 +# article = create(TextArticle, :profile_id => @community.id, :author => person)
  132 +# assert_equal 1, person.score_points.count
  133 +# article.destroy
  134 +# assert_equal 2, person.score_points.count
  135 +# assert_equal 0, person.points
  136 +# end
  137 +#
  138 +# should 'add merit badge to author when create 5 new articles' do
  139 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)
  140 +# GamificationPlugin.gamification_set_rules(environment)
  141 +#
  142 +# 5.times { create(TextArticle, :profile_id => person.id, :author => person) }
  143 +# assert_equal 'article_author', person.badges.first.name
  144 +# assert_equal 1, person.badges.first.level
  145 +# end
  146 +#
  147 +# should 'add merit badge level 2 to author when create 10 new articles' do
  148 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 1)
  149 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'article_author', :level => 2, :custom_fields => {:threshold => 10})
  150 +# GamificationPlugin.gamification_set_rules(environment)
  151 +#
  152 +# 10.times { create(TextArticle, :profile_id => person.id, :author => person) }
  153 +# assert_equal ['article_author'], person.badges.map(&:name).uniq
  154 +# assert_equal [1, 2], person.badges.map(&:level)
  155 +# end
  156 +#
  157 +# should 'add merit points to community article owner when an user like it' do
  158 +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  159 +#
  160 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: @community.id).first
  161 +# assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
  162 +# Vote.create!(:voter => person, :voteable => article, :vote => 1)
  163 +# end
  164 +# end
  165 +#
  166 +# should 'add merit points to article when an user like it' do
  167 +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  168 +# article = article.reload
  169 +#
  170 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).where(profile_id: @community.id).first
  171 +# assert_difference 'article.points(:category => c.id.to_s)', c.weight do
  172 +# Vote.create!(:voter => person, :voteable => article, :vote => 1)
  173 +# end
  174 +# end
  175 +#
  176 +# should 'add merit points to community when create a new article' do
  177 +# assert_difference 'community.score_points.count' do
  178 +# create(TextArticle, :profile_id => @community.id, :author => person)
  179 +# end
  180 +# end
  181 +#
  182 +# should 'add merit points to voter when he likes an article' do
  183 +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  184 +#
  185 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: @community.id).first
  186 +# assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
  187 +# Vote.create!(:voter => person, :voteable => article, :vote => 1)
  188 +# end
  189 +# end
  190 +#
  191 +# should 'add merit points to voter when he dislikes an article' do
  192 +# article = create(TextArticle, :name => 'Test', :profile => @community, :author => person)
  193 +#
  194 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: @community.id).first
  195 +# assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
  196 +# Vote.create!(:voter => person, :voteable => article, :vote => -1)
  197 +# end
  198 +# end
  199 +#
  200 +# should 'add badge to author when users like his article' do
  201 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received')
  202 +# GamificationPlugin.gamification_set_rules(environment)
  203 +#
  204 +# article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
  205 +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) }
  206 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
  207 +# assert_equal [], person.badges
  208 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
  209 +# assert_equal 'positive_votes_received', person.reload.badges.first.name
  210 +# end
  211 +#
  212 +# should 'add badge to author when users dislike his article' do
  213 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received')
  214 +# GamificationPlugin.gamification_set_rules(environment)
  215 +#
  216 +# article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
  217 +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) }
  218 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
  219 +# assert_equal [], person.badges
  220 +# Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
  221 +# assert_equal 'negative_votes_received', person.reload.badges.first.name
  222 +# end
  223 +#
  224 +
114 225 end
... ...
test/unit/comment_test.rb
... ... @@ -5,19 +5,19 @@ class CommentTest &lt; ActiveSupport::TestCase
5 5 def setup
6 6 @person = create_user('testuser').person
7 7 @author = create_user('testauthoruser').person
8   - @community = create_merit_categorization
9   - @article = create(TextileArticle, :profile_id => @community.id, :author_id => @author.id)
  8 + @article = create(TextileArticle, :profile_id => @person.id, :author_id => @author.id)
10 9 @environment = Environment.default
11   - GamificationPlugin.gamification_set_rules(@environment)
12 10 end
13   - attr_accessor :person, :article, :environment, :author, :community
  11 + attr_accessor :person, :article, :environment, :author
14 12  
15 13 should 'add merit points to author when create a new comment' do
  14 + create_point_rule_definition('comment_author')
16 15 create(Comment, :source => article, :author_id => person.id)
17 16 assert_equal 1, person.score_points.count
18 17 end
19 18  
20 19 should 'subtract merit points from author when destroy a comment' do
  20 + create_point_rule_definition('comment_author')
21 21 comment = create(Comment, :source => article, :author_id => person.id)
22 22 assert_equal 1, person.score_points.count
23 23 comment.destroy
... ... @@ -66,79 +66,225 @@ class CommentTest &lt; ActiveSupport::TestCase
66 66 end
67 67  
68 68 should 'add merit points to comment owner when an user like his comment' do
  69 + create_point_rule_definition('vote_voteable_author')
69 70 comment = create(Comment, :source => article, :author_id => person.id)
70 71  
71   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first
  72 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
72 73 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
73 74 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
74 75 end
75 76 end
76 77  
77 78 should 'subtract merit points to comment owner when an user unlike his comment' do
  79 + create_point_rule_definition('vote_voteable_author')
78 80 comment = create(Comment, :source => article, :author_id => author.id)
79 81 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
80 82  
81   - assert_difference 'comment.author.points', -20 do
  83 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
  84 + assert_difference 'comment.author.points', -1*c.weight do
82 85 Vote.where(:voteable_id => comment.id).destroy_all
83 86 end
84 87 end
85 88  
86 89 should 'subtract merit points from comment owner when an user dislike his comment' do
  90 + create_point_rule_definition('vote_voteable_author')
87 91 comment = create(Comment, :source => article, :author_id => person.id)
88 92  
89   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first
  93 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
90 94 assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do
91 95 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
92 96 end
93 97 end
94 98  
95 99 should 'add merit points from comment owner when an user remove a dislike in his comment' do
  100 + create_point_rule_definition('vote_voteable_author')
96 101 comment = create(Comment, :source => article, :author_id => author.id)
97 102 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
98 103  
99   - assert_difference 'comment.author.points', 20 do
  104 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
  105 + assert_difference 'comment.author.points', c.weight do
100 106 Vote.where(:voteable_id => comment.id).destroy_all
101 107 end
102 108 end
103 109  
104 110 should 'add merit points to article author when create a new comment' do
  111 + create_point_rule_definition('comment_article_author')
105 112 assert_difference 'author.score_points.count' do
106 113 create(Comment, :source => article, :author_id => person.id)
107 114 end
108 115 end
109 116  
110 117 should 'add merit points to voter when he likes a comment' do
  118 + create_point_rule_definition('vote_voter')
111 119 comment = create(Comment, :source => article, :author_id => person.id)
112 120  
113   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: community.id).first
  121 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
114 122 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
115 123 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
116 124 end
117 125 end
118 126  
119 127 should 'add merit points to voter when he dislikes a comment' do
  128 + create_point_rule_definition('vote_voter')
120 129 comment = create(Comment, :source => article, :author_id => person.id)
121 130  
122   - c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: community.id).first
  131 + c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
123 132 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
124 133 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
125 134 end
126 135 end
127 136  
128 137 should 'add merit points to source article when create a comment' do
129   - c = GamificationPlugin::PointsCategorization.for_type(:comment_article).where(profile_id: community.id).first
  138 + create_point_rule_definition('comment_article')
  139 + c = GamificationPlugin::PointsCategorization.for_type(:comment_article).first
130 140 assert_difference 'article.points(:category => c.id.to_s)', c.weight do
131 141 create(Comment, :source => article, :author_id => person.id)
132 142 end
133 143 end
134 144  
135 145 should 'add merit points to source community when create a comment' do
  146 + create_point_rule_definition('comment_community')
  147 + community = fast_create(Community)
136 148 article = create(TextileArticle, :profile_id => community.id, :author_id => author.id)
137 149  
138   - c = GamificationPlugin::PointsCategorization.for_type(:comment_community).where(profile_id: community.id).first
  150 + c = GamificationPlugin::PointsCategorization.for_type(:comment_community).first
139 151 assert_difference 'community.points(:category => c.id.to_s)', c.weight do
140 152 create(Comment, :source => article, :author_id => person.id)
141 153 end
142 154 end
143 155  
  156 +
  157 +# FIXME Put the tests above to works in profile context.
  158 +# They are the same tests of the general context
  159 +#
  160 +# should 'add merit points to author when create a new comment' do
  161 +# create(Comment, :source => article, :author_id => person.id)
  162 +# assert_equal 1, person.score_points.count
  163 +# end
  164 +#
  165 +# should 'subtract merit points from author when destroy a comment' do
  166 +# comment = create(Comment, :source => article, :author_id => person.id)
  167 +# assert_equal 1, person.score_points.count
  168 +# comment.destroy
  169 +# assert_equal 2, person.score_points.count
  170 +# assert_equal 0, person.points
  171 +# end
  172 +#
  173 +# should 'add merit badge to author when create 5 new comments' do
  174 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'comment_author')
  175 +# GamificationPlugin.gamification_set_rules(environment)
  176 +#
  177 +# 5.times { create(Comment, :source => article, :author_id => person.id) }
  178 +# assert_equal 'comment_author', person.badges.first.name
  179 +# end
  180 +#
  181 +# should 'add merit badge to source author when create 5 new comments' do
  182 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'comment_received')
  183 +# GamificationPlugin.gamification_set_rules(environment)
  184 +#
  185 +# 5.times { create(Comment, :source => article, :author_id => person.id) }
  186 +# assert_equal 'comment_received', author.badges.first.name
  187 +# end
  188 +#
  189 +# should 'add badge to author when users like his comment' do
  190 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'positive_votes_received')
  191 +# GamificationPlugin.gamification_set_rules(environment)
  192 +#
  193 +# comment = create(Comment, :source => article, :author_id => person.id)
  194 +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) }
  195 +# Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1)
  196 +# assert_equal [], person.badges
  197 +# Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1)
  198 +# assert_equal 'positive_votes_received', person.reload.badges.first.name
  199 +# end
  200 +#
  201 +# should 'add badge to author when users dislike his comment' do
  202 +# GamificationPlugin::Badge.create!(:owner => environment, :name => 'negative_votes_received')
  203 +# GamificationPlugin.gamification_set_rules(environment)
  204 +#
  205 +# comment = create(Comment, :source => article, :author_id => person.id)
  206 +# 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1) }
  207 +# Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1)
  208 +# assert_equal [], person.badges
  209 +# Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1)
  210 +# assert_equal 'negative_votes_received', person.reload.badges.first.name
  211 +# end
  212 +#
  213 +# should 'add merit points to comment owner when an user like his comment' do
  214 +# comment = create(Comment, :source => article, :author_id => person.id)
  215 +#
  216 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first
  217 +# assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
  218 +# Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  219 +# end
  220 +# end
  221 +#
  222 +# should 'subtract merit points to comment owner when an user unlike his comment' do
  223 +# comment = create(Comment, :source => article, :author_id => author.id)
  224 +# Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  225 +#
  226 +# assert_difference 'comment.author.points', -20 do
  227 +# Vote.where(:voteable_id => comment.id).destroy_all
  228 +# end
  229 +# end
  230 +#
  231 +# should 'subtract merit points from comment owner when an user dislike his comment' do
  232 +# comment = create(Comment, :source => article, :author_id => person.id)
  233 +#
  234 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first
  235 +# assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do
  236 +# Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  237 +# end
  238 +# end
  239 +#
  240 +# should 'add merit points from comment owner when an user remove a dislike in his comment' do
  241 +# comment = create(Comment, :source => article, :author_id => author.id)
  242 +# Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  243 +#
  244 +# assert_difference 'comment.author.points', 20 do
  245 +# Vote.where(:voteable_id => comment.id).destroy_all
  246 +# end
  247 +# end
  248 +#
  249 +# should 'add merit points to article author when create a new comment' do
  250 +# assert_difference 'author.score_points.count' do
  251 +# create(Comment, :source => article, :author_id => person.id)
  252 +# end
  253 +# end
  254 +#
  255 +# should 'add merit points to voter when he likes a comment' do
  256 +# comment = create(Comment, :source => article, :author_id => person.id)
  257 +#
  258 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: community.id).first
  259 +# assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
  260 +# Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  261 +# end
  262 +# end
  263 +#
  264 +# should 'add merit points to voter when he dislikes a comment' do
  265 +# comment = create(Comment, :source => article, :author_id => person.id)
  266 +#
  267 +# c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).where(profile_id: community.id).first
  268 +# assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
  269 +# Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  270 +# end
  271 +# end
  272 +#
  273 +# should 'add merit points to source article when create a comment' do
  274 +# c = GamificationPlugin::PointsCategorization.for_type(:comment_article).where(profile_id: community.id).first
  275 +# assert_difference 'article.points(:category => c.id.to_s)', c.weight do
  276 +# create(Comment, :source => article, :author_id => person.id)
  277 +# end
  278 +# end
  279 +#
  280 +# should 'add merit points to source community when create a comment' do
  281 +# article = create(TextileArticle, :profile_id => community.id, :author_id => author.id)
  282 +#
  283 +# c = GamificationPlugin::PointsCategorization.for_type(:comment_community).where(profile_id: community.id).first
  284 +# assert_difference 'community.points(:category => c.id.to_s)', c.weight do
  285 +# create(Comment, :source => article, :author_id => person.id)
  286 +# end
  287 +# end
  288 +#
  289 +
144 290 end
... ...
test/unit/person_test.rb
... ... @@ -4,8 +4,6 @@ class PersonTest &lt; ActiveSupport::TestCase
4 4  
5 5 def setup
6 6 @environment = Environment.default
7   - create_merit_categorization
8   - GamificationPlugin.gamification_set_rules(@environment)
9 7 @person = create_user('testuser').person
10 8 end
11 9 attr_accessor :environment, :person
... ... @@ -29,6 +27,7 @@ class PersonTest &lt; ActiveSupport::TestCase
29 27 end
30 28  
31 29 should 'add points when add someone as a friendly' do
  30 + create_point_rule_definition('friends')
32 31 other_person = create_user("testuserfriend").person
33 32 person.add_friend(other_person)
34 33 c = GamificationPlugin::PointsCategorization.for_type(:friends).first
... ...
test/unit/point_rules_test.rb
... ... @@ -4,16 +4,15 @@ class PointRulesTest &lt; ActiveSupport::TestCase
4 4  
5 5 def setup
6 6 @environment = Environment.default
7   - create_merit_categorization
8 7 @point_rules = Merit::PointRules.new(@environment)
9 8 end
10 9  
11 10 attr_accessor :environment, :point_rules
12 11  
13   - #should 'not define rules when environment is nil' do
14   - #point_rules = Merit::PointRules.new
15   - #assert point_rules.defined_rules.blank?
16   - #end
  12 + should 'not define rules when environment is nil' do
  13 + point_rules = Merit::PointRules.new
  14 + assert point_rules.defined_rules.blank?
  15 + end
17 16  
18 17 should 'define rules when environment is present' do
19 18 assert point_rules.defined_rules.present?
... ...
test/unit/profile_test.rb
... ... @@ -45,7 +45,8 @@ class ProfileTest &lt; ActiveSupport::TestCase
45 45 end
46 46  
47 47 should 'update profile level when the score changes' do
48   - community = create_merit_categorization
  48 + create_point_rule_definition('article_author')
  49 + community = fast_create(Community)
49 50 GamificationPlugin.gamification_set_rules(environment)
50 51  
51 52 person = create_user('testuser').person
... ...