merit 4.0.0 → 4.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/NEWS.md +18 -0
- data/README.md +15 -8
- data/lib/merit/generators/active_record/merit_generator.rb +1 -1
- data/lib/merit/generators/active_record/templates/create_merit_actions.erb +2 -0
- data/lib/merit/generators/install_generator.rb +4 -1
- data/lib/merit/generators/merit_generator.rb +4 -1
- data/lib/merit/generators/remove_generator.rb +4 -1
- data/lib/merit/generators/templates/merit.erb +13 -11
- data/lib/merit/judge.rb +6 -5
- data/lib/merit.rb +26 -23
- data/merit.gemspec +2 -1
- data/test/dummy/db/migrate/20130329224406_create_merit_actions.rb +2 -0
- data/test/dummy/db/schema.rb +3 -2
- data/test/integration/navigation_test.rb +1 -1
- data/test/unit/sash_test.rb +16 -0
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1163ea7681b5daca51eb89a7785bc648fe86ddbefff1a05cdc765c20c9b91973
|
4
|
+
data.tar.gz: 1329168f700f69f1d0eff4ca196ed511302b7839745eb8ed58bb5bb277cd5d51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e112a21e6ada4964c86c7253c72bc4235f4ab478a876badfa27cf1d60d2cea3ec297f234219100bc9049e50ea859860a7d6c3f504dcca86b8424da3aa28e007
|
7
|
+
data.tar.gz: 39f8af732714702142e9b0f279c63b7aa528113fd81f39df99f94ae09ca0320e9a2f52b230dd919bedc9e42f5947aed9ad656df89c84c9bc09a56cdacd7e8438
|
data/NEWS.md
CHANGED
@@ -2,6 +2,24 @@
|
|
2
2
|
|
3
3
|
User-visible changes worth mentioning.
|
4
4
|
|
5
|
+
## 4.0.3
|
6
|
+
|
7
|
+
- Add webrick as a development dependency
|
8
|
+
- [#363] Fix: `warning: already initialized constant Merit::*` messages
|
9
|
+
- [#357] Fix `merit_actions` migration template
|
10
|
+
|
11
|
+
## 4.0.2
|
12
|
+
|
13
|
+
- [#355, #356] Add index on merit_actions.processed column
|
14
|
+
- [#354] Fix Rails autoloader deprecation warnings
|
15
|
+
Requires wrapping `Merit::Badge.create` with `Rails.application.reloader.to_prepare`
|
16
|
+
- Test with Ruby 3 and Rails 6.1 (excludes Rails 5.2 with Ruby 3, that errors out)
|
17
|
+
- [#288] Don’t send “removed badge” notifications when user doesn’t have the badge
|
18
|
+
|
19
|
+
## 4.0.1
|
20
|
+
|
21
|
+
- [#351] Fix bug on generating migrations
|
22
|
+
|
5
23
|
## 4.0.0
|
6
24
|
|
7
25
|
- Stop testing on Rails 5.1
|
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:
|
@@ -4,7 +4,6 @@ module Merit
|
|
4
4
|
module Generators
|
5
5
|
class InstallGenerator < ::Rails::Generators::Base
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
7
|
-
hook_for :orm
|
8
7
|
|
9
8
|
desc 'Copy config and rules files'
|
10
9
|
def copy_migrations_and_model
|
@@ -13,6 +12,10 @@ module Merit
|
|
13
12
|
template 'merit_point_rules.erb', 'app/models/merit/point_rules.rb'
|
14
13
|
template 'merit_rank_rules.erb', 'app/models/merit/rank_rules.rb'
|
15
14
|
end
|
15
|
+
|
16
|
+
def run_active_record_generators
|
17
|
+
invoke 'merit:active_record:install'
|
18
|
+
end
|
16
19
|
end
|
17
20
|
end
|
18
21
|
end
|
@@ -4,7 +4,6 @@ module Merit
|
|
4
4
|
module Generators
|
5
5
|
class MeritGenerator < ::Rails::Generators::NamedBase
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
7
|
-
hook_for :orm
|
8
7
|
|
9
8
|
def inject_merit_content
|
10
9
|
if model_exists?
|
@@ -12,6 +11,10 @@ module Merit
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
14
|
+
def run_active_record_generators
|
15
|
+
invoke 'merit:active_record:merit'
|
16
|
+
end
|
17
|
+
|
15
18
|
private
|
16
19
|
|
17
20
|
def model_exists?
|
@@ -4,7 +4,10 @@ module Merit
|
|
4
4
|
module Generators
|
5
5
|
class RemoveGenerator < ::Rails::Generators::NamedBase
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
7
|
-
|
7
|
+
|
8
|
+
def run_active_record_generators
|
9
|
+
invoke 'merit:active_record:remove'
|
10
|
+
end
|
8
11
|
|
9
12
|
private
|
10
13
|
|
@@ -6,7 +6,7 @@ Merit.setup do |config|
|
|
6
6
|
# Add application observers to get notifications when reputation changes.
|
7
7
|
# config.add_observer 'MyObserverClassName'
|
8
8
|
|
9
|
-
# Define :user_model_name. This model will be used to
|
9
|
+
# Define :user_model_name. This model will be used to grant badge if no
|
10
10
|
# `:to` option is given. Default is 'User'.
|
11
11
|
# config.user_model_name = 'User'
|
12
12
|
|
@@ -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/lib/merit.rb
CHANGED
@@ -35,6 +35,16 @@ module Merit
|
|
35
35
|
@config.add_observer(class_name)
|
36
36
|
end
|
37
37
|
|
38
|
+
# If the app is reloaded, avoid printing `warning: previous definition of AppBadgeRules was here`
|
39
|
+
def self.remove_badge_rules
|
40
|
+
remove_const(:AppBadgeRules) if self.const_defined?('AppBadgeRules')
|
41
|
+
end
|
42
|
+
|
43
|
+
# If the app is reloaded, avoid printing `warning: previous definition of AppPointRules was here`
|
44
|
+
def self.remove_point_rules
|
45
|
+
remove_const(:AppPointRules) if self.const_defined?('AppPointRules')
|
46
|
+
end
|
47
|
+
|
38
48
|
class Configuration
|
39
49
|
attr_accessor :checks_on_each_request, :orm, :user_model_name, :observers,
|
40
50
|
:current_user_method
|
@@ -61,32 +71,25 @@ module Merit
|
|
61
71
|
config.app_generators.orm Merit.orm
|
62
72
|
|
63
73
|
initializer 'merit.controller' do |app|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
config.to_prepare do
|
75
|
+
ActiveSupport.on_load(:active_record) { include Merit }
|
76
|
+
ActiveSupport.on_load(app.config.api_only ? :action_controller_api : :action_controller_base) do
|
77
|
+
begin
|
78
|
+
# Remove previous definitions of constant if they are defined when app reloads
|
79
|
+
Merit.remove_badge_rules
|
80
|
+
Merit.remove_point_rules
|
81
|
+
# Load app rules on boot up
|
82
|
+
Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
|
83
|
+
Merit::AppPointRules = Merit::PointRules.new.defined_rules
|
84
|
+
include Merit::ControllerExtensions
|
85
|
+
rescue NameError => e
|
86
|
+
# Trap NameError if installing/generating files
|
87
|
+
raise e unless
|
88
|
+
e.to_s =~ /uninitialized constant Merit::(BadgeRules|PointRules)/
|
89
|
+
end
|
75
90
|
end
|
76
91
|
end
|
77
92
|
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
93
|
end
|
91
94
|
end
|
92
95
|
|
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.3'
|
10
10
|
s.authors = ["Tute Costa"]
|
11
11
|
s.email = 'tutecosta@gmail.com'
|
12
12
|
|
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.add_development_dependency 'rubocop'
|
22
22
|
s.add_development_dependency 'minitest-rails'
|
23
23
|
s.add_development_dependency 'mocha'
|
24
|
+
s.add_development_dependency 'webrick'
|
24
25
|
end
|
data/test/dummy/db/schema.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
# of editing this file, please use the migrations feature of Active Record to
|
3
3
|
# incrementally modify your database, and then regenerate this schema definition.
|
4
4
|
#
|
5
|
-
# This file is the source Rails uses to define your schema when running `rails
|
6
|
-
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
|
5
|
+
# This file is the source Rails uses to define your schema when running `bin/rails
|
6
|
+
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
|
7
7
|
# be faster and is potentially less error prone than running all of your
|
8
8
|
# migrations from scratch. Old migrations may fail to apply correctly if those
|
9
9
|
# migrations use external dependencies or application code.
|
@@ -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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tute Costa
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ambry
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: webrick
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: Manage badges, points and rankings (reputation) in your Rails app.
|
126
140
|
email: tutecosta@gmail.com
|
127
141
|
executables: []
|
@@ -265,7 +279,7 @@ homepage: https://github.com/merit-gem/merit
|
|
265
279
|
licenses:
|
266
280
|
- MIT
|
267
281
|
metadata: {}
|
268
|
-
post_install_message:
|
282
|
+
post_install_message:
|
269
283
|
rdoc_options: []
|
270
284
|
require_paths:
|
271
285
|
- lib
|
@@ -280,8 +294,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
280
294
|
- !ruby/object:Gem::Version
|
281
295
|
version: '0'
|
282
296
|
requirements: []
|
283
|
-
rubygems_version: 3.
|
284
|
-
signing_key:
|
297
|
+
rubygems_version: 3.2.32
|
298
|
+
signing_key:
|
285
299
|
specification_version: 4
|
286
300
|
summary: Reputation engine for Rails apps
|
287
301
|
test_files:
|