Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
handle nil responses
Browse files Browse the repository at this point in the history
  • Loading branch information
bartes committed Dec 27, 2018
1 parent ac16cff commit fa0713f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/castle/middleware/authenticating.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ def call(env)

# [status, headers, body]
app_result = app.call(env)
status, headers = app_result
return app_result if app_result.nil?

# Find a matching event from the config
mapping = @event_mapping.find_by_rack_request(app_result[0].to_s, path, app_result[1], req, true).first
mapping = @event_mapping.find_by_rack_request(status.to_s, path, headers, req, true).first

return app_result if mapping.nil?

Expand Down
1 change: 0 additions & 1 deletion lib/castle/middleware/sensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def initialize(app)

def call(env)
app_result = app.call(env)

status, headers, body = app_result

return app_result unless qualify_for_adding_cjs?(status, headers)
Expand Down
4 changes: 3 additions & 1 deletion lib/castle/middleware/tracking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ def call(env)

# [status, headers, body]
app_result = app.call(env)
status, headers = app_result
return app_result if app_result.nil?

# Find a matching track event from the config
mappings = @event_mapping.find_by_rack_request(app_result[0].to_s, path, app_result[1], req, false)
mappings = @event_mapping.find_by_rack_request(status.to_s, path, headers, req, false)

mappings.each do |mapping|
resource ||= configuration.services.provide_user.call(req, true)
Expand Down
7 changes: 7 additions & 0 deletions spec/castle/middleware/authenticating_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def params
allow(::Castle::Middleware::PropertiesProvide).to receive(:call).and_return(properties_provide)
end

context 'when response is nil' do
let(:response) { nil }
let(:mapping) { spy }

it { expect(call).to be(nil) }
end

context 'when a mapping exists' do
let(:mapping) { spy }

Expand Down
6 changes: 6 additions & 0 deletions spec/castle/middleware/sensor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def xhr?
describe '#call' do
subject { described_class.new(app).call(env) }

context 'when response is nil' do
let(:response) { nil }

it { is_expected.to be(nil) }
end

context 'with HTML body' do
let(:status) { 200 }
let(:user) { nil }
Expand Down
7 changes: 7 additions & 0 deletions spec/castle/middleware/tracking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def path
allow(::Castle::Middleware::PropertiesProvide).to receive(:call).and_return(properties_provide)
end

context 'when response is nil' do
let(:response) { nil }
let(:mapping) { spy }

it { expect(call).to be(nil) }
end

context 'when a mapping exists' do
let(:mapping) { spy }

Expand Down

0 comments on commit fa0713f

Please sign in to comment.