File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ def call!(env)
27
27
ensure
28
28
after_response = after
29
29
end
30
- after_response || @app_response
30
+ is_response_valid? ( after_response ) ? after_response : @app_response
31
31
end
32
32
33
33
# @abstract
@@ -65,6 +65,17 @@ def mime_types
65
65
end
66
66
types_without_params
67
67
end
68
+
69
+ def is_response_valid? ( response )
70
+ if response . is_a? ( Array )
71
+ status , headers , body = *response
72
+ ( status >= 100 && status < 600 ) && ( headers . is_a? ( Hash ) ) && body . respond_to? ( :each )
73
+ else
74
+ response . is_a? ( Rack ::Response )
75
+ end
76
+ rescue
77
+ false
78
+ end
68
79
end
69
80
end
70
81
end
Original file line number Diff line number Diff line change 40
40
41
41
context 'after callback' do
42
42
before do
43
- allow ( subject ) . to receive ( :after ) . and_return ( [ 200 , { } , 'Hello from after callback' ] )
43
+ allow ( subject ) . to receive ( :after ) . and_return ( [ 200 , { } , [ 'Hello from after callback' ] ] )
44
44
end
45
45
46
46
it 'overwrites application response' do
47
- expect ( subject . call! ( { } ) . last ) . to eq ( 'Hello from after callback' )
47
+ expect ( subject . call! ( { } ) . last ) . to eq ( [ 'Hello from after callback' ] )
48
+ end
49
+ end
50
+
51
+ context 'after callback with invalid response' do
52
+ before do
53
+ allow ( subject ) . to receive ( :after ) . and_return ( 'invalid response' )
54
+ end
55
+
56
+ it 'does not overwrite application response' do
57
+ expect ( subject . call! ( { } ) . last ) . to eq ( 'Hi there.' )
48
58
end
49
59
end
50
60
You can’t perform that action at this time.
0 commit comments