Refactor logger conditional to use coercion and parallel assignment
This commit is contained in:
parent
e6e06556aa
commit
7969c9daca
|
@ -55,13 +55,8 @@ class Grape::Middleware::Logger < Grape::Middleware::Globals
|
||||||
after_failure(error)
|
after_failure(error)
|
||||||
throw(:error, error)
|
throw(:error, error)
|
||||||
else
|
else
|
||||||
# Usually a rack response object is returned: https://github.com/ruby-grape/grape/blob/master/UPGRADING.md#changes-in-middleware
|
status, _, _ = *@app_response
|
||||||
# However, rack/auth/abstract/handler.rb still returns an array instead of a rack response object.
|
after(status)
|
||||||
if @app_response.is_a?(Array)
|
|
||||||
after(@app_response[0])
|
|
||||||
else
|
|
||||||
after(@app_response.status)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
@app_response
|
@app_response
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,20 +40,20 @@ describe Grape::Middleware::Logger do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when calling the app results in an array response' do
|
context 'when calling the app results in an array response' do
|
||||||
let(:app_response_array) { [401, {}, []] }
|
let(:app_response) { [401, {}, []] }
|
||||||
|
|
||||||
it 'calls +after+ with the correct status' do
|
it 'calls +after+ with the correct status' do
|
||||||
expect(app).to receive(:call).with(env).and_return(app_response_array)
|
expect(app).to receive(:call).with(env).and_return(app_response)
|
||||||
expect(subject).to receive(:before)
|
expect(subject).to receive(:before)
|
||||||
expect(subject).to receive(:after).with(401)
|
expect(subject).to receive(:after).with(401)
|
||||||
subject.call!(env)
|
subject.call!(env)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns the @app_response' do
|
it 'returns the @app_response' do
|
||||||
expect(app).to receive(:call).with(env).and_return(app_response_array)
|
expect(app).to receive(:call).with(env).and_return(app_response)
|
||||||
allow(subject).to receive(:before)
|
allow(subject).to receive(:before)
|
||||||
allow(subject).to receive(:after)
|
allow(subject).to receive(:after)
|
||||||
expect(subject.call!(env)).to eq app_response_array
|
expect(subject.call!(env)).to eq app_response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue