merit 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +13 -1
- data/README.md +10 -10
- data/UPGRADING.md +14 -0
- data/app/models/merit/action.rb +9 -10
- data/app/models/merit/badge.rb +9 -6
- data/lib/generators/merit/templates/merit.rb +6 -2
- data/lib/merit.rb +3 -2
- data/lib/merit/controller_extensions.rb +10 -9
- data/lib/merit/judge.rb +9 -15
- data/lib/merit/model_additions.rb +6 -6
- data/lib/merit/models/active_record/merit/action.rb +4 -2
- data/lib/merit/models/active_record/merit/activity_log.rb +3 -1
- data/lib/merit/models/active_record/merit/badges_sash.rb +6 -2
- data/lib/merit/models/active_record/merit/sash.rb +8 -8
- data/lib/merit/models/active_record/merit/score.rb +7 -3
- data/lib/merit/models/mongo_mapper/merit/action.rb +1 -1
- data/lib/merit/models/mongo_mapper/sash.rb +1 -0
- data/lib/merit/models/mongoid/merit/action.rb +4 -4
- data/lib/merit/models/mongoid/sash.rb +1 -1
- data/lib/merit/observer.rb +13 -0
- data/lib/merit/rule.rb +1 -1
- data/lib/merit/rules_badge_methods.rb +2 -2
- data/lib/merit/rules_matcher.rb +24 -0
- data/lib/merit/rules_rank_methods.rb +12 -8
- data/lib/merit/target_finder.rb +12 -9
- data/merit.gemspec +2 -5
- data/test/dummy/app/controllers/api/users_controller.rb +5 -0
- data/test/dummy/app/controllers/comments_controller.rb +15 -49
- data/test/dummy/app/controllers/registrations_controller.rb +7 -1
- data/test/dummy/app/controllers/users_controller.rb +11 -40
- data/test/dummy/app/models/comment.rb +3 -1
- data/test/dummy/app/models/merit/badge_rules.rb +11 -8
- data/test/dummy/app/models/merit/point_rules.rb +4 -4
- data/test/dummy/app/models/merit/rank_rules.rb +1 -1
- data/test/dummy/app/models/user.rb +3 -1
- data/test/dummy/app/views/admin/users/index.html.erb +1 -1
- data/test/dummy/app/views/comments/index.html.erb +1 -1
- data/test/dummy/app/views/users/index.html.erb +1 -1
- data/test/dummy/config/application.rb +1 -1
- data/test/dummy/config/environments/development.rb +2 -3
- data/test/dummy/config/environments/production.rb +2 -0
- data/test/dummy/config/environments/test.rb +2 -3
- data/test/dummy/config/initializers/merit.rb +27 -24
- data/test/dummy/config/initializers/secret_token.rb +6 -1
- data/test/dummy/config/routes.rb +5 -2
- data/test/integration/navigation_test.rb +67 -55
- data/test/test_helper.rb +5 -20
- data/test/{base_target_finder_test.rb → unit/base_target_finder_test.rb} +1 -1
- data/test/{merit_unit_test.rb → unit/merit_unit_test.rb} +14 -32
- data/test/unit/rule_unit_test.rb +44 -0
- data/test/{sash_finder_test.rb → unit/sash_finder_test.rb} +1 -1
- data/test/{target_finder_test.rb → unit/target_finder_test.rb} +5 -5
- metadata +12 -41
- data/Gemfile.lock +0 -146
@@ -8,15 +8,15 @@ module Merit
|
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
# Thanks for voting point
|
11
|
-
score 1, :
|
11
|
+
score 1, on: 'comments#vote'
|
12
12
|
|
13
13
|
# All user's comments earn points
|
14
|
-
score 2, :
|
14
|
+
score 2, to: :user_comments, on: 'comments#vote'
|
15
15
|
|
16
16
|
# Points to voted user
|
17
|
-
score 5, :
|
17
|
+
score 5, to: :user, on: 'comments#vote'
|
18
18
|
|
19
|
-
score 20, :
|
19
|
+
score 20, on: [
|
20
20
|
'comments#create',
|
21
21
|
'registrations#update'
|
22
22
|
] do |object|
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<td><%= user.points %></td>
|
17
17
|
<td><%= link_to 'Show', user %>
|
18
18
|
- <%= link_to 'Edit', edit_user_path(user) %>
|
19
|
-
- <%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
|
19
|
+
- <%= link_to 'Destroy', user, data: { :confirm => 'Are you sure?' }, :method => :delete %></td>
|
20
20
|
</tr>
|
21
21
|
<% end %>
|
22
22
|
</table>
|
@@ -25,7 +25,7 @@
|
|
25
25
|
</td>
|
26
26
|
<td><%= link_to 'Show', comment %></td>
|
27
27
|
<td><%= link_to 'Edit', edit_comment_path(comment) %></td>
|
28
|
-
<td><%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete %></td>
|
28
|
+
<td><%= link_to 'Destroy', comment, data: { :confirm => 'Are you sure?' }, :method => :delete %></td>
|
29
29
|
</tr>
|
30
30
|
<% end %>
|
31
31
|
</table>
|
@@ -16,7 +16,7 @@
|
|
16
16
|
<td><%= user.points %></td>
|
17
17
|
<td><%= link_to 'Show', user %>
|
18
18
|
- <%= link_to 'Edit', edit_user_path(user) %>
|
19
|
-
- <%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
|
19
|
+
- <%= link_to 'Destroy', user, data: { :confirm => 'Are you sure?' }, :method => :delete %></td>
|
20
20
|
</tr>
|
21
21
|
<% end %>
|
22
22
|
</table>
|
@@ -14,7 +14,7 @@ module Dummy
|
|
14
14
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
15
15
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
16
16
|
# config.i18n.default_locale = :de
|
17
|
-
config.active_record.whitelist_attributes = true
|
17
|
+
# config.active_record.whitelist_attributes = true
|
18
18
|
|
19
19
|
# Configure the default encoding used in templates for Ruby 1.9.
|
20
20
|
config.encoding = "utf-8"
|
@@ -6,9 +6,6 @@ Dummy::Application.configure do
|
|
6
6
|
# since you don't have to restart the webserver when you make code changes.
|
7
7
|
config.cache_classes = false
|
8
8
|
|
9
|
-
# Log error messages when you accidentally call methods on nil.
|
10
|
-
config.whiny_nils = true
|
11
|
-
|
12
9
|
# Show full error reports and disable caching
|
13
10
|
config.consider_all_requests_local = true
|
14
11
|
config.action_controller.perform_caching = false
|
@@ -21,5 +18,7 @@ Dummy::Application.configure do
|
|
21
18
|
|
22
19
|
# Only use best-standards-support built into browsers
|
23
20
|
config.action_dispatch.best_standards_support = :builtin
|
21
|
+
|
22
|
+
config.eager_load = false
|
24
23
|
end
|
25
24
|
|
@@ -7,9 +7,6 @@ Dummy::Application.configure do
|
|
7
7
|
# and recreated between test runs. Don't rely on the data there!
|
8
8
|
config.cache_classes = true
|
9
9
|
|
10
|
-
# Log error messages when you accidentally call methods on nil.
|
11
|
-
config.whiny_nils = true
|
12
|
-
|
13
10
|
# Show full error reports and disable caching
|
14
11
|
config.consider_all_requests_local = true
|
15
12
|
config.action_controller.perform_caching = false
|
@@ -32,4 +29,6 @@ Dummy::Application.configure do
|
|
32
29
|
|
33
30
|
# Print deprecation notices to the stderr
|
34
31
|
config.active_support.deprecation = :stderr
|
32
|
+
|
33
|
+
config.eager_load = false
|
35
34
|
end
|
@@ -3,43 +3,46 @@ Merit.setup do |config|
|
|
3
3
|
# Check rules on each request or in background
|
4
4
|
# config.checks_on_each_request = true
|
5
5
|
|
6
|
-
# Define ORM. Could be
|
6
|
+
# Define ORM. Could be:active_record (default), :mongo_mapper and :mongoid
|
7
7
|
# config.orm = :active_record
|
8
8
|
end
|
9
9
|
|
10
10
|
# Create application badges (uses https://github.com/norman/ambry)
|
11
11
|
badge_id = 0
|
12
12
|
[{
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
13
|
+
id: (badge_id = badge_id+1),
|
14
|
+
name: 'commenter',
|
15
|
+
description: 'You\'ve participated good in our boards! (level 10)',
|
16
|
+
level: 10
|
17
17
|
}, {
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
18
|
+
id: (badge_id = badge_id+1),
|
19
|
+
name: 'commenter',
|
20
|
+
description: 'You\'ve participated great in our boards!'
|
21
21
|
}, {
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
22
|
+
id: (badge_id = badge_id+1),
|
23
|
+
name: 'visited_admin',
|
24
|
+
description: 'You sneaked in!'
|
25
25
|
}, {
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
26
|
+
id: (badge_id = badge_id+1),
|
27
|
+
name: 'has_commenter_friend',
|
28
|
+
description: 'Testing badge granting in more than one rule per action, with different targets'
|
29
29
|
}, {
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
30
|
+
id: (badge_id = badge_id+1),
|
31
|
+
name: 'relevant-commenter',
|
32
|
+
description: 'You\'ve received 5 votes on a comment.'
|
33
33
|
}, {
|
34
|
-
:
|
35
|
-
:
|
36
|
-
:
|
34
|
+
id: (badge_id = badge_id+1),
|
35
|
+
name: 'autobiographer',
|
36
|
+
description: 'You\'ve edited your name and it\'s above 4 characters! (?)'
|
37
37
|
}, {
|
38
|
-
:
|
39
|
-
:
|
38
|
+
id: (badge_id = badge_id+1),
|
39
|
+
name: 'just-registered'
|
40
40
|
}, {
|
41
|
-
:
|
42
|
-
:
|
41
|
+
id: (badge_id = badge_id+1),
|
42
|
+
name: 'wildcard_badge'
|
43
|
+
}, {
|
44
|
+
id: (badge_id = badge_id+1),
|
45
|
+
name: 'gossip'
|
43
46
|
}].each do |badge|
|
44
47
|
Merit::Badge.create! badge
|
45
48
|
end
|
@@ -4,4 +4,9 @@
|
|
4
4
|
# If you change this key, all old signed cookies will become invalid!
|
5
5
|
# Make sure the secret is at least 30 characters and all random,
|
6
6
|
# no regular words or you'll be exposed to dictionary attacks.
|
7
|
-
|
7
|
+
|
8
|
+
if Rails.version < '4'
|
9
|
+
Dummy::Application.config.secret_token = 'f00fe8e4404331c84a9f1d877217c57399e0429ed948843f5d0b5db642cb2ab2c1dc28a17ef7daeecf64b1a4f2b61f7ae4886ab993fb0d7cf65d7b64ba5fbcb1'
|
10
|
+
else
|
11
|
+
Dummy::Application.config.secret_key_base = 'f00fe8e4404331c84a9f1d877217c57399e0429ed948843f5d0b5db642cb2ab2c1dc28a17ef7daeecf64b1a4f2b61f7ae4886ab993fb0d7cf65d7b64ba5fbcb1'
|
12
|
+
end
|
data/test/dummy/config/routes.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
Dummy::Application.routes.draw do
|
2
2
|
namespace :admin do
|
3
|
-
|
3
|
+
get '/users' => 'users#index'
|
4
|
+
end
|
5
|
+
namespace :api do
|
6
|
+
get '/users' => 'users#index'
|
4
7
|
end
|
5
8
|
resources :users, :except => :update
|
6
9
|
resources :registrations, :only => :update, :as => :registrations_user
|
7
10
|
resources :comments
|
8
11
|
|
9
|
-
|
12
|
+
get '/comments/:id/vote/:value' => 'comments#vote', :id => /\d+/, :value => /\d+/
|
10
13
|
|
11
14
|
root :to => 'users#index'
|
12
15
|
end
|
@@ -3,17 +3,17 @@ require 'test_helper'
|
|
3
3
|
class NavigationTest < ActiveSupport::IntegrationCase
|
4
4
|
test 'user sign up should grant badge to itself' do
|
5
5
|
visit '/users/new'
|
6
|
-
fill_in 'Name', :
|
6
|
+
fill_in 'Name', with: 'Jack'
|
7
7
|
assert_difference('Merit::ActivityLog.count') do
|
8
8
|
click_button('Create User')
|
9
9
|
end
|
10
10
|
|
11
|
-
user = User.where(:
|
11
|
+
user = User.where(name: 'Jack').first
|
12
12
|
assert_equal [Merit::Badge.by_name('just-registered').first], user.badges
|
13
13
|
end
|
14
14
|
|
15
15
|
test 'User#add_badge should add one badge, #rm_badge should delete one' do
|
16
|
-
user = User.create(:
|
16
|
+
user = User.create(name: 'test-user')
|
17
17
|
assert_equal [], user.badges
|
18
18
|
|
19
19
|
badge = Merit::Badge.first
|
@@ -27,40 +27,48 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
27
27
|
end
|
28
28
|
|
29
29
|
test 'Remove inexistent badge should do nothing' do
|
30
|
-
user = User.create(:
|
30
|
+
user = User.create(name: 'test-user')
|
31
31
|
assert_equal [], user.badges
|
32
32
|
user.rm_badge 1
|
33
33
|
assert_equal [], user.badges
|
34
34
|
end
|
35
35
|
|
36
36
|
test 'users#index should grant badge multiple times' do
|
37
|
-
user = User.create(:
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
user = User.create(name: 'test-user')
|
38
|
+
|
39
|
+
# Multiple rule
|
40
|
+
assert_difference 'badges_by_name(user, "gossip").count', 3 do
|
41
|
+
3.times { visit '/users' }
|
42
|
+
end
|
43
|
+
|
44
|
+
# Namespaced controller
|
45
|
+
assert_no_difference 'badges_by_name(user, "visited_admin").count' do
|
46
|
+
visit '/users'
|
47
|
+
end
|
48
|
+
assert_difference 'badges_by_name(user, "visited_admin").count' do
|
49
|
+
visit '/admin/users'
|
50
|
+
end
|
51
|
+
|
52
|
+
# Wildcard controllers
|
53
|
+
assert_difference 'badges_by_name(user, "wildcard_badge").count', 3 do
|
54
|
+
visit '/admin/users'
|
55
|
+
visit '/api/users'
|
56
|
+
visit '/users'
|
57
|
+
end
|
50
58
|
end
|
51
59
|
|
52
60
|
test 'user workflow should grant some badges at some times' do
|
53
61
|
# Commented 9 times, no badges yet
|
54
|
-
user = User.create(:
|
62
|
+
user = User.create(name: 'test-user')
|
55
63
|
# Create needed friend user object
|
56
|
-
friend = User.create(:
|
64
|
+
friend = User.create(name: 'friend')
|
57
65
|
|
58
66
|
(1..9).each do |i|
|
59
67
|
Comment.create(
|
60
|
-
:
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
68
|
+
name: "Title #{i}",
|
69
|
+
comment: "Comment #{i}",
|
70
|
+
user_id: user.id,
|
71
|
+
votes: 8
|
64
72
|
)
|
65
73
|
end
|
66
74
|
assert user.badges.empty?, 'Should not have badges'
|
@@ -75,9 +83,9 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
75
83
|
|
76
84
|
# Make tenth comment, assert 10-commenter badge granted
|
77
85
|
visit '/comments/new'
|
78
|
-
fill_in 'Name', :
|
79
|
-
fill_in 'Comment', :
|
80
|
-
fill_in 'User', :
|
86
|
+
fill_in 'Name', with: 'Hi!'
|
87
|
+
fill_in 'Comment', with: 'Hi bro!'
|
88
|
+
fill_in 'User', with: user.id
|
81
89
|
assert_difference('Merit::ActivityLog.count', 2) do
|
82
90
|
click_button('Create Comment')
|
83
91
|
end
|
@@ -86,79 +94,79 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
86
94
|
assert_equal [Merit::Badge.by_name('has_commenter_friend').first], friend.reload.badges
|
87
95
|
|
88
96
|
# Vote (to 5) a user's comment, assert relevant-commenter badge granted
|
89
|
-
relevant_comment = user.comments.where(:
|
97
|
+
relevant_comment = user.comments.where(votes: 8).first
|
90
98
|
visit '/comments'
|
91
99
|
within("tr#c_#{relevant_comment.id}") do
|
92
100
|
click_link '2'
|
93
101
|
end
|
94
102
|
|
95
103
|
relevant_badge = Merit::Badge.by_name('relevant-commenter').first
|
96
|
-
user_badges = User.where(:
|
104
|
+
user_badges = User.where(name: 'test-user').first.badges
|
97
105
|
assert user_badges.include?(relevant_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain relevant-commenter badge."
|
98
106
|
|
99
107
|
# Edit user's name by long name
|
100
108
|
# tests ruby code in grant_on is being executed, and gives badge
|
101
|
-
user = User.where(:
|
109
|
+
user = User.where(name: 'test-user').first
|
102
110
|
user_badges = user.badges
|
103
111
|
|
104
112
|
visit "/users/#{user.id}/edit"
|
105
|
-
fill_in 'Name', :
|
113
|
+
fill_in 'Name', with: 'long_name!'
|
106
114
|
click_button('Update User')
|
107
115
|
|
108
|
-
user = User.where(:
|
116
|
+
user = User.where(name: 'long_name!').first
|
109
117
|
autobiographer_badge = Merit::Badge.by_name('autobiographer').first
|
110
118
|
assert user.badges.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should contain autobiographer badge."
|
111
119
|
|
112
120
|
# Edit user's name by short name
|
113
121
|
# tests ruby code in grant_on is being executed, and removes badge
|
114
122
|
visit "/users/#{user.id}/edit"
|
115
|
-
fill_in 'Name', :
|
123
|
+
fill_in 'Name', with: 'abc'
|
116
124
|
assert_difference('Merit::ActivityLog.count', 2) do
|
117
125
|
click_button('Update User')
|
118
126
|
end
|
119
127
|
# Last one is point granting, previous one is badge removing
|
120
128
|
assert_equal 'removed', Merit::ActivityLog.all[-2].description
|
121
129
|
|
122
|
-
user = User.where(:
|
130
|
+
user = User.where(name: 'abc').first
|
123
131
|
assert !user.badges.include?(autobiographer_badge), "User badges: #{user.badges.collect(&:name).inspect} should remove autobiographer badge."
|
124
132
|
end
|
125
133
|
|
126
134
|
test 'user workflow should add up points at some times' do
|
127
135
|
User.delete_all
|
128
|
-
user = User.create(:
|
136
|
+
user = User.create(name: 'test-user')
|
129
137
|
assert_equal 0, user.points, 'User should start with 0 points'
|
130
138
|
|
131
139
|
visit "/users/#{user.id}/edit"
|
132
|
-
fill_in 'Name', :
|
140
|
+
fill_in 'Name', with: 'a'
|
133
141
|
assert_difference('Merit::ActivityLog.count', 2) do
|
134
142
|
click_button('Update User')
|
135
143
|
end
|
136
144
|
|
137
|
-
user = User.where(:
|
145
|
+
user = User.where(name: 'a').first
|
138
146
|
assert_equal 20, user.points, 'Updating info should grant 20 points'
|
139
147
|
|
140
148
|
visit '/comments/new'
|
141
149
|
click_button('Create Comment')
|
142
150
|
|
143
|
-
user = User.where(:
|
151
|
+
user = User.where(name: 'a').first
|
144
152
|
assert_equal 20, user.points, 'Empty comment should grant no points'
|
145
153
|
|
146
154
|
visit '/comments/new'
|
147
|
-
fill_in 'Name', :
|
148
|
-
fill_in 'Comment', :
|
149
|
-
fill_in 'User', :
|
155
|
+
fill_in 'Name', with: 'Hi!'
|
156
|
+
fill_in 'Comment', with: 'Hi bro!'
|
157
|
+
fill_in 'User', with: user.id
|
150
158
|
click_button('Create Comment')
|
151
159
|
|
152
|
-
user = User.where(:
|
160
|
+
user = User.where(name: 'a').first
|
153
161
|
assert_equal 20, user.points, 'Commenting should not grant 20 points if name.length <= 4'
|
154
162
|
|
155
163
|
visit '/comments/new'
|
156
|
-
fill_in 'Name', :
|
157
|
-
fill_in 'Comment', :
|
158
|
-
fill_in 'User', :
|
164
|
+
fill_in 'Name', with: 'Hi there!'
|
165
|
+
fill_in 'Comment', with: 'Hi bro!'
|
166
|
+
fill_in 'User', with: user.id
|
159
167
|
click_button('Create Comment')
|
160
168
|
|
161
|
-
user = User.where(:
|
169
|
+
user = User.where(name: 'a').first
|
162
170
|
assert_equal 40, user.points, 'Commenting should grant 20 points if name.length > 4'
|
163
171
|
|
164
172
|
visit "/comments/#{Comment.last.id}/vote/4"
|
@@ -167,15 +175,15 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
167
175
|
end
|
168
176
|
|
169
177
|
test 'user workflow should grant levels at some times' do
|
170
|
-
user = User.create(:
|
178
|
+
user = User.create(name: 'test-user')
|
171
179
|
assert user.badges.empty?
|
172
180
|
|
173
181
|
# Edit user's name by 2 chars name
|
174
182
|
visit "/users/#{user.id}/edit"
|
175
|
-
fill_in 'Name', :
|
183
|
+
fill_in 'Name', with: 'ab'
|
176
184
|
click_button('Update User')
|
177
185
|
|
178
|
-
user = User.where(:
|
186
|
+
user = User.where(name: 'ab').first
|
179
187
|
assert_equal 0, user.level, "User level should be 0."
|
180
188
|
Merit::RankRules.new.check_rank_rules
|
181
189
|
user.reload
|
@@ -183,29 +191,29 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
183
191
|
|
184
192
|
# Edit user's name by short name. Doesn't go back to previous rank.
|
185
193
|
visit "/users/#{user.id}/edit"
|
186
|
-
fill_in 'Name', :
|
194
|
+
fill_in 'Name', with: 'a'
|
187
195
|
click_button('Update User')
|
188
196
|
|
189
|
-
user = User.where(:
|
197
|
+
user = User.where(name: 'a').first
|
190
198
|
Merit::RankRules.new.check_rank_rules
|
191
199
|
user.reload
|
192
200
|
assert_equal 2, user.level, "User level should be 2."
|
193
201
|
|
194
202
|
# Edit user's name by 5 chars name
|
195
203
|
visit "/users/#{user.id}/edit"
|
196
|
-
fill_in 'Name', :
|
204
|
+
fill_in 'Name', with: 'abcde'
|
197
205
|
click_button('Update User')
|
198
206
|
|
199
|
-
user = User.where(:
|
207
|
+
user = User.where(name: 'abcde').first
|
200
208
|
Merit::RankRules.new.check_rank_rules
|
201
209
|
user.reload
|
202
210
|
assert_equal 5, user.level, "User level should be 5."
|
203
211
|
end
|
204
212
|
|
205
213
|
test 'assigning points to a group of records' do
|
206
|
-
commenter = User.create(:
|
207
|
-
comment_1 = commenter.comments.create(:
|
208
|
-
comment_2 = commenter.comments.create(:
|
214
|
+
commenter = User.create(name: 'commenter')
|
215
|
+
comment_1 = commenter.comments.create(name: 'comment_1', comment: 'a')
|
216
|
+
comment_2 = commenter.comments.create(name: 'comment_2', comment: 'b')
|
209
217
|
|
210
218
|
visit comments_path
|
211
219
|
# Thanks for voting point, to voted user and it's comments
|
@@ -218,4 +226,8 @@ class NavigationTest < ActiveSupport::IntegrationCase
|
|
218
226
|
comment_1.reload.points.must_be :==, 2
|
219
227
|
comment_2.reload.points.must_be :==, 2
|
220
228
|
end
|
229
|
+
|
230
|
+
def badges_by_name(user, name)
|
231
|
+
user.reload.badges.select{|b| b.name == name }
|
232
|
+
end
|
221
233
|
end
|