sweet_notifications 0.1.0 → 1.1.0
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 +43 -0
- data/.rubocop.yml +99 -4
- data/Appraisals +10 -4
- data/CHANGELOG.md +16 -0
- data/README.md +4 -3
- data/Rakefile +2 -2
- 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_head.gemfile +9 -0
- data/lib/sweet_notifications.rb +13 -3
- data/lib/sweet_notifications/controller_runtime.rb +2 -1
- data/lib/sweet_notifications/log_subscriber.rb +8 -1
- data/lib/sweet_notifications/version.rb +1 -1
- data/sweet_notifications.gemspec +14 -14
- data/test/controller_runtime_test.rb +30 -18
- data/test/log_subscriber_test.rb +3 -5
- data/test/sweet_notifications_test.rb +44 -4
- data/test/test_helper.rb +27 -4
- metadata +54 -40
- 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: 5c1c62f7f37f8ccb5183e5319cfbd745533545be20c374ef14ac034081adacab
|
4
|
+
data.tar.gz: 0f73960d95c9cc6d0c8df39fb0d16bf451672fe6eee7cb924c7ca1354da24ab6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16da12ca9aeb6817725667ae40fee08bd25d0da2f1dd46fb1e93aebb67205a3b07d23993df789e7800702ed0aaf9bb56a678fa09ebd9428f3374f9eb67abfab0
|
7
|
+
data.tar.gz: 4591548d09478c09b16b6f12790e43e24a00dfe9163e6763944399ecafc65c984b132926c1e63b8fe8f26aa18a209572d8ef72c9711eeb38b052fb072dc6df28
|
@@ -0,0 +1,43 @@
|
|
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
|
+
- Gemfile
|
17
|
+
ruby:
|
18
|
+
- 2.5
|
19
|
+
- 2.6
|
20
|
+
- 2.7
|
21
|
+
- jruby
|
22
|
+
include:
|
23
|
+
- ruby: 2.7
|
24
|
+
gemfile: gemfiles/rails_head.gemfile
|
25
|
+
env:
|
26
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v2
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
bundler-cache: true
|
33
|
+
- run: bundle exec rake test
|
34
|
+
rubocop:
|
35
|
+
name: Rubocop
|
36
|
+
runs-on: ubuntu-latest
|
37
|
+
steps:
|
38
|
+
- uses: actions/checkout@v2
|
39
|
+
- uses: ruby/setup-ruby@v1
|
40
|
+
with:
|
41
|
+
ruby-version: 2.7
|
42
|
+
bundler-cache: true
|
43
|
+
- 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,13 @@
|
|
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-head' do
|
10
|
+
gem 'rails', github: 'rails'
|
11
|
+
gem 'arel', github: 'rails/arel'
|
12
|
+
gem 'rack', github: 'rack'
|
7
13
|
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
@@ -16,6 +16,7 @@ module SweetNotifications
|
|
16
16
|
# initialized.
|
17
17
|
#
|
18
18
|
# @param name [Symbol] event namespace
|
19
|
+
# @param label [String] optional label for logging
|
19
20
|
# @return [Rails::Railtie, ActiveSupport::LogSubscriber] An array consisting
|
20
21
|
# of a Railtie and a LogSubscriber
|
21
22
|
# @yield event subscription
|
@@ -29,14 +30,23 @@ module SweetNotifications
|
|
29
30
|
# debug message(event, event.payload[:name], event.payload[:sql])
|
30
31
|
# end
|
31
32
|
# end
|
32
|
-
def self.subscribe(name, &block)
|
33
|
+
def self.subscribe(name, label: nil, &block)
|
34
|
+
label ||= name
|
33
35
|
log_subscriber = Class.new(SweetNotifications::LogSubscriber, &block)
|
34
|
-
controller_runtime = self.controller_runtime(
|
35
|
-
if
|
36
|
+
controller_runtime = self.controller_runtime(label, log_subscriber)
|
37
|
+
if rails_initialized?
|
36
38
|
initialize_rails(name, log_subscriber, controller_runtime)
|
37
39
|
[nil, log_subscriber]
|
38
40
|
else
|
39
41
|
[railtie(name, log_subscriber, controller_runtime), log_subscriber]
|
40
42
|
end
|
41
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?
|
42
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
|
@@ -7,6 +7,11 @@ module SweetNotifications
|
|
7
7
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
8
8
|
class_attribute :odd_color, :even_color
|
9
9
|
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
@odd = false
|
13
|
+
end
|
14
|
+
|
10
15
|
# Format a message for logging
|
11
16
|
#
|
12
17
|
# @param event [ActiveSupport::Notifications::Event] subscribed event
|
@@ -47,7 +52,8 @@ module SweetNotifications
|
|
47
52
|
#
|
48
53
|
# @return Numeric previous runtime value
|
49
54
|
def reset_runtime
|
50
|
-
rt
|
55
|
+
rt = runtime
|
56
|
+
self.runtime = 0
|
51
57
|
rt
|
52
58
|
end
|
53
59
|
|
@@ -72,6 +78,7 @@ module SweetNotifications
|
|
72
78
|
protected
|
73
79
|
|
74
80
|
def inherited(base)
|
81
|
+
super
|
75
82
|
base.class_eval do
|
76
83
|
@name ||= SecureRandom.hex
|
77
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 = '~> 2.
|
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
|
@@ -1,8 +1,3 @@
|
|
1
|
-
require 'active_support/test_case'
|
2
|
-
require 'active_support/log_subscriber'
|
3
|
-
require 'active_support/log_subscriber/test_helper'
|
4
|
-
require 'action_controller/log_subscriber'
|
5
|
-
require 'action_controller'
|
6
1
|
require 'test_helper'
|
7
2
|
|
8
3
|
describe SweetNotifications::ControllerRuntime do
|
@@ -11,29 +6,46 @@ describe SweetNotifications::ControllerRuntime do
|
|
11
6
|
|
12
7
|
ControllerRuntime = SweetNotifications.controller_runtime('Test',
|
13
8
|
TestLogSubscriber)
|
14
|
-
ActionController::Base.
|
9
|
+
ActionController::Base.include ControllerRuntime
|
15
10
|
|
16
11
|
class LogSubscribersController < ActionController::Base
|
17
12
|
def create
|
18
13
|
TestLogSubscriber.runtime += 100
|
19
|
-
|
14
|
+
render_text '100'
|
20
15
|
end
|
21
16
|
|
22
17
|
def show
|
23
|
-
|
18
|
+
render_text '0'
|
24
19
|
end
|
25
20
|
|
26
21
|
def destroy
|
27
22
|
TestLogSubscriber.runtime += 50
|
28
|
-
|
23
|
+
render_text 'OK'
|
29
24
|
TestLogSubscriber.runtime += 5
|
30
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
|
31
36
|
end
|
32
37
|
|
33
38
|
include ActiveSupport::LogSubscriber::TestHelper
|
34
39
|
tests LogSubscribersController
|
35
40
|
|
36
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
|
+
|
37
49
|
@old_logger = ActionController::Base.logger
|
38
50
|
ActionController::LogSubscriber.attach_to :action_controller
|
39
51
|
end
|
@@ -43,11 +55,11 @@ describe SweetNotifications::ControllerRuntime do
|
|
43
55
|
ActionController::Base.logger = @old_logger
|
44
56
|
end
|
45
57
|
|
46
|
-
# rubocop:disable AccessorMethodName
|
58
|
+
# rubocop:disable Naming/AccessorMethodName
|
47
59
|
def set_logger(logger)
|
48
60
|
ActionController::Base.logger = logger
|
49
61
|
end
|
50
|
-
# rubocop:enable AccessorMethodName
|
62
|
+
# rubocop:enable Naming/AccessorMethodName
|
51
63
|
|
52
64
|
describe '.log_process_action' do
|
53
65
|
it 'emits runtime to log messages' do
|
@@ -58,30 +70,30 @@ describe SweetNotifications::ControllerRuntime do
|
|
58
70
|
|
59
71
|
describe 'runtime logging' do
|
60
72
|
it 'does not append runtime when it is 0' do
|
61
|
-
get :show, id: 1
|
73
|
+
get :show, params: { id: 1 }
|
62
74
|
wait
|
63
75
|
assert_no_match(/Test:/, @logger.logged(:info)[2])
|
64
76
|
end
|
65
77
|
|
66
78
|
it 'appends non-zero runtime' do
|
67
|
-
post :create, test: 1
|
79
|
+
post :create, params: { test: 1 }
|
68
80
|
wait
|
69
|
-
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms
|
81
|
+
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms/
|
70
82
|
assert_match(expected_message, @logger.logged(:info)[2])
|
71
83
|
end
|
72
84
|
|
73
85
|
it 'resets runtime before request' do
|
74
86
|
TestLogSubscriber.runtime += 1000
|
75
|
-
post :create, test: 1
|
87
|
+
post :create, params: { test: 1 }
|
76
88
|
wait
|
77
|
-
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms
|
89
|
+
expected_message = /\(Views: [\d.]+ms \| Test: 100.0ms/
|
78
90
|
assert_match(expected_message, @logger.logged(:info)[2])
|
79
91
|
end
|
80
92
|
|
81
93
|
it 'includes runtime after render' do
|
82
|
-
post :destroy, id: 1
|
94
|
+
post :destroy, params: { id: 1 }
|
83
95
|
wait
|
84
|
-
expected_message = /\(Views: [\d.]+ms \| Test: 55.0ms
|
96
|
+
expected_message = /\(Views: [\d.]+ms \| Test: 55.0ms/
|
85
97
|
assert_match(expected_message, @logger.logged(:info)[2])
|
86
98
|
end
|
87
99
|
end
|
data/test/log_subscriber_test.rb
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'test_helper'
|
2
|
-
require 'active_support/log_subscriber/test_helper'
|
3
2
|
|
4
3
|
describe SweetNotifications::LogSubscriber do
|
5
4
|
include ActiveSupport::LogSubscriber::TestHelper
|
6
5
|
|
7
6
|
def event(name: 'Test', duration: 1, transaction_id: SecureRandom.hex,
|
8
7
|
payload: {})
|
9
|
-
now = Time.
|
8
|
+
now = Time.current
|
10
9
|
ActiveSupport::Notifications::Event.new(name,
|
11
10
|
now,
|
12
11
|
now + duration,
|
@@ -136,15 +135,14 @@ describe SweetNotifications::LogSubscriber do
|
|
136
135
|
subject.colorize_logging = true
|
137
136
|
odd = subject.message(event, 'Label', 'body')
|
138
137
|
even = subject.message(event, 'Label', 'body')
|
139
|
-
assert
|
138
|
+
assert odd.exclude?(ActiveSupport::LogSubscriber::BOLD + 'body')
|
140
139
|
assert even.include?(ActiveSupport::LogSubscriber::BOLD + 'body')
|
141
140
|
end
|
142
141
|
|
143
142
|
it 'does not use colors when setting is disabled' do
|
144
143
|
subject.colorize_logging = false
|
145
144
|
message = subject.message(event, 'Label', 'body')
|
146
|
-
assert
|
145
|
+
assert message.exclude?(ActiveSupport::LogSubscriber::CYAN)
|
147
146
|
end
|
148
|
-
|
149
147
|
end
|
150
148
|
end
|
@@ -1,11 +1,35 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
+
class SweetNotificationsController < ActionController::Base
|
4
|
+
def index
|
5
|
+
ActiveSupport::Notifications.instrument 'test.controller' do
|
6
|
+
'ok'
|
7
|
+
end
|
8
|
+
|
9
|
+
if rails_version?('< 4.2')
|
10
|
+
render text: 'ok'
|
11
|
+
else
|
12
|
+
render plain: 'ok'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
3
17
|
describe SweetNotifications do
|
4
18
|
include ActiveSupport::LogSubscriber::TestHelper
|
19
|
+
tests SweetNotificationsController
|
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
|
5
28
|
|
6
29
|
describe '.subscribe' do
|
7
30
|
it 'creates a railtie' do
|
8
|
-
railtie,
|
31
|
+
railtie, = SweetNotifications.subscribe 'railtie_create' do
|
32
|
+
# empty block
|
9
33
|
end
|
10
34
|
assert railtie < Rails::Railtie
|
11
35
|
end
|
@@ -19,7 +43,7 @@ describe SweetNotifications do
|
|
19
43
|
end
|
20
44
|
|
21
45
|
it 'binds log subscriber to notifications' do
|
22
|
-
railtie,
|
46
|
+
railtie, = SweetNotifications.subscribe 'sweet' do
|
23
47
|
event :test do |event|
|
24
48
|
info message(event, 'Test', 'blah blah')
|
25
49
|
end
|
@@ -39,13 +63,14 @@ describe SweetNotifications do
|
|
39
63
|
end
|
40
64
|
end
|
41
65
|
|
42
|
-
railtie,
|
66
|
+
railtie, = SweetNotifications.subscribe 'sweet' do
|
43
67
|
event :direct do |event|
|
44
68
|
info message(event, 'Direct', 'foo bar')
|
45
69
|
end
|
46
70
|
end
|
47
71
|
|
48
|
-
|
72
|
+
assert_nil railtie
|
73
|
+
|
49
74
|
module ::Rails
|
50
75
|
class << self
|
51
76
|
undef application
|
@@ -56,5 +81,20 @@ describe SweetNotifications do
|
|
56
81
|
end
|
57
82
|
assert_match(/Direct \(\d\.\d{2}ms\) foo bar/, @logger.logged(:info)[0])
|
58
83
|
end
|
84
|
+
|
85
|
+
it 'logs to Rails logger' do
|
86
|
+
railtie, = SweetNotifications.subscribe 'controller', label: 'Label' do
|
87
|
+
event :test, runtime: true do |event|
|
88
|
+
info message(event, 'Test', 'logging')
|
89
|
+
end
|
90
|
+
end
|
91
|
+
railtie.run_initializers
|
92
|
+
|
93
|
+
get :index
|
94
|
+
wait
|
95
|
+
assert_match(/Test \(\d\.\d{2}ms\) logging/, @logger.logged(:info)[0])
|
96
|
+
out = ActionController::Base.log_process_action(label_runtime: 1234)
|
97
|
+
assert_match(/Label: 1234\.0ms/, out[0])
|
98
|
+
end
|
59
99
|
end
|
60
100
|
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'
|
@@ -11,27 +11,50 @@ require 'minitest/spec'
|
|
11
11
|
require 'minitest/pride'
|
12
12
|
require 'sweet_notifications'
|
13
13
|
require 'active_support/test_case'
|
14
|
+
require 'action_controller'
|
15
|
+
require 'active_support/log_subscriber/test_helper'
|
16
|
+
require 'active_support/core_ext/string'
|
14
17
|
require 'securerandom'
|
15
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
|
+
|
16
27
|
class ActiveSupport::TestCase
|
17
28
|
class << self
|
18
|
-
remove_method :describe
|
29
|
+
remove_method :describe if method_defined? :describe
|
19
30
|
end
|
20
31
|
|
21
32
|
extend MiniTest::Spec::DSL
|
33
|
+
register_spec_type(/SweetNotifications$/, ActionController::TestCase)
|
22
34
|
register_spec_type(/ControllerRuntime$/, ActionController::TestCase)
|
23
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
|
24
42
|
end
|
25
43
|
|
26
44
|
module ActionController
|
45
|
+
extend RailsVersion
|
27
46
|
TestRoutes = ActionDispatch::Routing::RouteSet.new
|
28
|
-
|
29
|
-
|
47
|
+
|
48
|
+
if rails_version?('< 5.0')
|
49
|
+
TestRoutes.draw do
|
50
|
+
match ':controller(/:action)', via: [:all]
|
51
|
+
end
|
30
52
|
end
|
31
53
|
|
32
54
|
class Base
|
33
55
|
include ActionController::Testing
|
34
56
|
include TestRoutes.url_helpers
|
57
|
+
include RailsVersion
|
35
58
|
end
|
36
59
|
|
37
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.0
|
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: 2020-11-08 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,19 @@ 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_head.gemfile
|
186
202
|
- lib/sweet_notifications.rb
|
187
203
|
- lib/sweet_notifications/controller_runtime.rb
|
188
204
|
- lib/sweet_notifications/log_subscriber.rb
|
@@ -198,7 +214,7 @@ homepage: https://github.com/lautis/sweet_notifications
|
|
198
214
|
licenses:
|
199
215
|
- MIT
|
200
216
|
metadata: {}
|
201
|
-
post_install_message:
|
217
|
+
post_install_message:
|
202
218
|
rdoc_options: []
|
203
219
|
require_paths:
|
204
220
|
- lib
|
@@ -206,16 +222,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
206
222
|
requirements:
|
207
223
|
- - "~>"
|
208
224
|
- !ruby/object:Gem::Version
|
209
|
-
version: '2.
|
225
|
+
version: '2.5'
|
210
226
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
227
|
requirements:
|
212
228
|
- - ">="
|
213
229
|
- !ruby/object:Gem::Version
|
214
230
|
version: '0'
|
215
231
|
requirements: []
|
216
|
-
|
217
|
-
|
218
|
-
signing_key:
|
232
|
+
rubygems_version: 3.1.2
|
233
|
+
signing_key:
|
219
234
|
specification_version: 4
|
220
235
|
summary: Syntactic sugar for ActiveSupport::LogSubscriber.
|
221
236
|
test_files:
|
@@ -224,4 +239,3 @@ test_files:
|
|
224
239
|
- test/railtie_test.rb
|
225
240
|
- test/sweet_notifications_test.rb
|
226
241
|
- test/test_helper.rb
|
227
|
-
has_rdoc:
|