sweet_notifications 0.2.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +42 -0
- data/.rubocop.yml +99 -4
- data/Appraisals +14 -4
- data/CHANGELOG.md +16 -0
- data/README.md +4 -3
- data/Rakefile +1 -1
- data/gemfiles/{rails_4.0.gemfile → rails_5.2.gemfile} +2 -2
- data/gemfiles/{rails_4.1.gemfile → rails_6.0.gemfile} +2 -2
- data/gemfiles/rails_6.1.gemfile +7 -0
- data/gemfiles/rails_head.gemfile +9 -0
- data/lib/sweet_notifications.rb +9 -1
- data/lib/sweet_notifications/controller_runtime.rb +2 -1
- data/lib/sweet_notifications/log_subscriber.rb +3 -1
- data/lib/sweet_notifications/version.rb +1 -1
- data/sweet_notifications.gemspec +14 -14
- data/test/controller_runtime_test.rb +30 -13
- data/test/log_subscriber_test.rb +3 -4
- data/test/sweet_notifications_test.rb +21 -6
- data/test/test_helper.rb +24 -4
- metadata +56 -41
- data/.travis.yml +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b6c084ecf379a17039cbda23138ef831ec067ef33da0c653ecd0be81cbd39e28
|
4
|
+
data.tar.gz: 70a60a8ed86fc436352e160415563fad1f839893006655649296380bee09840b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864cd928cdc2a05ecbb355897e93b43b9bbf375430c04f9d9758a7f3fb761a3e990a8f7fd0dd1aa57354007d447224d8e44385b6d5beac01f0c2b296c00c0604
|
7
|
+
data.tar.gz: 52cfd3dc19bf1b96c79ff0701289fe30056eabb605192dfe12d9eec938605f1b3953d27929e56b117abf5e8d438c69b45c03a089a682dc9aad978dc52151449d
|
@@ -0,0 +1,42 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
name: >-
|
8
|
+
Test (${{ matrix.gemfile }} ${{ matrix.ruby }})
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
gemfile:
|
14
|
+
- gemfiles/rails_5.2.gemfile
|
15
|
+
- gemfiles/rails_6.0.gemfile
|
16
|
+
- gemfiles/rails_6.1.gemfile
|
17
|
+
- Gemfile
|
18
|
+
ruby:
|
19
|
+
- 2.5
|
20
|
+
- 2.6
|
21
|
+
- 2.7
|
22
|
+
- 3.0
|
23
|
+
- jruby
|
24
|
+
env:
|
25
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby }}
|
31
|
+
bundler-cache: true
|
32
|
+
- run: bundle exec rake test
|
33
|
+
rubocop:
|
34
|
+
name: Rubocop
|
35
|
+
runs-on: ubuntu-latest
|
36
|
+
steps:
|
37
|
+
- uses: actions/checkout@v2
|
38
|
+
- uses: ruby/setup-ruby@v1
|
39
|
+
with:
|
40
|
+
ruby-version: 3.0
|
41
|
+
bundler-cache: true
|
42
|
+
- run: bundle exec rubocop --format github
|
data/.rubocop.yml
CHANGED
@@ -1,19 +1,114 @@
|
|
1
|
+
require: rubocop-rails
|
2
|
+
|
1
3
|
AllCops:
|
2
4
|
Exclude:
|
3
5
|
- sweet_notifications.gemspec
|
4
6
|
- lib/sweet_notifications/version.rb
|
7
|
+
- "vendor/**/*"
|
8
|
+
- "gemfiles/vendor/**/*"
|
9
|
+
TargetRubyVersion: 2.5
|
10
|
+
|
11
|
+
Rails:
|
12
|
+
Enabled: true
|
13
|
+
|
14
|
+
Rails/ApplicationController:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Rails/AssertNot:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Rails/RefuteMethods:
|
21
|
+
Enabled: false
|
22
|
+
Rails/ActiveRecordCallbacksOrder:
|
23
|
+
Enabled: true
|
24
|
+
Rails/AfterCommitOverride:
|
25
|
+
Enabled: true
|
26
|
+
Rails/FindById:
|
27
|
+
Enabled: true
|
28
|
+
Rails/Inquiry:
|
29
|
+
Enabled: true
|
30
|
+
Rails/MailerName:
|
31
|
+
Enabled: true
|
32
|
+
Rails/MatchRoute:
|
33
|
+
Enabled: true
|
34
|
+
Rails/NegateInclude:
|
35
|
+
Enabled: true
|
36
|
+
Rails/Pluck:
|
37
|
+
Enabled: true
|
38
|
+
Rails/PluckInWhere:
|
39
|
+
Enabled: true
|
40
|
+
Rails/RenderInline:
|
41
|
+
Enabled: true
|
42
|
+
Rails/RenderPlainText:
|
43
|
+
Enabled: true
|
44
|
+
Rails/ShortI18n:
|
45
|
+
Enabled: true
|
46
|
+
Rails/SquishedSQLHeredocs:
|
47
|
+
Enabled: true
|
48
|
+
Rails/WhereExists:
|
49
|
+
Enabled: true
|
50
|
+
Rails/WhereNot:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
Bundler/OrderedGems:
|
54
|
+
Enabled: false
|
5
55
|
|
6
|
-
|
56
|
+
Lint/ConstantDefinitionInBlock:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Style/ClassAndModuleChildren:
|
7
60
|
Exclude:
|
8
61
|
- test/**/*.rb
|
9
62
|
|
10
|
-
Documentation:
|
63
|
+
Style/Documentation:
|
11
64
|
Include:
|
12
65
|
- lib/**/*.rb
|
13
66
|
|
14
|
-
MethodLength:
|
67
|
+
Metrics/MethodLength:
|
15
68
|
Exclude:
|
16
69
|
- lib/sweet_notifications/controller_runtime.rb
|
17
70
|
|
18
|
-
ModuleFunction:
|
71
|
+
Style/ModuleFunction:
|
72
|
+
Enabled: false
|
73
|
+
|
74
|
+
Metrics/AbcSize:
|
19
75
|
Enabled: false
|
76
|
+
|
77
|
+
Metrics/BlockLength:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Style/FormatStringToken:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Style/StringLiterals:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Style/FrozenStringLiteralComment:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
Style/StringConcatenation:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
Style/IfUnlessModifier:
|
93
|
+
Enabled: false
|
94
|
+
|
95
|
+
Lint/DuplicateRegexpCharacterClassElement:
|
96
|
+
Enabled: true
|
97
|
+
Lint/EmptyBlock:
|
98
|
+
Enabled: true
|
99
|
+
Lint/NoReturnInBeginEndBlocks:
|
100
|
+
Enabled: true
|
101
|
+
Lint/ToEnumArguments:
|
102
|
+
Enabled: true
|
103
|
+
Lint/UnmodifiedReduceAccumulator:
|
104
|
+
Enabled: true
|
105
|
+
Style/ArgumentsForwarding:
|
106
|
+
Enabled: true
|
107
|
+
Style/CollectionCompact:
|
108
|
+
Enabled: true
|
109
|
+
Style/DocumentDynamicEvalDefinition:
|
110
|
+
Enabled: true
|
111
|
+
Style/NegatedIfElseCondition:
|
112
|
+
Enabled: true
|
113
|
+
Style/SwapValues:
|
114
|
+
Enabled: true
|
data/Appraisals
CHANGED
@@ -1,7 +1,17 @@
|
|
1
|
-
appraise
|
2
|
-
gem 'rails', '~>
|
1
|
+
appraise 'rails-5.2' do
|
2
|
+
gem 'rails', '~> 5.2.0'
|
3
3
|
end
|
4
4
|
|
5
|
-
appraise
|
6
|
-
gem 'rails', '~>
|
5
|
+
appraise 'rails-6.0' do
|
6
|
+
gem 'rails', '~> 6.0.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
appraise 'rails-6.1' do
|
10
|
+
gem 'rails', '~> 6.1.0'
|
11
|
+
end
|
12
|
+
|
13
|
+
appraise 'rails-head' do
|
14
|
+
gem 'rails', github: 'rails'
|
15
|
+
gem 'arel', github: 'rails/arel'
|
16
|
+
gem 'rack', github: 'rack'
|
7
17
|
end
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
## 1.1.0 (8 November 2020)
|
2
|
+
|
3
|
+
- drop support for old Ruby and Rails versions
|
4
|
+
- call super in log subscriber inheriting hook
|
5
|
+
|
6
|
+
## 1.0.0 (18 January 2017)
|
7
|
+
|
8
|
+
- more robust Rails initialization testing
|
9
|
+
|
10
|
+
## 0.2.1 (3 October 2015)
|
11
|
+
|
12
|
+
- support Rails 5.0
|
13
|
+
|
14
|
+
## 0.2.0 (11 June 2014)
|
15
|
+
|
16
|
+
- allow overriding label used in logging
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
# SweetNotifications
|
1
|
+
# SweetNotifications
|
2
2
|
|
3
3
|
Syntactic sugar for ActiveSupport::LogSubscriber for easy instrumentation and
|
4
4
|
logging from third-party libraries.
|
5
5
|
|
6
|
-
This gem
|
6
|
+
This gem requires Ruby 2.0 or newer. Compatible versions of JRuby and Rubinius
|
7
|
+
are also supported.
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
@@ -43,7 +44,7 @@ Then, subscribe to these notifications using SweetNotifications in an initialize
|
|
43
44
|
SweetNotifications.subscribe :candies do
|
44
45
|
color ActiveSupport::LogSubscriber::GREEN
|
45
46
|
event :list, runtime: true do |event|
|
46
|
-
|
47
|
+
next unless logger.debug? # Use next in blocks
|
47
48
|
debug message(event, 'Candy', "listing candies: #{event.payload[:candies]}")
|
48
49
|
end
|
49
50
|
end
|
data/Rakefile
CHANGED
data/lib/sweet_notifications.rb
CHANGED
@@ -34,11 +34,19 @@ module SweetNotifications
|
|
34
34
|
label ||= name
|
35
35
|
log_subscriber = Class.new(SweetNotifications::LogSubscriber, &block)
|
36
36
|
controller_runtime = self.controller_runtime(label, log_subscriber)
|
37
|
-
if
|
37
|
+
if rails_initialized?
|
38
38
|
initialize_rails(name, log_subscriber, controller_runtime)
|
39
39
|
[nil, log_subscriber]
|
40
40
|
else
|
41
41
|
[railtie(name, log_subscriber, controller_runtime), log_subscriber]
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
def self.rails_initialized?
|
46
|
+
Rails.respond_to?(:application) &&
|
47
|
+
Rails.application &&
|
48
|
+
Rails.application.initialized?
|
49
|
+
end
|
50
|
+
|
51
|
+
private_class_method :rails_initialized?
|
44
52
|
end
|
@@ -39,7 +39,8 @@ module SweetNotifications
|
|
39
39
|
|
40
40
|
const_set(:ClassMethods, Module.new do
|
41
41
|
define_method :log_process_action do |payload|
|
42
|
-
messages
|
42
|
+
messages = super(payload)
|
43
|
+
runtime = payload[runtime_attr]
|
43
44
|
if runtime && runtime != 0
|
44
45
|
messages << format("#{name}: %.1fms", runtime.to_f)
|
45
46
|
end
|
@@ -52,7 +52,8 @@ module SweetNotifications
|
|
52
52
|
#
|
53
53
|
# @return Numeric previous runtime value
|
54
54
|
def reset_runtime
|
55
|
-
rt
|
55
|
+
rt = runtime
|
56
|
+
self.runtime = 0
|
56
57
|
rt
|
57
58
|
end
|
58
59
|
|
@@ -77,6 +78,7 @@ module SweetNotifications
|
|
77
78
|
protected
|
78
79
|
|
79
80
|
def inherited(base)
|
81
|
+
super
|
80
82
|
base.class_eval do
|
81
83
|
@name ||= SecureRandom.hex
|
82
84
|
end
|
data/sweet_notifications.gemspec
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'sweet_notifications/version'
|
5
4
|
|
@@ -8,8 +7,8 @@ Gem::Specification.new do |spec|
|
|
8
7
|
spec.version = SweetNotifications::VERSION
|
9
8
|
spec.authors = ["Ville Lautanala"]
|
10
9
|
spec.email = ["lautis@gmail.com"]
|
11
|
-
spec.summary =
|
12
|
-
spec.description =
|
10
|
+
spec.summary = 'Syntactic sugar for ActiveSupport::LogSubscriber.'
|
11
|
+
spec.description = 'Syntactic sugar for ActiveSupport::LogSubscriber for easy instrumentation and logging from third-party libraries.'
|
13
12
|
spec.homepage = "https://github.com/lautis/sweet_notifications"
|
14
13
|
spec.license = "MIT"
|
15
14
|
|
@@ -18,17 +17,18 @@ Gem::Specification.new do |spec|
|
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
18
|
spec.require_paths = ["lib"]
|
20
19
|
|
21
|
-
spec.required_ruby_version = '
|
20
|
+
spec.required_ruby_version = '>= 2.5'
|
22
21
|
|
23
|
-
spec.add_runtime_dependency "activesupport", "
|
22
|
+
spec.add_runtime_dependency "activesupport", ">= 5.2"
|
23
|
+
spec.add_runtime_dependency "railties", ">= 5.2"
|
24
24
|
spec.add_runtime_dependency "request_store", "~> 1.0"
|
25
|
-
spec.
|
26
|
-
spec.add_development_dependency "
|
27
|
-
spec.add_development_dependency "bundler", "
|
25
|
+
spec.add_development_dependency "actionpack", ">= 5.2"
|
26
|
+
spec.add_development_dependency "appraisal", "~> 2.0"
|
27
|
+
spec.add_development_dependency "bundler", ">= 1.6"
|
28
28
|
spec.add_development_dependency "minitest"
|
29
|
-
spec.add_development_dependency "rake", "~>
|
30
|
-
spec.add_development_dependency "
|
31
|
-
spec.add_development_dependency "
|
32
|
-
spec.add_development_dependency "simplecov", "~> 0.
|
33
|
-
spec.add_development_dependency "
|
29
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
30
|
+
spec.add_development_dependency "rubocop", "~> 1.2.0"
|
31
|
+
spec.add_development_dependency "rubocop-rails", "~> 2.0"
|
32
|
+
spec.add_development_dependency "simplecov", "~> 0.15"
|
33
|
+
spec.add_development_dependency "yard", "~> 0.9.7"
|
34
34
|
end
|
@@ -6,29 +6,46 @@ describe SweetNotifications::ControllerRuntime do
|
|
6
6
|
|
7
7
|
ControllerRuntime = SweetNotifications.controller_runtime('Test',
|
8
8
|
TestLogSubscriber)
|
9
|
-
ActionController::Base.
|
9
|
+
ActionController::Base.include ControllerRuntime
|
10
10
|
|
11
11
|
class LogSubscribersController < ActionController::Base
|
12
12
|
def create
|
13
13
|
TestLogSubscriber.runtime += 100
|
14
|
-
|
14
|
+
render_text '100'
|
15
15
|
end
|
16
16
|
|
17
17
|
def show
|
18
|
-
|
18
|
+
render_text '0'
|
19
19
|
end
|
20
20
|
|
21
21
|
def destroy
|
22
22
|
TestLogSubscriber.runtime += 50
|
23
|
-
|
23
|
+
render_text 'OK'
|
24
24
|
TestLogSubscriber.runtime += 5
|
25
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def render_text(text)
|
30
|
+
if rails_version?('< 4.2')
|
31
|
+
render text: text
|
32
|
+
else
|
33
|
+
render plain: text
|
34
|
+
end
|
35
|
+
end
|
26
36
|
end
|
27
37
|
|
28
38
|
include ActiveSupport::LogSubscriber::TestHelper
|
29
39
|
tests LogSubscribersController
|
30
40
|
|
31
41
|
before do
|
42
|
+
require 'rails'
|
43
|
+
if rails_version?('>= 5.0')
|
44
|
+
ActionController::TestRoutes.draw do
|
45
|
+
resources :log_subscribers
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
32
49
|
@old_logger = ActionController::Base.logger
|
33
50
|
ActionController::LogSubscriber.attach_to :action_controller
|
34
51
|
end
|
@@ -38,11 +55,11 @@ describe SweetNotifications::ControllerRuntime do
|
|
38
55
|
ActionController::Base.logger = @old_logger
|
39
56
|
end
|
40
57
|
|
41
|
-
# rubocop:disable AccessorMethodName
|
58
|
+
# rubocop:disable Naming/AccessorMethodName
|
42
59
|
def set_logger(logger)
|
43
60
|
ActionController::Base.logger = logger
|
44
61
|
end
|
45
|
-
# rubocop:enable AccessorMethodName
|
62
|
+
# rubocop:enable Naming/AccessorMethodName
|
46
63
|
|
47
64
|
describe '.log_process_action' do
|
48
65
|
it 'emits runtime to log messages' do
|
@@ -53,30 +70,30 @@ describe SweetNotifications::ControllerRuntime do
|
|
53
70
|
|
54
71
|
describe 'runtime logging' do
|
55
72
|
it 'does not append runtime when it is 0' do
|
56
|
-
get :show, id: 1
|
73
|
+
get :show, params: { id: 1 }
|
57
74
|
wait
|
58
75
|
assert_no_match(/Test:/, @logger.logged(:info)[2])
|
59
76
|
end
|
60
77
|
|
61
78
|
it 'appends non-zero runtime' do
|
62
|
-
post :create, test: 1
|
79
|
+
post :create, params: { test: 1 }
|
63
80
|
wait
|
64
|
-
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms
|
81
|
+
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms/
|
65
82
|
assert_match(expected_message, @logger.logged(:info)[2])
|
66
83
|
end
|
67
84
|
|
68
85
|
it 'resets runtime before request' do
|
69
86
|
TestLogSubscriber.runtime += 1000
|
70
|
-
post :create, test: 1
|
87
|
+
post :create, params: { test: 1 }
|
71
88
|
wait
|
72
|
-
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms
|
89
|
+
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms/
|
73
90
|
assert_match(expected_message, @logger.logged(:info)[2])
|
74
91
|
end
|
75
92
|
|
76
93
|
it 'includes runtime after render' do
|
77
|
-
post :destroy, id: 1
|
94
|
+
post :destroy, params: { id: 1 }
|
78
95
|
wait
|
79
|
-
expected_message = /\(Views: [\d.]+ms \| Test: 55.0ms
|
96
|
+
expected_message = /\(Views: [\d.]+ms \| Test: 55.0ms/
|
80
97
|
assert_match(expected_message, @logger.logged(:info)[2])
|
81
98
|
end
|
82
99
|
end
|
data/test/log_subscriber_test.rb
CHANGED
@@ -5,7 +5,7 @@ describe SweetNotifications::LogSubscriber do
|
|
5
5
|
|
6
6
|
def event(name: 'Test', duration: 1, transaction_id: SecureRandom.hex,
|
7
7
|
payload: {})
|
8
|
-
now = Time.
|
8
|
+
now = Time.current
|
9
9
|
ActiveSupport::Notifications::Event.new(name,
|
10
10
|
now,
|
11
11
|
now + duration,
|
@@ -135,15 +135,14 @@ describe SweetNotifications::LogSubscriber do
|
|
135
135
|
subject.colorize_logging = true
|
136
136
|
odd = subject.message(event, 'Label', 'body')
|
137
137
|
even = subject.message(event, 'Label', 'body')
|
138
|
-
assert
|
138
|
+
assert odd.exclude?(ActiveSupport::LogSubscriber::BOLD + 'body')
|
139
139
|
assert even.include?(ActiveSupport::LogSubscriber::BOLD + 'body')
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'does not use colors when setting is disabled' do
|
143
143
|
subject.colorize_logging = false
|
144
144
|
message = subject.message(event, 'Label', 'body')
|
145
|
-
assert
|
145
|
+
assert message.exclude?(ActiveSupport::LogSubscriber::CYAN)
|
146
146
|
end
|
147
|
-
|
148
147
|
end
|
149
148
|
end
|
@@ -5,7 +5,12 @@ class SweetNotificationsController < ActionController::Base
|
|
5
5
|
ActiveSupport::Notifications.instrument 'test.controller' do
|
6
6
|
'ok'
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
|
+
if rails_version?('< 4.2')
|
10
|
+
render text: 'ok'
|
11
|
+
else
|
12
|
+
render plain: 'ok'
|
13
|
+
end
|
9
14
|
end
|
10
15
|
end
|
11
16
|
|
@@ -13,9 +18,18 @@ describe SweetNotifications do
|
|
13
18
|
include ActiveSupport::LogSubscriber::TestHelper
|
14
19
|
tests SweetNotificationsController
|
15
20
|
|
21
|
+
before do
|
22
|
+
if rails_version?('>= 5.0')
|
23
|
+
ActionController::TestRoutes.draw do
|
24
|
+
resources :sweet_notifications
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
16
29
|
describe '.subscribe' do
|
17
30
|
it 'creates a railtie' do
|
18
|
-
railtie,
|
31
|
+
railtie, = SweetNotifications.subscribe 'railtie_create' do
|
32
|
+
# empty block
|
19
33
|
end
|
20
34
|
assert railtie < Rails::Railtie
|
21
35
|
end
|
@@ -29,7 +43,7 @@ describe SweetNotifications do
|
|
29
43
|
end
|
30
44
|
|
31
45
|
it 'binds log subscriber to notifications' do
|
32
|
-
railtie,
|
46
|
+
railtie, = SweetNotifications.subscribe 'sweet' do
|
33
47
|
event :test do |event|
|
34
48
|
info message(event, 'Test', 'blah blah')
|
35
49
|
end
|
@@ -49,13 +63,14 @@ describe SweetNotifications do
|
|
49
63
|
end
|
50
64
|
end
|
51
65
|
|
52
|
-
railtie,
|
66
|
+
railtie, = SweetNotifications.subscribe 'sweet' do
|
53
67
|
event :direct do |event|
|
54
68
|
info message(event, 'Direct', 'foo bar')
|
55
69
|
end
|
56
70
|
end
|
57
71
|
|
58
|
-
|
72
|
+
assert_nil railtie
|
73
|
+
|
59
74
|
module ::Rails
|
60
75
|
class << self
|
61
76
|
undef application
|
@@ -68,7 +83,7 @@ describe SweetNotifications do
|
|
68
83
|
end
|
69
84
|
|
70
85
|
it 'logs to Rails logger' do
|
71
|
-
railtie,
|
86
|
+
railtie, = SweetNotifications.subscribe 'controller', label: 'Label' do
|
72
87
|
event :test, runtime: true do |event|
|
73
88
|
info message(event, 'Test', 'logging')
|
74
89
|
end
|
data/test/test_helper.rb
CHANGED
@@ -3,7 +3,7 @@ require 'simplecov'
|
|
3
3
|
|
4
4
|
SimpleCov.start do
|
5
5
|
add_filter 'test'
|
6
|
-
command_name '
|
6
|
+
command_name 'Minitest'
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'minitest/autorun'
|
@@ -13,28 +13,48 @@ require 'sweet_notifications'
|
|
13
13
|
require 'active_support/test_case'
|
14
14
|
require 'action_controller'
|
15
15
|
require 'active_support/log_subscriber/test_helper'
|
16
|
+
require 'active_support/core_ext/string'
|
16
17
|
require 'securerandom'
|
17
18
|
|
19
|
+
module RailsVersion
|
20
|
+
extend self
|
21
|
+
def rails_version?(constraint)
|
22
|
+
gem_spec = Gem.loaded_specs['actionpack']
|
23
|
+
gem_spec && Gem::Requirement.new(constraint).satisfied_by?(gem_spec.version)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
18
27
|
class ActiveSupport::TestCase
|
19
28
|
class << self
|
20
|
-
remove_method :describe
|
29
|
+
remove_method :describe if method_defined? :describe
|
21
30
|
end
|
22
31
|
|
23
32
|
extend MiniTest::Spec::DSL
|
24
33
|
register_spec_type(/SweetNotifications$/, ActionController::TestCase)
|
25
34
|
register_spec_type(/ControllerRuntime$/, ActionController::TestCase)
|
26
35
|
register_spec_type(self)
|
36
|
+
|
37
|
+
include RailsVersion
|
38
|
+
end
|
39
|
+
|
40
|
+
if ActiveSupport::TestCase.respond_to?(:test_order=)
|
41
|
+
ActiveSupport::TestCase.test_order = :random
|
27
42
|
end
|
28
43
|
|
29
44
|
module ActionController
|
45
|
+
extend RailsVersion
|
30
46
|
TestRoutes = ActionDispatch::Routing::RouteSet.new
|
31
|
-
|
32
|
-
|
47
|
+
|
48
|
+
if rails_version?('< 5.0')
|
49
|
+
TestRoutes.draw do
|
50
|
+
match ':controller(/:action)', via: [:all]
|
51
|
+
end
|
33
52
|
end
|
34
53
|
|
35
54
|
class Base
|
36
55
|
include ActionController::Testing
|
37
56
|
include TestRoutes.url_helpers
|
57
|
+
include RailsVersion
|
38
58
|
end
|
39
59
|
|
40
60
|
class ActionController::TestCase
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sweet_notifications
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ville Lautanala
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '5.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '5.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: request_store
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,45 +53,45 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '1.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: actionpack
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
-
type: :
|
61
|
+
version: '5.2'
|
62
|
+
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
68
|
+
version: '5.2'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
70
|
+
name: appraisal
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - "~>"
|
60
74
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
75
|
+
version: '2.0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
82
|
+
version: '2.0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: bundler
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
72
86
|
requirements:
|
73
|
-
- - "
|
87
|
+
- - ">="
|
74
88
|
- !ruby/object:Gem::Version
|
75
89
|
version: '1.6'
|
76
90
|
type: :development
|
77
91
|
prerelease: false
|
78
92
|
version_requirements: !ruby/object:Gem::Requirement
|
79
93
|
requirements:
|
80
|
-
- - "
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '1.6'
|
83
97
|
- !ruby/object:Gem::Dependency
|
@@ -100,70 +114,70 @@ dependencies:
|
|
100
114
|
requirements:
|
101
115
|
- - "~>"
|
102
116
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
117
|
+
version: '13.0'
|
104
118
|
type: :development
|
105
119
|
prerelease: false
|
106
120
|
version_requirements: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
122
|
- - "~>"
|
109
123
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
124
|
+
version: '13.0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
126
|
+
name: rubocop
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
114
128
|
requirements:
|
115
129
|
- - "~>"
|
116
130
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
131
|
+
version: 1.2.0
|
118
132
|
type: :development
|
119
133
|
prerelease: false
|
120
134
|
version_requirements: !ruby/object:Gem::Requirement
|
121
135
|
requirements:
|
122
136
|
- - "~>"
|
123
137
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
138
|
+
version: 1.2.0
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
140
|
+
name: rubocop-rails
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
128
142
|
requirements:
|
129
143
|
- - "~>"
|
130
144
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
145
|
+
version: '2.0'
|
132
146
|
type: :development
|
133
147
|
prerelease: false
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
135
149
|
requirements:
|
136
150
|
- - "~>"
|
137
151
|
- !ruby/object:Gem::Version
|
138
|
-
version: '
|
152
|
+
version: '2.0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: simplecov
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
157
|
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: 0.
|
159
|
+
version: '0.15'
|
146
160
|
type: :development
|
147
161
|
prerelease: false
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
149
163
|
requirements:
|
150
164
|
- - "~>"
|
151
165
|
- !ruby/object:Gem::Version
|
152
|
-
version: 0.
|
166
|
+
version: '0.15'
|
153
167
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
168
|
+
name: yard
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
156
170
|
requirements:
|
157
171
|
- - "~>"
|
158
172
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
173
|
+
version: 0.9.7
|
160
174
|
type: :development
|
161
175
|
prerelease: false
|
162
176
|
version_requirements: !ruby/object:Gem::Requirement
|
163
177
|
requirements:
|
164
178
|
- - "~>"
|
165
179
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
180
|
+
version: 0.9.7
|
167
181
|
description: Syntactic sugar for ActiveSupport::LogSubscriber for easy instrumentation
|
168
182
|
and logging from third-party libraries.
|
169
183
|
email:
|
@@ -172,17 +186,20 @@ executables: []
|
|
172
186
|
extensions: []
|
173
187
|
extra_rdoc_files: []
|
174
188
|
files:
|
189
|
+
- ".github/workflows/ci.yml"
|
175
190
|
- ".gitignore"
|
176
191
|
- ".rubocop.yml"
|
177
|
-
- ".travis.yml"
|
178
192
|
- Appraisals
|
193
|
+
- CHANGELOG.md
|
179
194
|
- CONTRIBUTING.md
|
180
195
|
- Gemfile
|
181
196
|
- LICENSE.txt
|
182
197
|
- README.md
|
183
198
|
- Rakefile
|
184
|
-
- gemfiles/
|
185
|
-
- gemfiles/
|
199
|
+
- gemfiles/rails_5.2.gemfile
|
200
|
+
- gemfiles/rails_6.0.gemfile
|
201
|
+
- gemfiles/rails_6.1.gemfile
|
202
|
+
- gemfiles/rails_head.gemfile
|
186
203
|
- lib/sweet_notifications.rb
|
187
204
|
- lib/sweet_notifications/controller_runtime.rb
|
188
205
|
- lib/sweet_notifications/log_subscriber.rb
|
@@ -198,24 +215,23 @@ homepage: https://github.com/lautis/sweet_notifications
|
|
198
215
|
licenses:
|
199
216
|
- MIT
|
200
217
|
metadata: {}
|
201
|
-
post_install_message:
|
218
|
+
post_install_message:
|
202
219
|
rdoc_options: []
|
203
220
|
require_paths:
|
204
221
|
- lib
|
205
222
|
required_ruby_version: !ruby/object:Gem::Requirement
|
206
223
|
requirements:
|
207
|
-
- - "
|
224
|
+
- - ">="
|
208
225
|
- !ruby/object:Gem::Version
|
209
|
-
version: '2.
|
226
|
+
version: '2.5'
|
210
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
228
|
requirements:
|
212
229
|
- - ">="
|
213
230
|
- !ruby/object:Gem::Version
|
214
231
|
version: '0'
|
215
232
|
requirements: []
|
216
|
-
|
217
|
-
|
218
|
-
signing_key:
|
233
|
+
rubygems_version: 3.1.2
|
234
|
+
signing_key:
|
219
235
|
specification_version: 4
|
220
236
|
summary: Syntactic sugar for ActiveSupport::LogSubscriber.
|
221
237
|
test_files:
|
@@ -224,4 +240,3 @@ test_files:
|
|
224
240
|
- test/railtie_test.rb
|
225
241
|
- test/sweet_notifications_test.rb
|
226
242
|
- test/test_helper.rb
|
227
|
-
has_rdoc:
|