ddy_remote_resource 1.0.0.rc4 → 1.0.0.rc5
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: d688cecc3f4a1d713c2527d47a99cf88f81c9bfb
|
4
|
+
data.tar.gz: 11a9c8c67d6ed14e4aa46dd9de09079204ca0507
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc32aaed683143cf08c8a96b80adcf41d98a369cd7313ae1eabf9a527a0c9e861f41d468621b1518582d686593e097ce8e27209ae2ddbfbeaacb53cd0c4779aa
|
7
|
+
data.tar.gz: 1e47f7498e9f70cff6b708d73f1e1af8189e88c3c50b422989c33abecdec0beb7ac733877d244b9b5283ba65b508dd96997d085a5f02dd1db33e3db17c629578
|
@@ -45,7 +45,7 @@ module RemoteResource
|
|
45
45
|
root_element = @connection_options[:root_element]
|
46
46
|
|
47
47
|
if root_element.present?
|
48
|
-
parsed_body[root_element.to_s]
|
48
|
+
parsed_body.try(:key?, root_element.to_s) && parsed_body[root_element.to_s]
|
49
49
|
else
|
50
50
|
parsed_body
|
51
51
|
end.presence || {}
|
@@ -53,11 +53,11 @@ module RemoteResource
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def errors
|
56
|
-
@errors ||= parsed_body['errors'].presence || attributes['errors'].presence || {}
|
56
|
+
@errors ||= parsed_body.try(:key?, 'errors') && parsed_body['errors'].presence || attributes.try(:key?, 'errors') && attributes['errors'].presence || {}
|
57
57
|
end
|
58
58
|
|
59
59
|
def meta
|
60
|
-
@meta ||= parsed_body['meta'].presence || {}
|
60
|
+
@meta ||= parsed_body.try(:key?, 'meta') && parsed_body['meta'].presence || {}
|
61
61
|
end
|
62
62
|
|
63
63
|
end
|
@@ -130,6 +130,17 @@ RSpec.describe RemoteResource::Response do
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
+
context 'when connection_options[:root_element] is present and the parsed response body has NO keys' do
|
134
|
+
let(:connection_options) do
|
135
|
+
{ root_element: :data, collection: true }
|
136
|
+
end
|
137
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: [{ id: 12, name: 'Mies' }].to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
138
|
+
|
139
|
+
it 'returns an empty Hash' do
|
140
|
+
expect(response.attributes).to eql({})
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
133
144
|
context 'when the parsed response body is NOT present' do
|
134
145
|
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 500, body: '', headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
135
146
|
|
@@ -164,6 +175,25 @@ RSpec.describe RemoteResource::Response do
|
|
164
175
|
expect(response.errors).to eql({})
|
165
176
|
end
|
166
177
|
end
|
178
|
+
|
179
|
+
context 'when the parsed response body does NOT contain keys' do
|
180
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: [{ id: 12, name: 'Mies' }].to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
181
|
+
|
182
|
+
it 'returns an empty Hash' do
|
183
|
+
expect(response.errors).to eql({})
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context 'when the attributes do NOT contain keys, e.g. when connection_options[:root_element] is present' do
|
188
|
+
let(:connection_options) do
|
189
|
+
{ root_element: :data, collection: true }
|
190
|
+
end
|
191
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: { data: [{ id: 12, name: 'Mies' }] }.to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
192
|
+
|
193
|
+
it 'returns an empty Hash' do
|
194
|
+
expect(response.errors).to eql({})
|
195
|
+
end
|
196
|
+
end
|
167
197
|
end
|
168
198
|
|
169
199
|
describe '#meta' do
|
@@ -183,6 +213,14 @@ RSpec.describe RemoteResource::Response do
|
|
183
213
|
expect(response.meta).to eql({})
|
184
214
|
end
|
185
215
|
end
|
216
|
+
|
217
|
+
context 'when the parsed response body does NOT contain keys' do
|
218
|
+
let(:connection_response) { Typhoeus::Response.new(mock: true, code: 200, body: [{ id: 12, name: 'Mies' }].to_json, headers: { 'Content-Type' => 'application/json', 'Server' => 'nginx/1.4.6 (Ubuntu)' }) }
|
219
|
+
|
220
|
+
it 'returns an empty Hash' do
|
221
|
+
expect(response.meta).to eql({})
|
222
|
+
end
|
223
|
+
end
|
186
224
|
end
|
187
225
|
|
188
226
|
end
|