Merge Request #7

Open
noosfero-plugins/gamification!7
Created by Hugo Melo

Merit callback moved to delayed_job

Assignee: Victor Costa
Milestone: None
This can't be merged automatically, even if it could be merged you don't have the permission to do so.
This can be merged automatically but you don't have the permission to do so.
Commits (1)
2 participants
lib/merit_ext.rb
@@ -43,7 +43,7 @@ module Merit @@ -43,7 +43,7 @@ module Merit
43 module ClassMethods 43 module ClassMethods
44 44
45 def has_merit_actions(options = {}) 45 def has_merit_actions(options = {})
46 - after_create { |obj| obj.new_merit_action(:create, options) } 46 + after_create { |obj| obj.delay.new_merit_action(:create, options) }
47 before_destroy { |obj| obj.new_merit_action(:destroy, options) } 47 before_destroy { |obj| obj.new_merit_action(:destroy, options) }
48 end 48 end
49 49
test/unit/api_test.rb
@@ -56,7 +56,7 @@ class APITest < ActiveSupport::TestCase @@ -56,7 +56,7 @@ class APITest < ActiveSupport::TestCase
56 another_person.save 56 another_person.save
57 another_person.add_badge(badge.id) 57 another_person.add_badge(badge.id)
58 get "/api/v1/gamification_plugin/people/#{another_person.id}/badges?#{params.to_query}" 58 get "/api/v1/gamification_plugin/people/#{another_person.id}/badges?#{params.to_query}"
59 - json = JSON.parse(last_response.body) 59 + JSON.parse(last_response.body)
60 assert_equal 404, last_response.status 60 assert_equal 404, last_response.status
61 end 61 end
62 62
@@ -80,6 +80,8 @@ class APITest < ActiveSupport::TestCase @@ -80,6 +80,8 @@ class APITest < ActiveSupport::TestCase
80 article = create(TextArticle, :profile_id => @person.id, :author => @person) 80 article = create(TextArticle, :profile_id => @person.id, :author => @person)
81 create(Comment, :source_id => article.id, :author => fast_create(Person)) 81 create(Comment, :source_id => article.id, :author => fast_create(Person))
82 82
  83 + process_delayed_job_queue
  84 +
83 get "/api/v1/gamification_plugin/my/points?#{params.to_query}" 85 get "/api/v1/gamification_plugin/my/points?#{params.to_query}"
84 json = JSON.parse(last_response.body) 86 json = JSON.parse(last_response.body)
85 assert_equal default_point_weight(:article_author) + default_point_weight(:comment_article_author), json['points'] 87 assert_equal default_point_weight(:article_author) + default_point_weight(:comment_article_author), json['points']
@@ -88,6 +90,9 @@ class APITest < ActiveSupport::TestCase @@ -88,6 +90,9 @@ class APITest < ActiveSupport::TestCase
88 should 'get my points filtered by type' do 90 should 'get my points filtered by type' do
89 article = create(TextArticle, :profile_id => @person.id, :author => @person) 91 article = create(TextArticle, :profile_id => @person.id, :author => @person)
90 create(Comment, :source_id => article.id, :author => fast_create(Person)) 92 create(Comment, :source_id => article.id, :author => fast_create(Person))
  93 +
  94 + process_delayed_job_queue
  95 +
91 params[:type] = 'article_author' 96 params[:type] = 'article_author'
92 97
93 get "/api/v1/gamification_plugin/my/points_by_type?#{params.to_query}" 98 get "/api/v1/gamification_plugin/my/points_by_type?#{params.to_query}"
@@ -100,6 +105,9 @@ class APITest < ActiveSupport::TestCase @@ -100,6 +105,9 @@ class APITest < ActiveSupport::TestCase
100 create_point_rule_definition('article_author', community) 105 create_point_rule_definition('article_author', community)
101 create(TextArticle, :profile_id => @person.id, :author => @person) 106 create(TextArticle, :profile_id => @person.id, :author => @person)
102 create(TextArticle, :profile_id => community.id, :author => @person) 107 create(TextArticle, :profile_id => community.id, :author => @person)
  108 +
  109 + process_delayed_job_queue
  110 +
103 params[:profile] = community.identifier 111 params[:profile] = community.identifier
104 112
105 get "/api/v1/gamification_plugin/my/points_by_profile?#{params.to_query}" 113 get "/api/v1/gamification_plugin/my/points_by_profile?#{params.to_query}"
@@ -113,6 +121,8 @@ class APITest < ActiveSupport::TestCase @@ -113,6 +121,8 @@ class APITest < ActiveSupport::TestCase
113 create(TextArticle, :profile_id => @person.id, :author => @person) 121 create(TextArticle, :profile_id => @person.id, :author => @person)
114 create(TextArticle, :profile_id => community.id, :author => @person) 122 create(TextArticle, :profile_id => community.id, :author => @person)
115 123
  124 + process_delayed_job_queue
  125 +
116 get "/api/v1/gamification_plugin/my/points_out_of_profiles?#{params.to_query}" 126 get "/api/v1/gamification_plugin/my/points_out_of_profiles?#{params.to_query}"
117 json = JSON.parse(last_response.body) 127 json = JSON.parse(last_response.body)
118 assert_equal 2*default_point_weight(:article_author), json['points'] 128 assert_equal 2*default_point_weight(:article_author), json['points']
@@ -122,6 +132,8 @@ class APITest < ActiveSupport::TestCase @@ -122,6 +132,8 @@ class APITest < ActiveSupport::TestCase
122 article = create(TextArticle, :profile_id => @person.id, :author => @person) 132 article = create(TextArticle, :profile_id => @person.id, :author => @person)
123 create(Comment, :source_id => article.id, :author => fast_create(Person)) 133 create(Comment, :source_id => article.id, :author => fast_create(Person))
124 134
  135 + process_delayed_job_queue
  136 +
125 get "/api/v1/gamification_plugin/people/#{person.id}/points?#{params.to_query}" 137 get "/api/v1/gamification_plugin/people/#{person.id}/points?#{params.to_query}"
126 json = JSON.parse(last_response.body) 138 json = JSON.parse(last_response.body)
127 assert_equal default_point_weight(:article_author) + default_point_weight(:comment_article_author), json['points'] 139 assert_equal default_point_weight(:article_author) + default_point_weight(:comment_article_author), json['points']
@@ -130,6 +142,9 @@ class APITest < ActiveSupport::TestCase @@ -130,6 +142,9 @@ class APITest < ActiveSupport::TestCase
130 should 'get points of a person filtered by type' do 142 should 'get points of a person filtered by type' do
131 article = create(TextArticle, :profile_id => @person.id, :author => @person) 143 article = create(TextArticle, :profile_id => @person.id, :author => @person)
132 create(Comment, :source_id => article.id, :author => fast_create(Person)) 144 create(Comment, :source_id => article.id, :author => fast_create(Person))
  145 +
  146 + process_delayed_job_queue
  147 +
133 params[:type] = 'article_author' 148 params[:type] = 'article_author'
134 149
135 get "/api/v1/gamification_plugin/people/#{@person.id}/points_by_type?#{params.to_query}" 150 get "/api/v1/gamification_plugin/people/#{@person.id}/points_by_type?#{params.to_query}"
@@ -142,6 +157,9 @@ class APITest < ActiveSupport::TestCase @@ -142,6 +157,9 @@ class APITest < ActiveSupport::TestCase
142 create_point_rule_definition('article_author', community) 157 create_point_rule_definition('article_author', community)
143 create(TextArticle, :profile_id => @person.id, :author => @person) 158 create(TextArticle, :profile_id => @person.id, :author => @person)
144 create(TextArticle, :profile_id => community.id, :author => @person) 159 create(TextArticle, :profile_id => community.id, :author => @person)
  160 +
  161 + process_delayed_job_queue
  162 +
145 params[:profile] = community.identifier 163 params[:profile] = community.identifier
146 164
147 get "/api/v1/gamification_plugin/people/#{@person.id}/points_by_profile?#{params.to_query}" 165 get "/api/v1/gamification_plugin/people/#{@person.id}/points_by_profile?#{params.to_query}"
@@ -155,6 +173,8 @@ class APITest < ActiveSupport::TestCase @@ -155,6 +173,8 @@ class APITest < ActiveSupport::TestCase
155 create(TextArticle, :profile_id => @person.id, :author => @person) 173 create(TextArticle, :profile_id => @person.id, :author => @person)
156 create(TextArticle, :profile_id => community.id, :author => @person) 174 create(TextArticle, :profile_id => community.id, :author => @person)
157 175
  176 + process_delayed_job_queue
  177 +
158 get "/api/v1/gamification_plugin/people/#{@person.id}/points_out_of_profiles?#{params.to_query}" 178 get "/api/v1/gamification_plugin/people/#{@person.id}/points_out_of_profiles?#{params.to_query}"
159 json = JSON.parse(last_response.body) 179 json = JSON.parse(last_response.body)
160 assert_equal 2*default_point_weight(:article_author), json['points'] 180 assert_equal 2*default_point_weight(:article_author), json['points']
test/unit/article_follower_test.rb
@@ -14,9 +14,12 @@ class ArticleFollowerTest < ActiveSupport::TestCase @@ -14,9 +14,12 @@ class ArticleFollowerTest < ActiveSupport::TestCase
14 create_point_rule_definition('followed_article') 14 create_point_rule_definition('followed_article')
15 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 15 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
16 16
  17 + process_delayed_job_queue
  18 +
17 c = GamificationPlugin::PointsCategorization.for_type(:followed_article).first 19 c = GamificationPlugin::PointsCategorization.for_type(:followed_article).first
18 assert_difference 'article.points(:category => c.id.to_s)', c.weight do 20 assert_difference 'article.points(:category => c.id.to_s)', c.weight do
19 article.person_followers << person 21 article.person_followers << person
  22 + process_delayed_job_queue
20 end 23 end
21 end 24 end
22 25
@@ -25,9 +28,12 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase @@ -25,9 +28,12 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase
25 28
26 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 29 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
27 30
  31 + process_delayed_job_queue
  32 +
28 c = GamificationPlugin::PointsCategorization.for_type(:follower).first 33 c = GamificationPlugin::PointsCategorization.for_type(:follower).first
29 assert_difference 'person.points(:category => c.id.to_s)', c.weight do 34 assert_difference 'person.points(:category => c.id.to_s)', c.weight do
30 article.person_followers << person 35 article.person_followers << person
  36 + process_delayed_job_queue
31 end 37 end
32 end 38 end
33 39
@@ -36,9 +42,12 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase @@ -36,9 +42,12 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase
36 42
37 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 43 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
38 44
  45 + process_delayed_job_queue
  46 +
39 c = GamificationPlugin::PointsCategorization.for_type(:followed_article_author).first 47 c = GamificationPlugin::PointsCategorization.for_type(:followed_article_author).first
40 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do 48 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
41 article.person_followers << person 49 article.person_followers << person
  50 + process_delayed_job_queue
42 end 51 end
43 end 52 end
44 53
@@ -46,11 +55,18 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase @@ -46,11 +55,18 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase
46 create_point_rule_definition('follower') 55 create_point_rule_definition('follower')
47 follower = create_user('someuser').person 56 follower = create_user('someuser').person
48 article = create(TextArticle, :profile_id => community.id, :author => person) 57 article = create(TextArticle, :profile_id => community.id, :author => person)
  58 +
  59 + process_delayed_job_queue
  60 +
49 score_points = follower.score_points.count 61 score_points = follower.score_points.count
50 points = follower.points 62 points = follower.points
51 article.person_followers << follower 63 article.person_followers << follower
  64 + process_delayed_job_queue
  65 +
52 assert_equal score_points + 1, follower.score_points.count 66 assert_equal score_points + 1, follower.score_points.count
53 ArticleFollower.last.destroy 67 ArticleFollower.last.destroy
  68 + process_delayed_job_queue
  69 +
54 assert_equal score_points + 2, follower.score_points.count 70 assert_equal score_points + 2, follower.score_points.count
55 assert_equal points, follower.points 71 assert_equal points, follower.points
56 end 72 end
@@ -58,9 +74,13 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase @@ -58,9 +74,13 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase
58 should 'subtract merit points to article author when a user unfollow an article' do 74 should 'subtract merit points to article author when a user unfollow an article' do
59 create_point_rule_definition('follower') 75 create_point_rule_definition('follower')
60 article = create(TextArticle, :profile_id => community.id, :author => person) 76 article = create(TextArticle, :profile_id => community.id, :author => person)
  77 +
  78 + process_delayed_job_queue
  79 +
61 assert_no_difference 'person.points' do 80 assert_no_difference 'person.points' do
62 assert_difference 'person.score_points.count' do 81 assert_difference 'person.score_points.count' do
63 article.person_followers << fast_create(Person) 82 article.person_followers << fast_create(Person)
  83 + process_delayed_job_queue
64 end 84 end
65 assert_difference 'person.score_points.count' do 85 assert_difference 'person.score_points.count' do
66 ArticleFollower.last.destroy 86 ArticleFollower.last.destroy
@@ -71,11 +91,16 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase @@ -71,11 +91,16 @@ class ArticleFollowerTest &lt; ActiveSupport::TestCase
71 should 'subtract merit points to article when a user unfollow an article' do 91 should 'subtract merit points to article when a user unfollow an article' do
72 create_point_rule_definition('followed_article') 92 create_point_rule_definition('followed_article')
73 article = create(TextArticle, :profile_id => community.id, :author => person) 93 article = create(TextArticle, :profile_id => community.id, :author => person)
  94 + process_delayed_job_queue
74 score_points = article.score_points.count 95 score_points = article.score_points.count
75 points = article.points 96 points = article.points
76 article.person_followers << person 97 article.person_followers << person
  98 + process_delayed_job_queue
  99 +
77 assert_equal score_points + 1, article.score_points.count 100 assert_equal score_points + 1, article.score_points.count
78 ArticleFollower.last.destroy 101 ArticleFollower.last.destroy
  102 + process_delayed_job_queue
  103 +
79 assert_equal score_points + 2, article.score_points.count 104 assert_equal score_points + 2, article.score_points.count
80 assert_equal points, article.points 105 assert_equal points, article.points
81 end 106 end
test/unit/article_test.rb
@@ -12,6 +12,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -12,6 +12,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
12 should 'add merit points to author when create a new article' do 12 should 'add merit points to author when create a new article' do
13 create_point_rule_definition('article_author') 13 create_point_rule_definition('article_author')
14 create(TextArticle, :profile_id => person.id, :author => person) 14 create(TextArticle, :profile_id => person.id, :author => person)
  15 + process_delayed_job_queue
15 assert_equal 1, person.score_points.count 16 assert_equal 1, person.score_points.count
16 assert person.score_points.first.action.present? 17 assert person.score_points.first.action.present?
17 end 18 end
@@ -19,8 +20,10 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -19,8 +20,10 @@ class ArticleTest &lt; ActiveSupport::TestCase
19 should 'subtract merit points to author when destroy an article' do 20 should 'subtract merit points to author when destroy an article' do
20 create_point_rule_definition('article_author') 21 create_point_rule_definition('article_author')
21 article = create(TextArticle, :profile_id => person.id, :author => person) 22 article = create(TextArticle, :profile_id => person.id, :author => person)
  23 + process_delayed_job_queue
22 assert_equal 1, person.score_points.count 24 assert_equal 1, person.score_points.count
23 article.destroy 25 article.destroy
  26 + process_delayed_job_queue
24 assert_equal 2, person.score_points.count 27 assert_equal 2, person.score_points.count
25 assert_equal 0, person.points 28 assert_equal 0, person.points
26 end 29 end
@@ -30,6 +33,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -30,6 +33,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
30 GamificationPlugin.gamification_set_rules(environment) 33 GamificationPlugin.gamification_set_rules(environment)
31 34
32 5.times { create(TextArticle, :profile_id => person.id, :author => person) } 35 5.times { create(TextArticle, :profile_id => person.id, :author => person) }
  36 + process_delayed_job_queue
33 assert_equal 'article_author', person.badges.first.name 37 assert_equal 'article_author', person.badges.first.name
34 assert_equal 1, person.badges.first.level 38 assert_equal 1, person.badges.first.level
35 end 39 end
@@ -40,6 +44,8 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -40,6 +44,8 @@ class ArticleTest &lt; ActiveSupport::TestCase
40 GamificationPlugin.gamification_set_rules(environment) 44 GamificationPlugin.gamification_set_rules(environment)
41 45
42 10.times { create(TextArticle, :profile_id => person.id, :author => person) } 46 10.times { create(TextArticle, :profile_id => person.id, :author => person) }
  47 + process_delayed_job_queue
  48 + sleep 4
43 assert_equal ['article_author'], person.badges.map(&:name).uniq 49 assert_equal ['article_author'], person.badges.map(&:name).uniq
44 assert_equal [1, 2], person.badges.map(&:level) 50 assert_equal [1, 2], person.badges.map(&:level)
45 end 51 end
@@ -48,49 +54,59 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -48,49 +54,59 @@ class ArticleTest &lt; ActiveSupport::TestCase
48 create_point_rule_definition('vote_voteable_author') 54 create_point_rule_definition('vote_voteable_author')
49 community = fast_create(Community) 55 community = fast_create(Community)
50 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 56 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  57 + process_delayed_job_queue
51 58
52 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 59 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
53 - assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do  
54 - Vote.create!(:voter => person, :voteable => article, :vote => 1)  
55 - end 60 + points = article.author.points(:category => c.id.to_s)
  61 + Vote.create!(:voter => person, :voteable => article, :vote => 1)
  62 + process_delayed_job_queue
  63 + assert_equal article.author.points(:category => c.id.to_s), points + c.weight
56 end 64 end
57 65
58 should 'add merit points to article when an user like it' do 66 should 'add merit points to article when an user like it' do
59 create_point_rule_definition('vote_voteable') 67 create_point_rule_definition('vote_voteable')
60 article = create(TextArticle, :name => 'Test', :profile => person, :author => person) 68 article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
  69 + process_delayed_job_queue
61 article = article.reload 70 article = article.reload
62 71
63 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).first 72 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).first
64 assert_difference 'article.points(:category => c.id.to_s)', c.weight do 73 assert_difference 'article.points(:category => c.id.to_s)', c.weight do
65 Vote.create!(:voter => person, :voteable => article, :vote => 1) 74 Vote.create!(:voter => person, :voteable => article, :vote => 1)
  75 + process_delayed_job_queue
66 end 76 end
67 end 77 end
68 78
69 should 'add merit points to community when create a new article' do 79 should 'add merit points to community when create a new article' do
70 create_point_rule_definition('article_community') 80 create_point_rule_definition('article_community')
71 community = fast_create(Community) 81 community = fast_create(Community)
  82 + process_delayed_job_queue
72 assert_difference 'community.score_points.count' do 83 assert_difference 'community.score_points.count' do
73 create(TextArticle, :profile_id => community.id, :author => person) 84 create(TextArticle, :profile_id => community.id, :author => person)
  85 + process_delayed_job_queue
74 end 86 end
75 end 87 end
76 88
77 should 'add merit points to voter when he likes an article' do 89 should 'add merit points to voter when he likes an article' do
78 create_point_rule_definition('vote_voter') 90 create_point_rule_definition('vote_voter')
79 article = create(TextArticle, :name => 'Test', :profile => person, :author => person) 91 article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
  92 + process_delayed_job_queue
80 93
81 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 94 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
82 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do 95 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
83 Vote.create!(:voter => person, :voteable => article, :vote => 1) 96 Vote.create!(:voter => person, :voteable => article, :vote => 1)
  97 + process_delayed_job_queue
84 end 98 end
85 end 99 end
86 100
87 should 'add merit points to voter when he dislikes an article' do 101 should 'add merit points to voter when he dislikes an article' do
88 create_point_rule_definition('vote_voter') 102 create_point_rule_definition('vote_voter')
89 article = create(TextArticle, :name => 'Test', :profile => person, :author => person) 103 article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
  104 + process_delayed_job_queue
90 105
91 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 106 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
92 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do 107 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
93 Vote.create!(:voter => person, :voteable => article, :vote => -1) 108 Vote.create!(:voter => person, :voteable => article, :vote => -1)
  109 + process_delayed_job_queue
94 end 110 end
95 end 111 end
96 112
@@ -101,8 +117,10 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -101,8 +117,10 @@ class ArticleTest &lt; ActiveSupport::TestCase
101 article = create(TextArticle, :name => 'Test', :profile => person, :author => person) 117 article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
102 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) } 118 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) }
103 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) 119 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
  120 + process_delayed_job_queue
104 assert_equal [], person.badges 121 assert_equal [], person.badges
105 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) 122 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
  123 + process_delayed_job_queue
106 assert_equal 'positive_votes_received', person.reload.badges.first.name 124 assert_equal 'positive_votes_received', person.reload.badges.first.name
107 end 125 end
108 126
@@ -113,8 +131,10 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -113,8 +131,10 @@ class ArticleTest &lt; ActiveSupport::TestCase
113 article = create(TextArticle, :name => 'Test', :profile => person, :author => person) 131 article = create(TextArticle, :name => 'Test', :profile => person, :author => person)
114 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) } 132 4.times { Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) }
115 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1) 133 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => 1)
  134 + process_delayed_job_queue
116 assert_equal [], person.badges 135 assert_equal [], person.badges
117 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1) 136 Vote.create!(:voter => fast_create(Person), :voteable => article, :vote => -1)
  137 + process_delayed_job_queue
118 assert_equal 'negative_votes_received', person.reload.badges.first.name 138 assert_equal 'negative_votes_received', person.reload.badges.first.name
119 end 139 end
120 140
@@ -123,6 +143,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -123,6 +143,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
123 community = fast_create(Community) 143 community = fast_create(Community)
124 rule = create_point_rule_definition('article_author', community) 144 rule = create_point_rule_definition('article_author', community)
125 create(TextArticle, profile_id: community.id, author_id: person.id) 145 create(TextArticle, profile_id: community.id, author_id: person.id)
  146 + process_delayed_job_queue
126 assert_equal rule.weight, person.points_by_profile(community.identifier) 147 assert_equal rule.weight, person.points_by_profile(community.identifier)
127 assert person.score_points.first.action.present? 148 assert person.score_points.first.action.present?
128 end 149 end
@@ -131,8 +152,10 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -131,8 +152,10 @@ class ArticleTest &lt; ActiveSupport::TestCase
131 community = fast_create(Community) 152 community = fast_create(Community)
132 rule = create_point_rule_definition('article_author', community) 153 rule = create_point_rule_definition('article_author', community)
133 article = create(TextArticle, profile_id: community.id, author_id: person.id) 154 article = create(TextArticle, profile_id: community.id, author_id: person.id)
  155 + process_delayed_job_queue
134 assert_equal rule.weight, person.points_by_profile(community.identifier) 156 assert_equal rule.weight, person.points_by_profile(community.identifier)
135 article.destroy 157 article.destroy
  158 + process_delayed_job_queue
136 assert_equal 0, person.points 159 assert_equal 0, person.points
137 end 160 end
138 161
@@ -140,10 +163,12 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -140,10 +163,12 @@ class ArticleTest &lt; ActiveSupport::TestCase
140 community = fast_create(Community) 163 community = fast_create(Community)
141 create_point_rule_definition('vote_voteable_author', community) 164 create_point_rule_definition('vote_voteable_author', community)
142 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 165 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  166 + process_delayed_job_queue
143 167
144 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 168 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
145 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do 169 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
146 Vote.create!(:voter => person, :voteable => article, :vote => 1) 170 Vote.create!(:voter => person, :voteable => article, :vote => 1)
  171 + process_delayed_job_queue
147 end 172 end
148 end 173 end
149 174
@@ -151,19 +176,23 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -151,19 +176,23 @@ class ArticleTest &lt; ActiveSupport::TestCase
151 community = fast_create(Community) 176 community = fast_create(Community)
152 create_point_rule_definition('vote_voteable', community) 177 create_point_rule_definition('vote_voteable', community)
153 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 178 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  179 + process_delayed_job_queue
154 article = article.reload 180 article = article.reload
155 181
156 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).first 182 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable).first
157 assert_difference 'article.points(:category => c.id.to_s)', c.weight do 183 assert_difference 'article.points(:category => c.id.to_s)', c.weight do
158 Vote.create!(:voter => person, :voteable => article, :vote => 1) 184 Vote.create!(:voter => person, :voteable => article, :vote => 1)
  185 + process_delayed_job_queue
159 end 186 end
160 end 187 end
161 188
162 should 'add merit points to community when create a new article on community' do 189 should 'add merit points to community when create a new article on community' do
163 community = fast_create(Community) 190 community = fast_create(Community)
164 create_point_rule_definition('article_community') 191 create_point_rule_definition('article_community')
  192 + process_delayed_job_queue
165 assert_difference 'community.score_points.count' do 193 assert_difference 'community.score_points.count' do
166 create(TextArticle, :profile_id => community.id, :author => person) 194 create(TextArticle, :profile_id => community.id, :author => person)
  195 + process_delayed_job_queue
167 end 196 end
168 end 197 end
169 198
@@ -171,10 +200,12 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -171,10 +200,12 @@ class ArticleTest &lt; ActiveSupport::TestCase
171 community = fast_create(Community) 200 community = fast_create(Community)
172 create_point_rule_definition('vote_voter', community) 201 create_point_rule_definition('vote_voter', community)
173 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 202 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  203 + process_delayed_job_queue
174 204
175 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 205 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
176 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do 206 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
177 Vote.create!(:voter => person, :voteable => article, :vote => 1) 207 Vote.create!(:voter => person, :voteable => article, :vote => 1)
  208 + process_delayed_job_queue
178 end 209 end
179 end 210 end
180 211
@@ -182,10 +213,12 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -182,10 +213,12 @@ class ArticleTest &lt; ActiveSupport::TestCase
182 community = fast_create(Community) 213 community = fast_create(Community)
183 create_point_rule_definition('vote_voter', community) 214 create_point_rule_definition('vote_voter', community)
184 article = create(TextArticle, :name => 'Test', :profile => community, :author => person) 215 article = create(TextArticle, :name => 'Test', :profile => community, :author => person)
  216 + process_delayed_job_queue
185 217
186 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 218 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
187 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do 219 assert_difference 'article.author.points(:category => c.id.to_s)', c.weight do
188 Vote.create!(:voter => person, :voteable => article, :vote => -1) 220 Vote.create!(:voter => person, :voteable => article, :vote => -1)
  221 + process_delayed_job_queue
189 end 222 end
190 end 223 end
191 224
@@ -195,6 +228,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -195,6 +228,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
195 GamificationPlugin.gamification_set_rules(environment) 228 GamificationPlugin.gamification_set_rules(environment)
196 229
197 5.times { create(TextArticle, :profile_id => organization.id, :author => person) } 230 5.times { create(TextArticle, :profile_id => organization.id, :author => person) }
  231 + process_delayed_job_queue
198 assert_equal 'article_author', person.badges.first.name 232 assert_equal 'article_author', person.badges.first.name
199 assert_equal 1, person.badges.first.level 233 assert_equal 1, person.badges.first.level
200 end 234 end
@@ -206,6 +240,7 @@ class ArticleTest &lt; ActiveSupport::TestCase @@ -206,6 +240,7 @@ class ArticleTest &lt; ActiveSupport::TestCase
206 GamificationPlugin.gamification_set_rules(environment) 240 GamificationPlugin.gamification_set_rules(environment)
207 241
208 5.times { create(TextArticle, :profile_id => other_organization.id, :author => person) } 242 5.times { create(TextArticle, :profile_id => other_organization.id, :author => person) }
  243 + process_delayed_job_queue
209 assert_equal [], person.badges 244 assert_equal [], person.badges
210 end 245 end
211 246
test/unit/comment_test.rb
@@ -13,14 +13,17 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -13,14 +13,17 @@ class CommentTest &lt; ActiveSupport::TestCase
13 should 'add merit points to author when create a new comment' do 13 should 'add merit points to author when create a new comment' do
14 create_point_rule_definition('comment_author') 14 create_point_rule_definition('comment_author')
15 create(Comment, :source => article, :author_id => person.id) 15 create(Comment, :source => article, :author_id => person.id)
  16 + process_delayed_job_queue
16 assert_equal 1, person.score_points.count 17 assert_equal 1, person.score_points.count
17 end 18 end
18 19
19 should 'subtract merit points from author when destroy a comment' do 20 should 'subtract merit points from author when destroy a comment' do
20 create_point_rule_definition('comment_author') 21 create_point_rule_definition('comment_author')
21 comment = create(Comment, :source => article, :author_id => person.id) 22 comment = create(Comment, :source => article, :author_id => person.id)
  23 + process_delayed_job_queue
22 assert_equal 1, person.score_points.count 24 assert_equal 1, person.score_points.count
23 comment.destroy 25 comment.destroy
  26 + process_delayed_job_queue
24 assert_equal 2, person.score_points.count 27 assert_equal 2, person.score_points.count
25 assert_equal 0, person.points 28 assert_equal 0, person.points
26 end 29 end
@@ -30,6 +33,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -30,6 +33,7 @@ class CommentTest &lt; ActiveSupport::TestCase
30 GamificationPlugin.gamification_set_rules(environment) 33 GamificationPlugin.gamification_set_rules(environment)
31 34
32 5.times { create(Comment, :source => article, :author_id => person.id) } 35 5.times { create(Comment, :source => article, :author_id => person.id) }
  36 + process_delayed_job_queue
33 assert_equal 'comment_author', person.badges.first.name 37 assert_equal 'comment_author', person.badges.first.name
34 end 38 end
35 39
@@ -38,6 +42,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -38,6 +42,7 @@ class CommentTest &lt; ActiveSupport::TestCase
38 GamificationPlugin.gamification_set_rules(environment) 42 GamificationPlugin.gamification_set_rules(environment)
39 43
40 5.times { create(Comment, :source => article, :author_id => person.id) } 44 5.times { create(Comment, :source => article, :author_id => person.id) }
  45 + process_delayed_job_queue
41 assert_equal 'comment_received', author.badges.first.name 46 assert_equal 'comment_received', author.badges.first.name
42 end 47 end
43 48
@@ -48,8 +53,10 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -48,8 +53,10 @@ class CommentTest &lt; ActiveSupport::TestCase
48 comment = create(Comment, :source => article, :author_id => person.id) 53 comment = create(Comment, :source => article, :author_id => person.id)
49 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) } 54 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) }
50 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1) 55 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1)
  56 + process_delayed_job_queue
51 assert_equal [], person.badges 57 assert_equal [], person.badges
52 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) 58 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1)
  59 + process_delayed_job_queue
53 assert_equal 'positive_votes_received', person.reload.badges.first.name 60 assert_equal 'positive_votes_received', person.reload.badges.first.name
54 end 61 end
55 62
@@ -60,18 +67,22 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -60,18 +67,22 @@ class CommentTest &lt; ActiveSupport::TestCase
60 comment = create(Comment, :source => article, :author_id => person.id) 67 comment = create(Comment, :source => article, :author_id => person.id)
61 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1) } 68 4.times { Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1) }
62 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1) 69 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => 1)
  70 + process_delayed_job_queue
63 assert_equal [], person.badges 71 assert_equal [], person.badges
64 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1) 72 Vote.create!(:voter => fast_create(Person), :voteable => comment, :vote => -1)
  73 + process_delayed_job_queue
65 assert_equal 'negative_votes_received', person.reload.badges.first.name 74 assert_equal 'negative_votes_received', person.reload.badges.first.name
66 end 75 end
67 76
68 should 'add merit points to comment owner when an user like his comment' do 77 should 'add merit points to comment owner when an user like his comment' do
69 create_point_rule_definition('vote_voteable_author') 78 create_point_rule_definition('vote_voteable_author')
70 comment = create(Comment, :source => article, :author_id => person.id) 79 comment = create(Comment, :source => article, :author_id => person.id)
  80 + process_delayed_job_queue
71 81
72 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 82 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
73 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do 83 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
74 Vote.create!(:voter => person, :voteable => comment, :vote => 1) 84 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  85 + process_delayed_job_queue
75 end 86 end
76 end 87 end
77 88
@@ -79,20 +90,24 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -79,20 +90,24 @@ class CommentTest &lt; ActiveSupport::TestCase
79 create_point_rule_definition('vote_voteable_author') 90 create_point_rule_definition('vote_voteable_author')
80 comment = create(Comment, :source => article, :author_id => author.id) 91 comment = create(Comment, :source => article, :author_id => author.id)
81 Vote.create!(:voter => person, :voteable => comment, :vote => 1) 92 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  93 + process_delayed_job_queue
82 94
83 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 95 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
84 assert_difference 'comment.author.points', -1*c.weight do 96 assert_difference 'comment.author.points', -1*c.weight do
85 Vote.where(:voteable_id => comment.id).destroy_all 97 Vote.where(:voteable_id => comment.id).destroy_all
  98 + process_delayed_job_queue
86 end 99 end
87 end 100 end
88 101
89 should 'subtract merit points from comment owner when an user dislike his comment' do 102 should 'subtract merit points from comment owner when an user dislike his comment' do
90 create_point_rule_definition('vote_voteable_author') 103 create_point_rule_definition('vote_voteable_author')
91 comment = create(Comment, :source => article, :author_id => person.id) 104 comment = create(Comment, :source => article, :author_id => person.id)
  105 + process_delayed_job_queue
92 106
93 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 107 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
94 assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do 108 assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do
95 Vote.create!(:voter => person, :voteable => comment, :vote => -1) 109 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  110 + process_delayed_job_queue
96 end 111 end
97 end 112 end
98 113
@@ -100,37 +115,44 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -100,37 +115,44 @@ class CommentTest &lt; ActiveSupport::TestCase
100 create_point_rule_definition('vote_voteable_author') 115 create_point_rule_definition('vote_voteable_author')
101 comment = create(Comment, :source => article, :author_id => author.id) 116 comment = create(Comment, :source => article, :author_id => author.id)
102 Vote.create!(:voter => person, :voteable => comment, :vote => -1) 117 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  118 + process_delayed_job_queue
103 119
104 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 120 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
105 assert_difference 'comment.author.points', c.weight do 121 assert_difference 'comment.author.points', c.weight do
106 Vote.where(:voteable_id => comment.id).destroy_all 122 Vote.where(:voteable_id => comment.id).destroy_all
  123 + process_delayed_job_queue
107 end 124 end
108 end 125 end
109 126
110 should 'add merit points to article author when create a new comment' do 127 should 'add merit points to article author when create a new comment' do
111 create_point_rule_definition('comment_article_author') 128 create_point_rule_definition('comment_article_author')
112 - assert_difference 'author.score_points.count' do  
113 - create(Comment, :source => article, :author_id => person.id)  
114 - end 129 + scores = author.score_points.count
  130 + create(Comment, :source => article, :author_id => person.id)
  131 + process_delayed_job_queue
  132 + assert_not_equal author.reload.score_points.count, scores
115 end 133 end
116 134
117 should 'add merit points to voter when he likes a comment' do 135 should 'add merit points to voter when he likes a comment' do
118 create_point_rule_definition('vote_voter') 136 create_point_rule_definition('vote_voter')
119 comment = create(Comment, :source => article, :author_id => person.id) 137 comment = create(Comment, :source => article, :author_id => person.id)
  138 + process_delayed_job_queue
120 139
121 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 140 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
122 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do 141 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
123 Vote.create!(:voter => person, :voteable => comment, :vote => 1) 142 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  143 + process_delayed_job_queue
124 end 144 end
125 end 145 end
126 146
127 should 'add merit points to voter when he dislikes a comment' do 147 should 'add merit points to voter when he dislikes a comment' do
128 create_point_rule_definition('vote_voter') 148 create_point_rule_definition('vote_voter')
129 comment = create(Comment, :source => article, :author_id => person.id) 149 comment = create(Comment, :source => article, :author_id => person.id)
  150 + process_delayed_job_queue
130 151
131 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 152 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
132 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do 153 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
133 Vote.create!(:voter => person, :voteable => comment, :vote => -1) 154 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  155 + process_delayed_job_queue
134 end 156 end
135 end 157 end
136 158
@@ -139,6 +161,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -139,6 +161,7 @@ class CommentTest &lt; ActiveSupport::TestCase
139 c = GamificationPlugin::PointsCategorization.for_type(:comment_article).first 161 c = GamificationPlugin::PointsCategorization.for_type(:comment_article).first
140 assert_difference 'article.points(:category => c.id.to_s)', c.weight do 162 assert_difference 'article.points(:category => c.id.to_s)', c.weight do
141 create(Comment, :source => article, :author_id => person.id) 163 create(Comment, :source => article, :author_id => person.id)
  164 + process_delayed_job_queue
142 end 165 end
143 end 166 end
144 167
@@ -146,10 +169,12 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -146,10 +169,12 @@ class CommentTest &lt; ActiveSupport::TestCase
146 create_point_rule_definition('comment_community') 169 create_point_rule_definition('comment_community')
147 community = fast_create(Community) 170 community = fast_create(Community)
148 article = create(TextileArticle, :profile_id => community.id, :author_id => author.id) 171 article = create(TextileArticle, :profile_id => community.id, :author_id => author.id)
  172 + process_delayed_job_queue
149 173
150 c = GamificationPlugin::PointsCategorization.for_type(:comment_community).first 174 c = GamificationPlugin::PointsCategorization.for_type(:comment_community).first
151 assert_difference 'community.points(:category => c.id.to_s)', c.weight do 175 assert_difference 'community.points(:category => c.id.to_s)', c.weight do
152 create(Comment, :source => article, :author_id => person.id) 176 create(Comment, :source => article, :author_id => person.id)
  177 + process_delayed_job_queue
153 end 178 end
154 end 179 end
155 180
@@ -157,8 +182,10 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -157,8 +182,10 @@ class CommentTest &lt; ActiveSupport::TestCase
157 should 'add merit community points to author when create a new comment in a community' do 182 should 'add merit community points to author when create a new comment in a community' do
158 community = fast_create(Community) 183 community = fast_create(Community)
159 article = create(TextArticle, profile_id: community.id, author_id: person.id) 184 article = create(TextArticle, profile_id: community.id, author_id: person.id)
  185 + process_delayed_job_queue
160 rule = create_point_rule_definition('comment_author', article.profile) 186 rule = create_point_rule_definition('comment_author', article.profile)
161 create(Comment, :source => article, :author_id => person.id) 187 create(Comment, :source => article, :author_id => person.id)
  188 + process_delayed_job_queue
162 assert_equal rule.weight, person.points_by_profile(article.profile.identifier) 189 assert_equal rule.weight, person.points_by_profile(article.profile.identifier)
163 end 190 end
164 191
@@ -167,6 +194,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -167,6 +194,7 @@ class CommentTest &lt; ActiveSupport::TestCase
167 article = create(TextArticle, profile_id: community.id, author_id: fast_create(Person).id) 194 article = create(TextArticle, profile_id: community.id, author_id: fast_create(Person).id)
168 rule = create_point_rule_definition('comment_author', article.profile) 195 rule = create_point_rule_definition('comment_author', article.profile)
169 comment = create(Comment, :source => article, :author_id => person.id) 196 comment = create(Comment, :source => article, :author_id => person.id)
  197 + process_delayed_job_queue
170 assert_equal rule.weight, person.points_by_profile(article.profile.identifier) 198 assert_equal rule.weight, person.points_by_profile(article.profile.identifier)
171 comment.destroy 199 comment.destroy
172 assert_equal 0, person.points_by_profile(article.profile.identifier) 200 assert_equal 0, person.points_by_profile(article.profile.identifier)
@@ -177,10 +205,12 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -177,10 +205,12 @@ class CommentTest &lt; ActiveSupport::TestCase
177 article = create(TextArticle, profile_id: community.id, author_id: person.id) 205 article = create(TextArticle, profile_id: community.id, author_id: person.id)
178 create_point_rule_definition('vote_voteable_author', community) 206 create_point_rule_definition('vote_voteable_author', community)
179 comment = create(Comment, :source => article, :author_id => person.id) 207 comment = create(Comment, :source => article, :author_id => person.id)
  208 + process_delayed_job_queue
180 209
181 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first 210 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first
182 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do 211 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
183 Vote.create!(:voter => person, :voteable => comment, :vote => 1) 212 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  213 + process_delayed_job_queue
184 end 214 end
185 end 215 end
186 216
@@ -190,6 +220,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -190,6 +220,7 @@ class CommentTest &lt; ActiveSupport::TestCase
190 create_point_rule_definition('vote_voteable_author', community) 220 create_point_rule_definition('vote_voteable_author', community)
191 comment = create(Comment, :source => article, :author_id => author.id) 221 comment = create(Comment, :source => article, :author_id => author.id)
192 Vote.create!(:voter => person, :voteable => comment, :vote => 1) 222 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  223 + process_delayed_job_queue
193 224
194 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 225 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
195 assert_difference 'comment.author.points_by_profile(community.identifier)', -1*c.weight do 226 assert_difference 'comment.author.points_by_profile(community.identifier)', -1*c.weight do
@@ -202,10 +233,12 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -202,10 +233,12 @@ class CommentTest &lt; ActiveSupport::TestCase
202 article = create(TextArticle, profile_id: community.id, author_id: person.id) 233 article = create(TextArticle, profile_id: community.id, author_id: person.id)
203 create_point_rule_definition('vote_voteable_author', community) 234 create_point_rule_definition('vote_voteable_author', community)
204 comment = create(Comment, :source => article, :author_id => person.id) 235 comment = create(Comment, :source => article, :author_id => person.id)
  236 + process_delayed_job_queue
205 237
206 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first 238 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).where(profile_id: article.profile.id).first
207 assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do 239 assert_difference 'comment.author.points(:category => c.id.to_s)', -1*c.weight do
208 Vote.create!(:voter => person, :voteable => comment, :vote => -1) 240 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  241 + process_delayed_job_queue
209 end 242 end
210 end 243 end
211 244
@@ -215,6 +248,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -215,6 +248,7 @@ class CommentTest &lt; ActiveSupport::TestCase
215 create_point_rule_definition('vote_voteable_author', community) 248 create_point_rule_definition('vote_voteable_author', community)
216 comment = create(Comment, :source => article, :author_id => author.id) 249 comment = create(Comment, :source => article, :author_id => author.id)
217 Vote.create!(:voter => person, :voteable => comment, :vote => -1) 250 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  251 + process_delayed_job_queue
218 252
219 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first 253 c = GamificationPlugin::PointsCategorization.for_type(:vote_voteable_author).first
220 assert_difference 'comment.author.points_by_profile(community.identifier)', c.weight do 254 assert_difference 'comment.author.points_by_profile(community.identifier)', c.weight do
@@ -225,9 +259,11 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -225,9 +259,11 @@ class CommentTest &lt; ActiveSupport::TestCase
225 should 'add merit community points to article author when create a new comment inside a community' do 259 should 'add merit community points to article author when create a new comment inside a community' do
226 community = fast_create(Community) 260 community = fast_create(Community)
227 article = create(TextArticle, profile_id: community.id, author_id: author.id) 261 article = create(TextArticle, profile_id: community.id, author_id: author.id)
  262 + process_delayed_job_queue
228 rule = create_point_rule_definition('comment_article_author', community) 263 rule = create_point_rule_definition('comment_article_author', community)
229 assert_difference 'author.points_by_profile(community.identifier)', rule.weight do 264 assert_difference 'author.points_by_profile(community.identifier)', rule.weight do
230 create(Comment, :source => article, :author_id => author.id) 265 create(Comment, :source => article, :author_id => author.id)
  266 + process_delayed_job_queue
231 end 267 end
232 end 268 end
233 269
@@ -236,10 +272,12 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -236,10 +272,12 @@ class CommentTest &lt; ActiveSupport::TestCase
236 article = create(TextArticle, profile_id: community.id, author_id: person.id) 272 article = create(TextArticle, profile_id: community.id, author_id: person.id)
237 create_point_rule_definition('vote_voter') 273 create_point_rule_definition('vote_voter')
238 comment = create(Comment, :source => article, :author_id => person.id) 274 comment = create(Comment, :source => article, :author_id => person.id)
  275 + process_delayed_job_queue
239 276
240 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 277 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
241 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do 278 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
242 Vote.create!(:voter => person, :voteable => comment, :vote => 1) 279 Vote.create!(:voter => person, :voteable => comment, :vote => 1)
  280 + process_delayed_job_queue
243 end 281 end
244 end 282 end
245 283
@@ -248,20 +286,24 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -248,20 +286,24 @@ class CommentTest &lt; ActiveSupport::TestCase
248 article = create(TextArticle, profile_id: community.id, author_id: person.id) 286 article = create(TextArticle, profile_id: community.id, author_id: person.id)
249 create_point_rule_definition('vote_voter') 287 create_point_rule_definition('vote_voter')
250 comment = create(Comment, :source => article, :author_id => person.id) 288 comment = create(Comment, :source => article, :author_id => person.id)
  289 + process_delayed_job_queue
251 290
252 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first 291 c = GamificationPlugin::PointsCategorization.for_type(:vote_voter).first
253 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do 292 assert_difference 'comment.author.points(:category => c.id.to_s)', c.weight do
254 Vote.create!(:voter => person, :voteable => comment, :vote => -1) 293 Vote.create!(:voter => person, :voteable => comment, :vote => -1)
  294 + process_delayed_job_queue
255 end 295 end
256 end 296 end
257 297
258 should 'add merit community points to source article when create a comment inside a community' do 298 should 'add merit community points to source article when create a comment inside a community' do
259 community = fast_create(Community) 299 community = fast_create(Community)
260 article = create(TextArticle, profile_id: community.id, author_id: person.id) 300 article = create(TextArticle, profile_id: community.id, author_id: person.id)
  301 + process_delayed_job_queue
261 create_point_rule_definition('comment_article') 302 create_point_rule_definition('comment_article')
262 c = GamificationPlugin::PointsCategorization.for_type(:comment_article).first 303 c = GamificationPlugin::PointsCategorization.for_type(:comment_article).first
263 assert_difference 'article.points(:category => c.id.to_s)', c.weight do 304 assert_difference 'article.points(:category => c.id.to_s)', c.weight do
264 create(Comment, :source => article, :author_id => person.id) 305 create(Comment, :source => article, :author_id => person.id)
  306 + process_delayed_job_queue
265 end 307 end
266 end 308 end
267 309
@@ -269,10 +311,12 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -269,10 +311,12 @@ class CommentTest &lt; ActiveSupport::TestCase
269 create_point_rule_definition('comment_community') 311 create_point_rule_definition('comment_community')
270 community = fast_create(Community) 312 community = fast_create(Community)
271 article = create(TextileArticle, :profile_id => community.id, :author_id => author.id) 313 article = create(TextileArticle, :profile_id => community.id, :author_id => author.id)
  314 + process_delayed_job_queue
272 315
273 c = GamificationPlugin::PointsCategorization.for_type(:comment_community).first 316 c = GamificationPlugin::PointsCategorization.for_type(:comment_community).first
274 assert_difference 'community.points(:category => c.id.to_s)', c.weight do 317 assert_difference 'community.points(:category => c.id.to_s)', c.weight do
275 create(Comment, :source => article, :author_id => person.id) 318 create(Comment, :source => article, :author_id => person.id)
  319 + process_delayed_job_queue
276 end 320 end
277 end 321 end
278 322
@@ -283,6 +327,7 @@ class CommentTest &lt; ActiveSupport::TestCase @@ -283,6 +327,7 @@ class CommentTest &lt; ActiveSupport::TestCase
283 article.profile = organization 327 article.profile = organization
284 328
285 5.times { create(Comment, :source => article, :author_id => person.id) } 329 5.times { create(Comment, :source => article, :author_id => person.id) }
  330 + process_delayed_job_queue
286 assert_equal 'comment_author', person.badges.first.name 331 assert_equal 'comment_author', person.badges.first.name
287 end 332 end
288 333
test/unit/person_test.rb
@@ -13,8 +13,10 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -13,8 +13,10 @@ class PersonTest &lt; ActiveSupport::TestCase
13 GamificationPlugin.gamification_set_rules(environment) 13 GamificationPlugin.gamification_set_rules(environment)
14 14
15 4.times { Vote.create!(:voter => person, :voteable => fast_create(Comment), :vote => 1) } 15 4.times { Vote.create!(:voter => person, :voteable => fast_create(Comment), :vote => 1) }
  16 + process_delayed_job_queue
16 assert_equal [], person.badges 17 assert_equal [], person.badges
17 Vote.create!(:voter => person, :voteable => fast_create(Comment), :vote => 1) 18 Vote.create!(:voter => person, :voteable => fast_create(Comment), :vote => 1)
  19 + process_delayed_job_queue
18 assert_equal 'votes_performed', person.reload.badges.first.name 20 assert_equal 'votes_performed', person.reload.badges.first.name
19 end 21 end
20 22
@@ -23,6 +25,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -23,6 +25,7 @@ class PersonTest &lt; ActiveSupport::TestCase
23 GamificationPlugin.gamification_set_rules(environment) 25 GamificationPlugin.gamification_set_rules(environment)
24 26
25 5.times { |i| person.add_friend(create_user("testuser#{i}").person) } 27 5.times { |i| person.add_friend(create_user("testuser#{i}").person) }
  28 + process_delayed_job_queue
26 assert_equal 'friendly', person.reload.badges.first.name 29 assert_equal 'friendly', person.reload.badges.first.name
27 end 30 end
28 31
@@ -30,6 +33,7 @@ class PersonTest &lt; ActiveSupport::TestCase @@ -30,6 +33,7 @@ class PersonTest &lt; ActiveSupport::TestCase
30 create_point_rule_definition('friends') 33 create_point_rule_definition('friends')
31 other_person = create_user("testuserfriend").person 34 other_person = create_user("testuserfriend").person
32 person.add_friend(other_person) 35 person.add_friend(other_person)
  36 + process_delayed_job_queue
33 c = GamificationPlugin::PointsCategorization.for_type(:friends).first 37 c = GamificationPlugin::PointsCategorization.for_type(:friends).first
34 assert_equal 5, person.score_points(:category => c.id.to_s).sum(:num_points) 38 assert_equal 5, person.score_points(:category => c.id.to_s).sum(:num_points)
35 end 39 end
test/unit/point_rules_test.rb
@@ -23,6 +23,7 @@ class PointRulesTest &lt; ActiveSupport::TestCase @@ -23,6 +23,7 @@ class PointRulesTest &lt; ActiveSupport::TestCase
23 person = create_user('testuser').person 23 person = create_user('testuser').person
24 create_point_rule_definition('article_author') 24 create_point_rule_definition('article_author')
25 article = create(TextArticle, :profile_id => person.id, :author => person) 25 article = create(TextArticle, :profile_id => person.id, :author => person)
  26 + process_delayed_job_queue
26 url = Merit::PointRules.target_url(person.score_points.last) 27 url = Merit::PointRules.target_url(person.score_points.last)
27 assert_equal article.url, url 28 assert_equal article.url, url
28 end 29 end
@@ -32,6 +33,7 @@ class PointRulesTest &lt; ActiveSupport::TestCase @@ -32,6 +33,7 @@ class PointRulesTest &lt; ActiveSupport::TestCase
32 create_point_rule_definition('comment_author') 33 create_point_rule_definition('comment_author')
33 article = create(Article, :profile_id => person.id, :author => person) 34 article = create(Article, :profile_id => person.id, :author => person)
34 comment = create(Comment, :source_id => article.id, :author => person) 35 comment = create(Comment, :source_id => article.id, :author => person)
  36 + process_delayed_job_queue
35 url = Merit::PointRules.target_url(person.score_points.last) 37 url = Merit::PointRules.target_url(person.score_points.last)
36 assert_equal comment.url, url 38 assert_equal comment.url, url
37 end 39 end
test/unit/profile_test.rb
@@ -50,6 +50,7 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -50,6 +50,7 @@ class ProfileTest &lt; ActiveSupport::TestCase
50 Person.any_instance.stubs(:is_profile_complete?).returns(true) 50 Person.any_instance.stubs(:is_profile_complete?).returns(true)
51 create_point_rule_definition('profile_completion', nil, {value: 0}) 51 create_point_rule_definition('profile_completion', nil, {value: 0})
52 GamificationPlugin.gamification_set_rules(environment) 52 GamificationPlugin.gamification_set_rules(environment)
  53 + process_delayed_job_queue
53 assert_equal 0, person.level 54 assert_equal 0, person.level
54 assert_nothing_raised do 55 assert_nothing_raised do
55 person.save 56 person.save
@@ -62,8 +63,10 @@ class ProfileTest &lt; ActiveSupport::TestCase @@ -62,8 +63,10 @@ class ProfileTest &lt; ActiveSupport::TestCase
62 GamificationPlugin.gamification_set_rules(environment) 63 GamificationPlugin.gamification_set_rules(environment)
63 64
64 person = create_user('testuser').person 65 person = create_user('testuser').person
  66 + process_delayed_job_queue
65 assert_equal 0, person.level 67 assert_equal 0, person.level
66 create(TextArticle, :profile_id => community.id, :author => person) 68 create(TextArticle, :profile_id => community.id, :author => person)
  69 + process_delayed_job_queue
67 assert_equal 3, person.reload.level 70 assert_equal 3, person.reload.level
68 end 71 end
69 72