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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81342bb2e6b393dca1eed04fb9918e964d7add7e4a5144da975deb98fa05651e
4
- data.tar.gz: 6b942ef093394de05ad17ddc74b2c802ed3e4e648f4452b1497b0e1a3521eefb
3
+ metadata.gz: 80cd3f1c6e1d7bac792d556e3b5145c82f0e3db9bd5b07eb6487c2de7f029613
4
+ data.tar.gz: ba6e5ee3691603cf88f3871b23bd875bb755fe2206c24f790d3ce427f6c2430f
5
5
  SHA512:
6
- metadata.gz: 9054350196c3dbb3d9a4542519a100f1ee1f34bc8bd2374de067fea912910afb1d795c78bd120e9b5007c2032dd0aecb4d113e21d7470232f00be15c2fe41c88
7
- data.tar.gz: e86554c92ac022a624a911a2e5cdb81562cde41babc2c2fa195aa78e4c264ef389db106c5907ba05f7db6bb4f4ce9a276d57d49b34d78138eee6c633dbed655c
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
- Merit::Badge.create!(
62
- id: 1,
63
- name: "year-member",
64
- description: "Active member for a year",
65
- custom_fields: { difficulty: :silver }
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 in your
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
- extend_orm_with_has_merit
65
- ActiveSupport.on_load(action_controller_hook) do
66
- begin
67
- # Load app rules on boot up
68
- Merit::AppBadgeRules = Merit::BadgeRules.new.defined_rules
69
- Merit::AppPointRules = Merit::PointRules.new.defined_rules
70
- include Merit::ControllerExtensions
71
- rescue NameError => e
72
- # Trap NameError if installing/generating files
73
- raise e unless
74
- e.to_s =~ /uninitialized constant Merit::(BadgeRules|PointRules)/
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
 
@@ -12,4 +12,6 @@ class CreateMeritActions < ActiveRecord::Migration<%= migration_version %>
12
12
  t.timestamps null: false
13
13
  end
14
14
  end
15
+
16
+ add_index :merit_actions, :processed
15
17
  end
@@ -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
- # badge_id = 0
21
- # [{
22
- # id: (badge_id = badge_id+1),
23
- # name: 'just-registered'
24
- # }, {
25
- # id: (badge_id = badge_id+1),
26
- # name: 'best-unicorn',
27
- # custom_fields: { category: 'fantasy' }
28
- # }].each do |attrs|
29
- # Merit::Badge.create! attrs
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
- notify_observers(
55
- description: I18n.t("merit.removed_badge", badge_name: badge.name),
56
- sash_id: sash.id
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.1'
9
+ s.version = '4.0.2'
10
10
  s.authors = ["Tute Costa"]
11
11
  s.email = 'tutecosta@gmail.com'
12
12
 
@@ -10,6 +10,8 @@ class CreateMeritActions < ActiveRecord::Migration[5.0]
10
10
  t.boolean :processed, :default => false
11
11
  t.timestamps null: false
12
12
  end
13
+
14
+ add_index :merit_actions, :processed
13
15
  end
14
16
 
15
17
  def self.down
@@ -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', 2) do
183
+ assert_difference('Merit::ActivityLog.count', 1) do
184
184
  click_button('Update User')
185
185
  end
186
186
 
@@ -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.1
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: 2020-08-15 00:00:00.000000000 Z
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.0.3
283
+ rubygems_version: 3.1.6
284
284
  signing_key:
285
285
  specification_version: 4
286
286
  summary: Reputation engine for Rails apps