use +before+ because it works on Grape master
This commit is contained in:
parent
d65714ffd8
commit
4cac0e0ac0
|
@ -9,9 +9,17 @@ module Grape
|
|||
# Overrides
|
||||
#
|
||||
|
||||
def before
|
||||
@start_time = Time.now
|
||||
super
|
||||
logger.info ''
|
||||
logger.info %Q(Started #{env['grape.request'].request_method} "#{env['grape.request'].path}")
|
||||
logger.info %Q( Parameters: #{parameters})
|
||||
end
|
||||
|
||||
def call!(env)
|
||||
@env = env
|
||||
_before
|
||||
before
|
||||
error = catch(:error) { @app_response = @app.call(@env); nil }
|
||||
if error
|
||||
after_failure(error)
|
||||
|
@ -31,14 +39,6 @@ module Grape
|
|||
# Helpers
|
||||
#
|
||||
|
||||
# @todo rename to +before+ when Grape v0.12.0 is released
|
||||
def _before
|
||||
@start_time = Time.now
|
||||
logger.info ''
|
||||
logger.info %Q(Started #{env['grape.request'].request_method} "#{env['grape.request'].path}")
|
||||
logger.info %Q( Parameters: #{parameters})
|
||||
end
|
||||
|
||||
def after_failure(error)
|
||||
logger.info %Q( Error: #{error[:message]}) if error[:message]
|
||||
after(error[:status])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
module Grape
|
||||
module Middleware
|
||||
class Logger
|
||||
VERSION = '0.1.0'
|
||||
VERSION = '0.1.1'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,13 +20,16 @@ describe Grape::Middleware::Logger do
|
|||
}
|
||||
}
|
||||
}
|
||||
# @todo remove when Grape v0.12.0 is released
|
||||
before(:each) { allow(subject).to receive(:before) }
|
||||
|
||||
describe '#call!' do
|
||||
context 'when calling the app results in an error response' do
|
||||
let(:error) { { status: 400 } }
|
||||
|
||||
it 'calls +after_failure+ and rethrows the error' do
|
||||
expect(app).to receive(:call).with(env).and_throw(:error, error)
|
||||
expect(subject).to receive(:_before)
|
||||
expect(subject).to receive(:before)
|
||||
expect(subject).to receive(:after_failure).with(error)
|
||||
expect(subject).to receive(:throw).with(:error, error)
|
||||
subject.call!(env)
|
||||
|
@ -36,21 +39,21 @@ describe Grape::Middleware::Logger do
|
|||
context 'when there is no error' do
|
||||
it 'calls +after+ with the correct status' do
|
||||
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(200)
|
||||
subject.call!(env)
|
||||
end
|
||||
|
||||
it 'returns the @app_response' do
|
||||
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)
|
||||
expect(subject.call!(env)).to eq app_response
|
||||
end
|
||||
end
|
||||
|
||||
describe 'integration' do
|
||||
it 'properly logs requests' do
|
||||
it 'properly logs requests', pending: 'Grape v0.12.0' do
|
||||
expect(app).to receive(:call).with(env).and_return(app_response)
|
||||
expect(subject.logger).to receive(:info).with('')
|
||||
expect(subject.logger).to receive(:info).with(%Q(Started POST "/api/1.0/users"))
|
||||
|
|
Loading…
Reference in New Issue