flexirest 1.9.11 → 1.9.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/flexirest/json_api_proxy.rb +4 -2
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/json_api_spec.rb +35 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3320d5c425f13498cf558c361209bed466565f0b173ebcc2bd3f8e6205fd37dd
|
4
|
+
data.tar.gz: dd621beea4b50068147c70fbf079b7753d32e8a625e080a5803f4904cb757eea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8811975e7c20d9b6a69fcb9c11e68883c2950927d2444723872cd302c10cec7802fa732ed50fb7b088a56535beb23d9180d4e717d7884bd7a1901c5fe05295f1
|
7
|
+
data.tar.gz: 9a8db810620535a335d2d94822ba277b5a61fe0963ce19479d53c57c001567afd30c96fb40720d231142ec7fd2dbcc01c8423f0c83d44408f6ea4c231cf6591f
|
data/CHANGELOG.md
CHANGED
@@ -196,8 +196,10 @@ module Flexirest
|
|
196
196
|
# Save resource class for building lazy association loaders
|
197
197
|
save_resource_class(object)
|
198
198
|
|
199
|
-
#
|
200
|
-
|
199
|
+
# According to the spec:
|
200
|
+
# "The members data and errors MUST NOT coexist in the same document."
|
201
|
+
# Thus, if the "errors" key is present, we can return it and ignore the "data" key.
|
202
|
+
return body['errors'] if body.include?('errors')
|
201
203
|
|
202
204
|
# return early if data is an empty array
|
203
205
|
return [] if body['data'] == []
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/json_api_spec.rb
CHANGED
@@ -312,28 +312,46 @@ describe 'JSON API' do
|
|
312
312
|
expect(subject.find_all).to be_an_instance_of(Flexirest::ResultIterator)
|
313
313
|
end
|
314
314
|
|
315
|
-
|
316
|
-
|
317
|
-
let(:response_body) do
|
318
|
-
{
|
319
|
-
errors: [
|
320
|
-
{
|
321
|
-
title: "Record not found",
|
322
|
-
detail: "The record identified by 123456 could not be found",
|
323
|
-
code: "not_found",
|
324
|
-
status: "404",
|
325
|
-
}
|
326
|
-
]
|
327
|
-
}
|
328
|
-
end
|
315
|
+
describe 'error responses' do
|
316
|
+
subject(:make_request) { JsonAPIExample::Article.real_find(123) }
|
329
317
|
|
330
|
-
|
318
|
+
before do
|
319
|
+
headers = { "Content-Type" => "application/vnd.api+json" }
|
331
320
|
expect_any_instance_of(Flexirest::Connection).
|
332
321
|
to receive(:get).with("/articles/123", an_instance_of(Hash)).
|
333
322
|
and_return(::FaradayResponseMock.new(OpenStruct.new(body: response_body.to_json, response_headers: headers, status: 404)))
|
323
|
+
end
|
324
|
+
|
325
|
+
context 'when no "data" key is present alongside the "errors" key' do
|
326
|
+
let(:response_body) do
|
327
|
+
{
|
328
|
+
errors: [
|
329
|
+
{ detail: "The record identified by 123456 could not be found", }
|
330
|
+
]
|
331
|
+
}
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'should raise the relevant Flexirest error' do
|
335
|
+
expect(-> { make_request }).to raise_error(Flexirest::HTTPNotFoundClientException) do |exception|
|
336
|
+
expect(exception.result.first.detail).to eq("The record identified by 123456 could not be found")
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'when a "data" key is present alongside the "errors" key (although this is forbidden by the spec)' do
|
342
|
+
let(:response_body) do
|
343
|
+
{
|
344
|
+
errors: [
|
345
|
+
{ detail: "The record identified by 123456 could not be found", }
|
346
|
+
],
|
347
|
+
data: {}
|
348
|
+
}
|
349
|
+
end
|
334
350
|
|
335
|
-
|
336
|
-
expect(
|
351
|
+
it 'should ignore the "data" key and raise the relevant Flexirest error' do
|
352
|
+
expect(-> { make_request }).to raise_error(Flexirest::HTTPNotFoundClientException) do |exception|
|
353
|
+
expect(exception.result.first.detail).to eq("The record identified by 123456 could not be found")
|
354
|
+
end
|
337
355
|
end
|
338
356
|
end
|
339
357
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexirest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|