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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f402c30e90e85f106749a754d7783d2519da5b86cc0caf730799cac8a5f65c72
4
- data.tar.gz: 29c6172196d8d09abbf37e2b40b0665d6b7d6498aa923b99c99e95683cf8c9c2
3
+ metadata.gz: 294f2e24981dde7af931d0bedd578e4eb260538f947f716739a3d4037cd2a6b8
4
+ data.tar.gz: 5ab2e8babd0e312eea734257e6fdeeb1ccd1701143ec4a953a0ea90b102ed3f4
5
5
  SHA512:
6
- metadata.gz: 502bdb7fb81e058703485d37c32f01f584ebdbc5a4d9eb37badf492847a9e9070f1705c06aee048397b61c16335b175b0447ccf8b6bf663080d83d84d6b64e8b
7
- data.tar.gz: 4a2317aac7ea5adfafe440efb5401a6da26cb1a7a8f58d4d236a5978e8c239cd540d5a45a7c9bebc39d15065d07b75ab6410b3c42a53a8e5af986a984431afa4
6
+ metadata.gz: ce1125b17e4a41d11bc3cb3be10888d89604beaff46839fe3dbbce1fb663b4d69bbc58f3a8dab9463b2367daae9e182751393c8adc2ed5148e90138ce88ab167
7
+ data.tar.gz: c4f992e9c9e70b2faabf3384512f6973b6e3f5fb8ebca7515faae48670ec61b630a2c951d908efbf95170506885f19a9e87454ce2bc0caac64a0a6f01a4f9770
@@ -1,11 +1,19 @@
1
1
  # Changelog
2
2
 
3
- ## 1.9.0
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
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.9.10"
2
+ VERSION = "1.9.11"
3
3
  end
@@ -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
- it 'should raise an error when response has "errors" key and no "data"' do
315
- body = {
316
- errors: [
317
- {
318
- title: "Record not found",
319
- detail: "The record identified by 123456 could not be found",
320
- code: "not_found",
321
- status: "404",
322
- }
323
- ]
324
- }
325
- headers = { "Content-Type" => "application/vnd.api+json" }
326
- expect_any_instance_of(Flexirest::Connection).
327
- to receive(:get).with("/articles/123", an_instance_of(Hash)).
328
- and_return(::FaradayResponseMock.new(OpenStruct.new(body: body.to_json, response_headers: headers, status: 404)))
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
- expect(-> { JsonAPIExample::Article.real_find(123) }).to raise_error(Flexirest::HTTPNotFoundClientException) do |exception|
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.10
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-12 00:00:00.000000000 Z
11
+ date: 2020-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler