coach 0.4.5 → 0.4.6

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: ee62dd79b30b026f6b147715cfd69e5a06b0dab0
4
- data.tar.gz: 7dea56a9d5e873925093698fee383b800e62d82d
3
+ metadata.gz: e57234c99f6622d05b93fed13fb589250cab7082
4
+ data.tar.gz: 950d40743209a397c5509438b2056a9aa06e16ce
5
5
  SHA512:
6
- metadata.gz: 4229b86085230cc2e464f8e02aca5cf8a3723964a36e59d63d6595fca067fff9a687559595c41bfae1bf08e3aca046cddc10599ad146448d7cb45ef2c1b3a9c3
7
- data.tar.gz: 1ba51dd6d4fb775e834ed94dbda5e0b372313c6d8d0890221b2ab462f7c34dc3c9000bd19ef79748e62408547b0658b5b3151e61c26851138c7779504caed4f2
6
+ metadata.gz: 926d433306e25f0aba99f433a491b135e17405da467b5baaf36466d96929aeb7fc42204321b88ca74855e1a01dbe7f158b16474cfe905ce6ba3a3a259f2a93f1
7
+ data.tar.gz: 1b79b97214372ffa5411cd6c94d165af8efee424a4cf3542b0e91755ea34bac765d1f9873ad4e1584dd2f02ca4f17cf8f9557e958cbe1b71838792b4f67ab49f
@@ -4,27 +4,14 @@
4
4
  LineLength:
5
5
  Max: 90
6
6
 
7
- ClassLength:
8
- Enabled: false
9
-
10
- ModuleLength:
11
- Enabled: false
12
-
13
7
  # Avoid methods longer than 30 lines of code
14
8
  MethodLength:
15
9
  CountComments: false # count full line comments?
16
- Max: 87
17
-
18
- # Avoid single-line methods.
19
- SingleLineMethods:
20
- AllowIfMethodIsEmpty: true
10
+ Max: 16
21
11
 
22
12
  StringLiterals:
23
13
  Enabled: false
24
14
 
25
- GlobalVars:
26
- Enabled: false # We use them Redis + StatsD (though maybe we shouldn't?)
27
-
28
15
  # Wants underscores in all large numbers. Pain in the ass for things like
29
16
  # unix timestamps.
30
17
  NumericLiterals:
@@ -39,7 +26,7 @@ Style/SignalException:
39
26
  EnforcedStyle: 'only_raise'
40
27
 
41
28
  # Use trailing rather than leading dots on multi-line call chains
42
- Style/DotPosition:
29
+ Layout/DotPosition:
43
30
  EnforcedStyle: trailing
44
31
 
45
32
  Lint/NestedMethodDefinition:
@@ -65,7 +52,7 @@ Style/AsciiComments:
65
52
  Enabled: false
66
53
 
67
54
  # Configuration parameters: EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle, SupportedLastArgumentHashStyles.
68
- Style/AlignHash:
55
+ Layout/AlignHash:
69
56
  Enabled: false
70
57
 
71
58
  # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
@@ -76,7 +63,7 @@ Style/BlockDelimiters:
76
63
  Style/ClassAndModuleChildren:
77
64
  Enabled: false
78
65
 
79
- Style/ClosingParenthesisIndentation:
66
+ Layout/ClosingParenthesisIndentation:
80
67
  Enabled: false
81
68
 
82
69
  # Configuration parameters: Keywords.
@@ -94,14 +81,14 @@ Style/GuardClause:
94
81
  Enabled: false
95
82
 
96
83
  # Configuration parameters: EnforcedStyle, SupportedStyles.
97
- Style/IndentHash:
84
+ Layout/IndentHash:
98
85
  Enabled: false
99
86
 
100
87
  Style/Lambda:
101
88
  Enabled: false
102
89
 
103
90
  # Configuration parameters: EnforcedStyle, SupportedStyles.
104
- Style/MultilineOperationIndentation:
91
+ Layout/MultilineOperationIndentation:
105
92
  Enabled: false
106
93
 
107
94
  # Configuration parameters: NamePrefix, NamePrefixBlacklist.
@@ -111,13 +98,17 @@ Style/PredicateName:
111
98
  Style/RedundantSelf:
112
99
  Enabled: false
113
100
 
114
- Style/SpaceBeforeFirstArg:
101
+ Layout/SpaceBeforeFirstArg:
115
102
  Enabled: false
116
103
 
117
104
  # Configuration parameters: MultiSpaceAllowedForOperators.
118
- Style/SpaceAroundOperators:
105
+ Layout/SpaceAroundOperators:
119
106
  Enabled: false
120
107
 
121
108
  # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist.
122
109
  Style/TrivialAccessors:
123
110
  Enabled: false
111
+
112
+ Metrics/BlockLength:
113
+ Exclude:
114
+ - "**/*_spec.rb"
@@ -1,3 +1,10 @@
1
+ # Unreleased changes
2
+
3
+ # 0.4.6
4
+
5
+ * [https://github.com/gocardless/coach/pull/22](#22) Publish ActiveSupport notifications
6
+ even on errors
7
+
1
8
  # 0.4.5 / 2017-04-26
2
9
 
3
10
  * [https://github.com/gocardless/coach/pull/17] Only require rspec/expectations
data/README.md CHANGED
@@ -152,6 +152,7 @@ class Logger < Coach::Middleware
152
152
  def call
153
153
  # Logs the incoming request path, with a configured prefix
154
154
  Rails.logger.info("[#{config[:prefix]}] - #{request.path}")
155
+ next_middleware.call
155
156
  end
156
157
  end
157
158
 
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'coach/version'
@@ -8,9 +9,9 @@ Gem::Specification.new do |spec|
8
9
  spec.version = Coach::VERSION
9
10
  spec.summary = 'coach middleware'
10
11
  spec.description = 'Controller framework'
11
- spec.authors = %w(GoCardless)
12
+ spec.authors = %w[GoCardless]
12
13
  spec.homepage = "https://github.com/gocardless/coach"
13
- spec.email = %w(developers@gocardless.com)
14
+ spec.email = %w[developers@gocardless.com]
14
15
  spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files -z`.split("\x0")
@@ -23,5 +24,5 @@ Gem::Specification.new do |spec|
23
24
  spec.add_development_dependency 'rspec', '~> 3.2'
24
25
  spec.add_development_dependency 'rspec-its', '~> 1.2'
25
26
  spec.add_development_dependency 'pry', '~> 0.10'
26
- spec.add_development_dependency 'rubocop', '~> 0.32.0'
27
+ spec.add_development_dependency 'rubocop', '~> 0.49.1'
27
28
  end
@@ -2,6 +2,8 @@ require "coach/errors"
2
2
 
3
3
  module Coach
4
4
  class Handler
5
+ STATUS_CODE_FOR_EXCEPTIONS = 500
6
+
5
7
  def initialize(middleware, config = {})
6
8
  @root_item = MiddlewareItem.new(middleware, config)
7
9
  validate!
@@ -25,16 +27,17 @@ module Coach
25
27
  start = Time.now
26
28
 
27
29
  publish('coach.handler.start', start_event.dup)
28
- response = chain.instrument.call
29
-
30
- finish = Time.now
31
- publish('coach.handler.finish',
32
- start, finish, nil,
33
- start_event.
34
- merge(response: { status: response[0] },
35
- metadata: context.fetch(:_metadata, {})))
36
30
 
37
- response
31
+ begin
32
+ response = chain.instrument.call
33
+ ensure
34
+ status = response.try(:first) || STATUS_CODE_FOR_EXCEPTIONS
35
+ publish('coach.handler.finish', start, Time.now, nil,
36
+ start_event.merge(
37
+ response: { status: status },
38
+ metadata: context.fetch(:_metadata, {})
39
+ ))
40
+ end
38
41
  end
39
42
 
40
43
  # Traverse the middlware tree to build a linear middleware sequence,
@@ -32,11 +32,11 @@ module Coach
32
32
  @benchmarks[event[:request].uuid] = RequestBenchmark.new(event[:middleware])
33
33
  end
34
34
 
35
- @subscriptions << subscribe('middleware.finish') do |name, start, finish, _, event|
35
+ @subscriptions << subscribe('middleware.finish') do |_name, start, finish, _, event|
36
36
  log_middleware_finish(event, start, finish)
37
37
  end
38
38
 
39
- @subscriptions << subscribe('handler.finish') do |name, start, finish, _, event|
39
+ @subscriptions << subscribe('handler.finish') do |_name, start, finish, _, event|
40
40
  log_handler_finish(event, start, finish)
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Coach
2
- VERSION = '0.4.5'.freeze
2
+ VERSION = '0.4.6'.freeze
3
3
  end
@@ -26,7 +26,7 @@ describe Coach::Handler do
26
26
  result = handler.call({})
27
27
  expect(a_spy).to have_received(:call)
28
28
  expect(b_spy).to have_received(:call)
29
- expect(result).to eq(%w(A{} B{} Terminal{:handler=>true}))
29
+ expect(result).to eq(%w[A{} B{} Terminal{:handler=>true}])
30
30
  end
31
31
  end
32
32
 
@@ -94,7 +94,7 @@ describe Coach::Handler do
94
94
 
95
95
  it "sets up the chain correctly, calling each item in the correct order" do
96
96
  expect(handler.build_request_chain(sequence, {}).call).
97
- to eq(%w(A{} B{:b=>true} Terminal{}))
97
+ to eq(%w[A{} B{:b=>true} Terminal{}])
98
98
  end
99
99
 
100
100
  context "with inheriting config" do
@@ -103,7 +103,7 @@ describe Coach::Handler do
103
103
 
104
104
  it "calls lambda with parent middlewares config" do
105
105
  expect(handler.build_request_chain(sequence, {}).call).
106
- to eq(%w(A{} C{:b=>true} D{} B{:b=>true} Terminal{}))
106
+ to eq(%w[A{} C{:b=>true} D{} B{:b=>true} Terminal{}])
107
107
  end
108
108
  end
109
109
  end
@@ -137,6 +137,38 @@ describe Coach::Handler do
137
137
  it { is_expected.to include('coach.request') }
138
138
  it { is_expected.to include('coach.middleware.finish') }
139
139
  it { is_expected.to include('coach.handler.finish') }
140
+
141
+ context "when an exception is raised in the chain" do
142
+ let(:explosive_action) { -> { raise "AH" } }
143
+ before { terminal_middleware.uses(middleware_a, callback: explosive_action) }
144
+
145
+ subject(:coach_events) do
146
+ events = []
147
+ subscription = ActiveSupport::Notifications.subscribe(/coach/) do |name, *args|
148
+ events << [name, args.last]
149
+ end
150
+
151
+ begin
152
+ handler.call({})
153
+ rescue
154
+ :continue_anyway
155
+ end
156
+ ActiveSupport::Notifications.unsubscribe(subscription)
157
+ events
158
+ end
159
+
160
+ it "should capture the error event with the metadata " do
161
+ is_expected.
162
+ to include(['coach.handler.finish', hash_including(
163
+ response: { status: 500 },
164
+ metadata: { A: true }
165
+ )])
166
+ end
167
+
168
+ it "should bubble the error to the next handler" do
169
+ expect { handler.call({}) }.to raise_error(StandardError, "AH")
170
+ end
171
+ end
140
172
  end
141
173
  end
142
174
 
@@ -53,7 +53,7 @@ describe Coach::Notifications do
53
53
 
54
54
  it "contains all middleware that have been run" do
55
55
  middleware_names = middleware_event[:chain].map { |item| item[:name] }
56
- expect(middleware_names).to include(*%w(Terminal A B))
56
+ expect(middleware_names).to include('Terminal', 'A', 'B')
57
57
  end
58
58
 
59
59
  it "includes all logged metadata" do
@@ -36,7 +36,7 @@ describe Coach::RequestBenchmark do
36
36
 
37
37
  it "correctly orders chain" do
38
38
  chain_names = stats[:chain].map { |item| item[:name] }
39
- expect(chain_names).to eq %w(A B)
39
+ expect(chain_names).to eq %w[A B]
40
40
  end
41
41
  end
42
42
  end
@@ -13,7 +13,7 @@ describe Coach::Router do
13
13
 
14
14
  let(:resource_routes) do
15
15
  routes_module = Module.new
16
- [:Index, :Show, :Create, :Update, :Destroy, :Refund].each do |class_name|
16
+ %i[Index Show Create Update Destroy Refund].each do |class_name|
17
17
  routes_module.const_set(class_name, Class.new)
18
18
  end
19
19
  routes_module
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coach
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-26 00:00:00.000000000 Z
11
+ date: 2017-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.32.0
89
+ version: 0.49.1
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.32.0
96
+ version: 0.49.1
97
97
  description: Controller framework
98
98
  email:
99
99
  - developers@gocardless.com
@@ -149,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  requirements: []
151
151
  rubyforge_project:
152
- rubygems_version: 2.6.8
152
+ rubygems_version: 2.6.11
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: coach middleware