sweet_notifications 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1c1adad5429dc0a8d3ec40a499531b9fabacc9b5
4
- data.tar.gz: 360d747cf1d39ac6bfc3c9583e87adcf110d0f03
3
+ metadata.gz: b10b735828800811baddaaf6234ccde5d4825d0c
4
+ data.tar.gz: f4a229a8c82c4fbd5d098cae36c945d32fe78c43
5
5
  SHA512:
6
- metadata.gz: 1e20abf7323c1ccc38984ff3b03105503c8e1e96025d54c3cb0ea23d8de015164923a6c8076f1bbc649b4f1d365bc167a3687a4dc92f96ee2b6724805d8ffd1a
7
- data.tar.gz: 2019786e91f894fbb984e351f1d996da0f8b78c3b694026ba8aacee5d213fd50a14a6e541d2416372fb29a345816801383c060065943fe6905c892506a86190d
6
+ metadata.gz: 46055d7192e980297c47042fd7c0d72a86e9c97fac56b02befc39055f7cfea05537fe79de7876e52406f03fea4bc309bff5035720a9492b0931ca0b5b12a24c7
7
+ data.tar.gz: 9244a85530d1b16dcb7ade6b656986f9a699d70c25d02a3fd2aaefde9b77efb81c64611c637df3f730116286ab8e092f9b255ad823da60a0bf401b5118aeda3f
data/Rakefile CHANGED
@@ -13,6 +13,6 @@ YARD::Rake::YardocTask.new do |t|
13
13
  end
14
14
 
15
15
  desc 'Check for code style'
16
- Rubocop::RakeTask.new
16
+ RuboCop::RakeTask.new
17
17
 
18
18
  task default: [:test, :rubocop]
@@ -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,9 +30,10 @@ 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(name, log_subscriber)
36
+ controller_runtime = self.controller_runtime(label, log_subscriber)
35
37
  if Rails.try(:application).try(:initialized?)
36
38
  initialize_rails(name, log_subscriber, controller_runtime)
37
39
  [nil, log_subscriber]
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SweetNotifications
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -30,5 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "yard", "~> 0.8.7"
31
31
  spec.add_development_dependency "appraisal", "~> 1.0"
32
32
  spec.add_development_dependency "simplecov", "~> 0.8.2"
33
- spec.add_development_dependency "rubocop", "~> 0.22.0"
33
+ spec.add_development_dependency "rubocop", "~> 0.23.0"
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
@@ -1,5 +1,4 @@
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
@@ -1,7 +1,17 @@
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
+ render nothing: true
9
+ end
10
+ end
11
+
3
12
  describe SweetNotifications do
4
13
  include ActiveSupport::LogSubscriber::TestHelper
14
+ tests SweetNotificationsController
5
15
 
6
16
  describe '.subscribe' do
7
17
  it 'creates a railtie' do
@@ -56,5 +66,20 @@ describe SweetNotifications do
56
66
  end
57
67
  assert_match(/Direct \(\d\.\d{2}ms\) foo bar/, @logger.logged(:info)[0])
58
68
  end
69
+
70
+ it 'logs to Rails logger' do
71
+ railtie, _ = SweetNotifications.subscribe 'controller', label: 'Label' do
72
+ event :test, runtime: true do |event|
73
+ info message(event, 'Test', 'logging')
74
+ end
75
+ end
76
+ railtie.run_initializers
77
+
78
+ get :index
79
+ wait
80
+ assert_match(/Test \(\d\.\d{2}ms\) logging/, @logger.logged(:info)[0])
81
+ out = ActionController::Base.log_process_action(label_runtime: 1234)
82
+ assert_match(/Label: 1234\.0ms/, out[0])
83
+ end
59
84
  end
60
85
  end
@@ -11,6 +11,8 @@ 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'
14
16
  require 'securerandom'
15
17
 
16
18
  class ActiveSupport::TestCase
@@ -19,6 +21,7 @@ class ActiveSupport::TestCase
19
21
  end
20
22
 
21
23
  extend MiniTest::Spec::DSL
24
+ register_spec_type(/SweetNotifications$/, ActionController::TestCase)
22
25
  register_spec_type(/ControllerRuntime$/, ActionController::TestCase)
23
26
  register_spec_type(self)
24
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sweet_notifications
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ville Lautanala
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-08 00:00:00.000000000 Z
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -156,14 +156,14 @@ dependencies:
156
156
  requirements:
157
157
  - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: 0.22.0
159
+ version: 0.23.0
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: 0.22.0
166
+ version: 0.23.0
167
167
  description: Syntactic sugar for ActiveSupport::LogSubscriber for easy instrumentation
168
168
  and logging from third-party libraries.
169
169
  email: