Commit dbf8a5e 1 parent aac227e commit dbf8a5e Copy full SHA for dbf8a5e
File tree 3 files changed +16
-5
lines changed
3 files changed +16
-5
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ def http_status_code
37
37
# API.
38
38
#
39
39
# @param errors [Apia::ManifestErrors]
40
- # @reeturn [void]
40
+ # @return [void]
41
41
def validate ( errors )
42
42
unless code . is_a? ( Symbol )
43
43
errors . add self , 'InvalidCode' , 'Code must be a symbol'
Original file line number Diff line number Diff line change @@ -70,11 +70,14 @@ def body
70
70
#
71
71
# @return [Array]
72
72
def rack_triplet
73
- case @type
74
- when JSON
75
- Rack . json_triplet ( body , headers : headers , status : status )
76
- when PLAIN
73
+ # Errors will always be sent as a hash intended for JSON encoding,
74
+ # even if the endpoint specifies a plain text response, so only
75
+ # send a pain response if the type is plaintext _and_ the body is
76
+ # a string
77
+ if @type == PLAIN && body . is_a? ( String )
77
78
Rack . plain_triplet ( body , headers : headers , status : status )
79
+ else
80
+ Rack . json_triplet ( body , headers : headers , status : status )
78
81
end
79
82
end
80
83
Original file line number Diff line number Diff line change 135
135
expect ( response . rack_triplet [ 2 ] [ 0 ] ) . to eq 'hello world'
136
136
expect ( response . rack_triplet [ 1 ] [ 'content-length' ] ) . to eq '11'
137
137
end
138
+
139
+ it 'should return JSON if the body is not a string' do
140
+ response = Apia ::Response . new ( request , endpoint )
141
+ response . body = { hello : 'world' }
142
+ expect ( response . rack_triplet [ 1 ] [ 'content-type' ] ) . to eq 'application/json'
143
+ expect ( response . rack_triplet [ 1 ] [ 'content-length' ] ) . to eq '17'
144
+ expect ( response . rack_triplet [ 2 ] [ 0 ] ) . to eq '{"hello":"world"}'
145
+ end
138
146
end
139
147
140
148
context 'with a legacy plain text response' do
You can’t perform that action at this time.
0 commit comments