flexirest 1.9.10 → 1.9.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/lib/flexirest/json_api_proxy.rb +6 -1
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/json_api_spec.rb +36 -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: 294f2e24981dde7af931d0bedd578e4eb260538f947f716739a3d4037cd2a6b8
|
4
|
+
data.tar.gz: 5ab2e8babd0e312eea734257e6fdeeb1ccd1701143ec4a953a0ea90b102ed3f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce1125b17e4a41d11bc3cb3be10888d89604beaff46839fe3dbbce1fb663b4d69bbc58f3a8dab9463b2367daae9e182751393c8adc2ed5148e90138ce88ab167
|
7
|
+
data.tar.gz: c4f992e9c9e70b2faabf3384512f6973b6e3f5fb8ebca7515faae48670ec61b630a2c951d908efbf95170506885f19a9e87454ce2bc0caac64a0a6f01a4f9770
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,19 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 1.9.
|
3
|
+
## 1.9.11
|
4
|
+
|
5
|
+
Bugfix:
|
6
|
+
|
7
|
+
- Prevent crash when JSONAPI response["data"] is an empty array (thanks to François Ferrandis for the PR).
|
8
|
+
|
9
|
+
## 1.9.10
|
4
10
|
|
5
11
|
Bugfix:
|
6
12
|
|
7
13
|
- Correctly handle errors in JSONAPI calls (thanks to François Ferrandis for the PR).
|
8
14
|
|
15
|
+
Important: Note, because a gem was accidentally pushed as version 1.9.10 instead of 1.9.0, there will be no 1.9.0 to 1.9.9, to reduce the risk of someone having updated to the accidental high version increase. Sorry about that
|
16
|
+
|
9
17
|
## 1.8.9
|
10
18
|
|
11
19
|
Feature:
|
@@ -196,9 +196,14 @@ module Flexirest
|
|
196
196
|
# Save resource class for building lazy association loaders
|
197
197
|
save_resource_class(object)
|
198
198
|
|
199
|
+
# try to return errors if their is no data
|
200
|
+
return body.fetch("errors", {}) if body['data'].nil?
|
201
|
+
|
202
|
+
# return early if data is an empty array
|
203
|
+
return [] if body['data'] == []
|
204
|
+
|
199
205
|
# Retrieve the resource(s) object or array from the data object
|
200
206
|
records = body['data']
|
201
|
-
return body['errors'] unless records.present?
|
202
207
|
|
203
208
|
# Convert the resource object to an array,
|
204
209
|
# because it is easier to work with an array than a single object
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/json_api_spec.rb
CHANGED
@@ -239,6 +239,7 @@ module JsonAPIExample
|
|
239
239
|
}
|
240
240
|
}
|
241
241
|
|
242
|
+
get(:real_index, '/articles')
|
242
243
|
get(:real_find, '/articles/:id')
|
243
244
|
|
244
245
|
get(
|
@@ -311,24 +312,42 @@ describe 'JSON API' do
|
|
311
312
|
expect(subject.find_all).to be_an_instance_of(Flexirest::ResultIterator)
|
312
313
|
end
|
313
314
|
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
315
|
+
context 'when response has "errors" key and no "data" key' do
|
316
|
+
let(:headers) { { "Content-Type" => "application/vnd.api+json" } }
|
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
|
329
|
+
|
330
|
+
it 'should raise a Flexirest error' do
|
331
|
+
expect_any_instance_of(Flexirest::Connection).
|
332
|
+
to receive(:get).with("/articles/123", an_instance_of(Hash)).
|
333
|
+
and_return(::FaradayResponseMock.new(OpenStruct.new(body: response_body.to_json, response_headers: headers, status: 404)))
|
334
|
+
|
335
|
+
expect(-> { JsonAPIExample::Article.real_find(123) }).to raise_error(Flexirest::HTTPNotFoundClientException) do |exception|
|
336
|
+
expect(exception.result.first.title).to eq("Record not found")
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
context 'when response has an empty "data" key' do
|
342
|
+
let(:headers) { { "Content-Type" => "application/vnd.api+json" } }
|
343
|
+
let(:response_body) { { data: [] } }
|
344
|
+
|
345
|
+
it 'should return an empty array' do
|
346
|
+
expect_any_instance_of(Flexirest::Connection).
|
347
|
+
to receive(:get).with("/articles", an_instance_of(Hash)).
|
348
|
+
and_return(::FaradayResponseMock.new(OpenStruct.new(body: response_body.to_json, response_headers: headers, status: 200)))
|
329
349
|
|
330
|
-
|
331
|
-
expect(exception.result.first.title).to eq("Record not found")
|
350
|
+
expect(JsonAPIExample::Article.real_index.to_a).to eq([])
|
332
351
|
end
|
333
352
|
end
|
334
353
|
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.11
|
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-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|