grape-middleware-logger 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fff85131fb1c55207dcfe522acde1ad666839cc8
|
4
|
+
data.tar.gz: fc6f65023b7645ac2ba0b48aba20739d07b1b60a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b984cb11a87cfbad641f934b2c336e1305dbb18880657012c6f2447329bb95350c528db6bdbdd01c4112a5de3275fe5c31d6edd31cb82e4ac25736aee8c6e04
|
7
|
+
data.tar.gz: b73d0d4cc26d63b2351e0058e7075fb74b140b46d982d24f73acd4ee8176f77d388cc94cdf031fde4069e76e0c8aeddf21341aa2b51b9be3d9abfade7e9b8545
|
@@ -9,9 +9,17 @@ module Grape
|
|
9
9
|
# Overrides
|
10
10
|
#
|
11
11
|
|
12
|
+
def before
|
13
|
+
@start_time = Time.now
|
14
|
+
super
|
15
|
+
logger.info ''
|
16
|
+
logger.info %Q(Started #{env['grape.request'].request_method} "#{env['grape.request'].path}")
|
17
|
+
logger.info %Q( Parameters: #{parameters})
|
18
|
+
end
|
19
|
+
|
12
20
|
def call!(env)
|
13
21
|
@env = env
|
14
|
-
|
22
|
+
before
|
15
23
|
error = catch(:error) { @app_response = @app.call(@env); nil }
|
16
24
|
if error
|
17
25
|
after_failure(error)
|
@@ -31,14 +39,6 @@ module Grape
|
|
31
39
|
# Helpers
|
32
40
|
#
|
33
41
|
|
34
|
-
# @todo rename to +before+ when Grape v0.12.0 is released
|
35
|
-
def _before
|
36
|
-
@start_time = Time.now
|
37
|
-
logger.info ''
|
38
|
-
logger.info %Q(Started #{env['grape.request'].request_method} "#{env['grape.request'].path}")
|
39
|
-
logger.info %Q( Parameters: #{parameters})
|
40
|
-
end
|
41
|
-
|
42
42
|
def after_failure(error)
|
43
43
|
logger.info %Q( Error: #{error[:message]}) if error[:message]
|
44
44
|
after(error[:status])
|
@@ -20,13 +20,16 @@ describe Grape::Middleware::Logger do
|
|
20
20
|
}
|
21
21
|
}
|
22
22
|
}
|
23
|
+
# @todo remove when Grape v0.12.0 is released
|
24
|
+
before(:each) { allow(subject).to receive(:before) }
|
25
|
+
|
23
26
|
describe '#call!' do
|
24
27
|
context 'when calling the app results in an error response' do
|
25
28
|
let(:error) { { status: 400 } }
|
26
29
|
|
27
30
|
it 'calls +after_failure+ and rethrows the error' do
|
28
31
|
expect(app).to receive(:call).with(env).and_throw(:error, error)
|
29
|
-
expect(subject).to receive(:
|
32
|
+
expect(subject).to receive(:before)
|
30
33
|
expect(subject).to receive(:after_failure).with(error)
|
31
34
|
expect(subject).to receive(:throw).with(:error, error)
|
32
35
|
subject.call!(env)
|
@@ -36,21 +39,21 @@ describe Grape::Middleware::Logger do
|
|
36
39
|
context 'when there is no error' do
|
37
40
|
it 'calls +after+ with the correct status' do
|
38
41
|
expect(app).to receive(:call).with(env).and_return(app_response)
|
39
|
-
expect(subject).to receive(:
|
42
|
+
expect(subject).to receive(:before)
|
40
43
|
expect(subject).to receive(:after).with(200)
|
41
44
|
subject.call!(env)
|
42
45
|
end
|
43
46
|
|
44
47
|
it 'returns the @app_response' do
|
45
48
|
expect(app).to receive(:call).with(env).and_return(app_response)
|
46
|
-
allow(subject).to receive(:
|
49
|
+
allow(subject).to receive(:before)
|
47
50
|
allow(subject).to receive(:after)
|
48
51
|
expect(subject.call!(env)).to eq app_response
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
52
55
|
describe 'integration' do
|
53
|
-
it 'properly logs requests' do
|
56
|
+
it 'properly logs requests', pending: 'Grape v0.12.0' do
|
54
57
|
expect(app).to receive(:call).with(env).and_return(app_response)
|
55
58
|
expect(subject.logger).to receive(:info).with('')
|
56
59
|
expect(subject.logger).to receive(:info).with(%Q(Started POST "/api/1.0/users"))
|