flexirest 1.10.1 → 1.10.2

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: 89ef0bd6a927d830d9f98f1e4deeee8d26bf68a203a001f2299785386e1365b9
4
- data.tar.gz: 3fa35c87cb16df1181207a6393682c6ec003346b4789d8bff30bbedbdba0e753
3
+ metadata.gz: 8001a7a20f2054fd34a7f09ae350253da96eba3dc4ff8b390e5b07509f1f09ea
4
+ data.tar.gz: 8f96916235d0f45fa9aa1c3ff5f37502f81c5d2f2a1c5db079d72e63d0de923c
5
5
  SHA512:
6
- metadata.gz: 520a9f3131d517c00180dd15a9fbd8c03372343bde13474457a37db78b321efa54a756878bd5161253ab6646a6e6ffc24171a3f69fca043c14cfb49630cf7ef8
7
- data.tar.gz: 5580fe4c1079b03fb51465550afce7ca4a542051efbd127df0405d113d47955182d88cfc324ff184a36be7eee0d4eaab5fad85efe47f94d5163846aad952df6d
6
+ metadata.gz: ad2e6dad01ee45f4d0b0540b53e8c6f20329d94cae6364f59d281ede3c45955959d3ecb70762249911cf05cc637840ba7e88a1c2fac49ff329ad3de680f643b3
7
+ data.tar.gz: de207d3cb3ac7bb243137925217efc0067d7c80950bac1a6a02450f251da0380470866e448ffd5c876e6009ed07b2cf0573ad82ce0782ad07cfb53c839a8e70d
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.10.2
4
+
5
+ Bugfix:
6
+
7
+ - JSON-API calls do not include linked resources when no other parameter is passed (thanks to Stevo-S for the bug report and François Ferrandis for the PR)
8
+
3
9
  ## 1.10.1
4
10
 
5
11
  Enhancement:
@@ -12,17 +12,26 @@ This proxy translates requests according to the JSON API specifications, parses
12
12
 
13
13
  It supports lazy loading by default. Unless a compound document is returned from the connected JSON API service, it will make another request to the service for the specified linked resource.
14
14
 
15
+
16
+ ## Including associations
17
+
15
18
  To reduce the number of requests to the service, you can ask the service to include the linked resources in the response. Such responses are called "compound documents". To do this, use the `includes` method:
16
19
 
17
20
  ```ruby
18
- # Makes a call to /articles with parameters: include=images
21
+ # Makes a call to: /articles?include=images
19
22
  Article.includes(:images).all
20
23
 
21
- # For nested resources, the include parameter becomes: include=images.tags,images.photographer
24
+ # Fetch nested resources: /articles?include=images.tags,images.photographer
22
25
  Article.includes(:images => [:tags, :photographer]).all
26
+
27
+ # Note: the `includes` method takes precedence over the passed `:include` parameter.
28
+ # This will result in query: /articles?include=images
29
+ Article.includes(:images).all(include: "author")
23
30
  ```
24
31
 
25
- For POST and PATCH requests, the proxy formats a JSON API compliant request, and adds a `Content-Type: application/vnd.api+json` header. It guesses the `type` value in the resource object from the class name, but it can be set specifically with `alias_type`:
32
+ ## Resource type
33
+
34
+ The `type` value is guessed from the class name, but it can be set specifically with `alias_type`:
26
35
 
27
36
  ```ruby
28
37
  class Photographer < Flexirest::Base
@@ -34,7 +43,10 @@ class Photographer < Flexirest::Base
34
43
  end
35
44
  ```
36
45
 
37
- NB: Updating relationships is not yet supported.
46
+
47
+ ## Notes
48
+
49
+ Updating relationships is not yet supported.
38
50
 
39
51
 
40
52
  -----
@@ -7,7 +7,7 @@ class Person < Flexirest::Base
7
7
  end
8
8
 
9
9
  people = Person._plain_request('http://api.example.com/v1/people') # Defaults to get with no parameters
10
- # people is a normal Flexirest object, implementing iteration, HAL loading, etc.
10
+ # people is a string containing the response
11
11
 
12
12
  Person._plain_request('http://api.example.com/v1/people', :post, {id:1234,name:"John"}) # Post with parameters
13
13
  ```
@@ -50,11 +50,8 @@ module Flexirest
50
50
  end
51
51
 
52
52
  def translate(params, include_associations)
53
- # Return to caller if nothing is to be done
54
- return params unless params.present? && include_associations.present?
55
-
56
53
  # Format the linked resources array, and assign to include key
57
- params[:include] = format_include_params(include_associations)
54
+ params[:include] = format_include_params(include_associations) if include_associations.present?
58
55
  end
59
56
 
60
57
  private
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.10.1"
2
+ VERSION = "1.10.2"
3
3
  end
@@ -303,7 +303,7 @@ describe 'JSON API' do
303
303
  let(:tags) { JsonAPIExample::Tag }
304
304
  let(:author) { JsonAPIExample::Author }
305
305
 
306
- context 'responses' do
306
+ describe 'responses' do
307
307
  it 'should return the data object if the response contains only one data instance' do
308
308
  expect(subject.find(1)).to be_an_instance_of(JsonAPIExampleArticle)
309
309
  end
@@ -370,17 +370,17 @@ describe 'JSON API' do
370
370
  end
371
371
  end
372
372
 
373
- context 'attributes' do
373
+ describe 'attributes' do
374
374
  it 'should return the attributes as part of the data instance' do
375
- expect(subject.find(1).item).to_not be_nil
375
+ expect(subject.find(1).item).to eq("item one")
376
376
  end
377
377
 
378
378
  it 'should return the association\'s attributes as part of the association instance' do
379
- expect(subject.includes(:author).find_single_author(1).author.item).to_not be_nil
379
+ expect(subject.includes(:author).find_single_author(1).author.item).to eq("item two")
380
380
  end
381
381
  end
382
382
 
383
- context 'associations' do
383
+ describe 'associations' do
384
384
  it 'should retrieve the resource\'s associations via its relationships object' do
385
385
  expect(subject.includes(:tags).find(1).tags.size).to eq(2)
386
386
  end
@@ -415,6 +415,40 @@ describe 'JSON API' do
415
415
  end
416
416
  end
417
417
 
418
+ describe 'requests' do
419
+ describe 'the `include=` parameter' do
420
+ before { stub_request(:get, %r{example\.com/articles}) }
421
+
422
+ context 'when using `.includes(:tags)`' do
423
+ it 'equal "tags"' do
424
+ JsonAPIExample::Article.includes(:tags).real_index
425
+ expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?include=tags')
426
+ end
427
+ end
428
+
429
+ context 'when using `.includes(tags: [:authors, :articles])`' do
430
+ it 'equal "tags.authors,tags.articles"' do
431
+ JsonAPIExample::Article.includes(tags: [:authors, :articles]).real_index
432
+ expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?include=tags.authors,tags.articles')
433
+ end
434
+ end
435
+
436
+ context 'when using both `.includes(:tags)` and other params in the final call' do
437
+ it 'uses the values passed to the `includes() method`' do
438
+ JsonAPIExample::Article.includes(:tags).real_index(filter: { author_id: 4 })
439
+ expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?filter%5Bauthor_id%5D=4&include=tags')
440
+ end
441
+ end
442
+
443
+ context 'when using both `.includes(:tags)` and the :include param in final call' do
444
+ it 'uses the values passed to the `includes() method`' do
445
+ JsonAPIExample::Article.includes(:tags).real_index(include: "author")
446
+ expect(WebMock).to have_requested(:get, 'http://www.example.com/articles?include=tags')
447
+ end
448
+ end
449
+ end
450
+ end
451
+
418
452
  context 'lazy loading' do
419
453
  it 'should fetch association lazily' do
420
454
  stub_request(:get, /www.example.com\/articles\/1\/tags/)
@@ -434,7 +468,7 @@ describe 'JSON API' do
434
468
  end
435
469
  end
436
470
 
437
- context 'client' do
471
+ describe 'client' do
438
472
  it 'should request with json api format, and expect a json api response' do
439
473
  expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, _, _, options|
440
474
  expect(options[:headers]).to include('Content-Type' => 'application/vnd.api+json')
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.10.1
4
+ version: 1.10.2
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-10-12 00:00:00.000000000 Z
11
+ date: 2020-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler