merit 4.0.1 → 4.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +8 -0
- data/README.md +15 -8
- data/lib/merit.rb +13 -23
- data/lib/merit/generators/active_record/templates/create_merit_actions.erb +2 -0
- data/lib/merit/generators/templates/merit.erb +12 -10
- data/lib/merit/judge.rb +6 -5
- data/merit.gemspec +1 -1
- data/test/dummy/db/migrate/20130329224406_create_merit_actions.rb +2 -0
- data/test/dummy/db/schema.rb +1 -0
- data/test/integration/navigation_test.rb +1 -1
- data/test/unit/sash_test.rb +16 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80cd3f1c6e1d7bac792d556e3b5145c82f0e3db9bd5b07eb6487c2de7f029613
|
4
|
+
data.tar.gz: ba6e5ee3691603cf88f3871b23bd875bb755fe2206c24f790d3ce427f6c2430f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 639a9e1f07a6c5505a41ee412fb4d8de43184c125ca254b941501863b92ebc15c9495f1714d4edba4f286166e895c4962b62ed249a546eddc9b1201b8154dfdb
|
7
|
+
data.tar.gz: ba40fb0d27815c0f1e523cf445eef9b44f5fa06682562e067405216bb4b56c748af0574baaa7e9d4b5d3ec935dd2f7002bb03fa0655eb6d73805acc568079097
|
data/NEWS.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
User-visible changes worth mentioning.
|
4
4
|
|
5
|
+
## 4.0.2
|
6
|
+
|
7
|
+
- [#355, #356] Add index on merit_actions.processed column
|
8
|
+
- [#354] Fix Rails autoloader deprecation warnings
|
9
|
+
Requires wrapping `Merit::Badge.create` with `Rails.application.reloader.to_prepare`
|
10
|
+
- Test with Ruby 3 and Rails 6.1 (excludes Rails 5.2 with Ruby 3, that errors out)
|
11
|
+
- [#288] Don’t send “removed badge” notifications when user doesn’t have the badge
|
12
|
+
|
5
13
|
## 4.0.1
|
6
14
|
|
7
15
|
- [#351] Fix bug on generating migrations
|
data/README.md
CHANGED
@@ -58,12 +58,16 @@ Create badges in `config/initializers/merit.rb`
|
|
58
58
|
### Example
|
59
59
|
|
60
60
|
```ruby
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
# config/initializers/merit.rb
|
62
|
+
|
63
|
+
Rails.application.reloader.to_prepare do
|
64
|
+
Merit::Badge.create!(
|
65
|
+
id: 1,
|
66
|
+
name: "year-member",
|
67
|
+
description: "Active member for a year",
|
68
|
+
custom_fields: { difficulty: :silver }
|
69
|
+
)
|
70
|
+
end
|
67
71
|
```
|
68
72
|
|
69
73
|
## Defining Rules
|
@@ -305,8 +309,8 @@ warning, with a comment to check the configuration for the rule.
|
|
305
309
|
|
306
310
|
# Getting Notifications
|
307
311
|
|
308
|
-
You can get observers notified any time merit changes reputation
|
309
|
-
application.
|
312
|
+
You can get observers notified any time merit automatically changes reputation
|
313
|
+
in your application.
|
310
314
|
|
311
315
|
It needs to implement the `update` method, which receives as parameter the
|
312
316
|
following hash:
|
@@ -337,6 +341,9 @@ end
|
|
337
341
|
config.add_observer 'ReputationChangeObserver'
|
338
342
|
```
|
339
343
|
|
344
|
+
**NOTE:** Observers won’t get notified if you grant reputation with
|
345
|
+
direct calls to `add_badge` or `add_point`.
|
346
|
+
|
340
347
|
# I18n
|
341
348
|
|
342
349
|
Merit uses default messages with I18n for notify alerts. To customize your app, you can set up your locale file:
|
data/lib/merit.rb
CHANGED
@@ -61,32 +61,22 @@ module Merit
|
|
61
61
|
config.app_generators.orm Merit.orm
|
62
62
|
|
63
63
|
initializer 'merit.controller' do |app|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
e
|
64
|
+
config.to_prepare do
|
65
|
+
ActiveSupport.on_load(:active_record) { include Merit }
|
66
|
+
ActiveSupport.on_load(app.config.api_only ? :action_controller_api : :action_controller_base) do
|
67
|
+
begin
|
68
|
+
# Load app rules on boot up
|
69
|
+
Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
|
70
|
+
Merit::AppPointRules = Merit::PointRules.new.defined_rules
|
71
|
+
include Merit::ControllerExtensions
|
72
|
+
rescue NameError => e
|
73
|
+
# Trap NameError if installing/generating files
|
74
|
+
raise e unless
|
75
|
+
e.to_s =~ /uninitialized constant Merit::(BadgeRules|PointRules)/
|
76
|
+
end
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|
78
|
-
|
79
|
-
def extend_orm_with_has_merit
|
80
|
-
ActiveRecord::Base.include(Merit)
|
81
|
-
end
|
82
|
-
|
83
|
-
def action_controller_hook
|
84
|
-
if Rails.application.config.api_only
|
85
|
-
:action_controller_api
|
86
|
-
else
|
87
|
-
:action_controller_base
|
88
|
-
end
|
89
|
-
end
|
90
80
|
end
|
91
81
|
end
|
92
82
|
|
@@ -17,14 +17,16 @@ Merit.setup do |config|
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# Create application badges (uses https://github.com/norman/ambry)
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
20
|
+
# Rails.application.reloader.to_prepare do
|
21
|
+
# badge_id = 0
|
22
|
+
# [{
|
23
|
+
# id: (badge_id = badge_id+1),
|
24
|
+
# name: 'just-registered'
|
25
|
+
# }, {
|
26
|
+
# id: (badge_id = badge_id+1),
|
27
|
+
# name: 'best-unicorn',
|
28
|
+
# custom_fields: { category: 'fantasy' }
|
29
|
+
# }].each do |attrs|
|
30
|
+
# Merit::Badge.create! attrs
|
31
|
+
# end
|
30
32
|
# end
|
data/lib/merit/judge.rb
CHANGED
@@ -50,11 +50,12 @@ module Merit
|
|
50
50
|
|
51
51
|
def remove_badges
|
52
52
|
sashes.each do |sash|
|
53
|
-
sash.rm_badge badge.id
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
53
|
+
if sash.rm_badge badge.id
|
54
|
+
notify_observers(
|
55
|
+
description: I18n.t("merit.removed_badge", badge_name: badge.name),
|
56
|
+
sash_id: sash.id
|
57
|
+
)
|
58
|
+
end
|
58
59
|
end
|
59
60
|
end
|
60
61
|
|
data/merit.gemspec
CHANGED
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
6
6
|
s.files = `git ls-files`.split("\n").reject{|f| f =~ /^\./ }
|
7
7
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
8
8
|
s.license = 'MIT'
|
9
|
-
s.version = '4.0.
|
9
|
+
s.version = '4.0.2'
|
10
10
|
s.authors = ["Tute Costa"]
|
11
11
|
s.email = 'tutecosta@gmail.com'
|
12
12
|
|
data/test/dummy/db/schema.rb
CHANGED
@@ -49,6 +49,7 @@ ActiveRecord::Schema.define(version: 2014_08_19_133931) do
|
|
49
49
|
t.datetime "created_at", null: false
|
50
50
|
t.datetime "updated_at", null: false
|
51
51
|
t.text "target_data"
|
52
|
+
t.index ["processed"], name: "index_merit_actions_on_processed"
|
52
53
|
end
|
53
54
|
|
54
55
|
create_table "merit_activity_logs", force: :cascade do |t|
|
@@ -180,7 +180,7 @@ class NavigationTest < ActionDispatch::IntegrationTest
|
|
180
180
|
|
181
181
|
visit "/users/#{user.id}/edit"
|
182
182
|
fill_in 'Name', with: 'a'
|
183
|
-
assert_difference('Merit::ActivityLog.count',
|
183
|
+
assert_difference('Merit::ActivityLog.count', 1) do
|
184
184
|
click_button('Update User')
|
185
185
|
end
|
186
186
|
|
data/test/unit/sash_test.rb
CHANGED
@@ -6,6 +6,22 @@ class SashTest < ActiveSupport::TestCase
|
|
6
6
|
@sash = Merit::Sash.create
|
7
7
|
end
|
8
8
|
|
9
|
+
describe "#rm_badge" do
|
10
|
+
describe "when has badge" do
|
11
|
+
it "returns truthy" do
|
12
|
+
@sash.badges_sashes.create!(badge_id: 1)
|
13
|
+
|
14
|
+
assert_equal !!@sash.rm_badge(1), true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "when does NOT have badge" do
|
19
|
+
it "returns falsey" do
|
20
|
+
assert_equal !!@sash.rm_badge(0), false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
9
25
|
describe "#add_points" do
|
10
26
|
describe "when category specified" do
|
11
27
|
it "should create a new Point with specified category" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: merit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tute Costa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ambry
|
@@ -280,7 +280,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
280
|
- !ruby/object:Gem::Version
|
281
281
|
version: '0'
|
282
282
|
requirements: []
|
283
|
-
rubygems_version: 3.
|
283
|
+
rubygems_version: 3.1.6
|
284
284
|
signing_key:
|
285
285
|
specification_version: 4
|
286
286
|
summary: Reputation engine for Rails apps
|