flexirest 1.6.2 → 1.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ef0d167d4d731cacdb7ac4f272ca0cf0c1ebb24
4
- data.tar.gz: b56d4dc78f1f6e5875f57e737cab0a1b4efd749f
3
+ metadata.gz: 395be9d32a66854a03dfee23f11da2773fce4852
4
+ data.tar.gz: 624db41375f5919e5495eef37d1bb5a2362e3f7e
5
5
  SHA512:
6
- metadata.gz: 6cc9bfa84951e23c7ac5f12804967e27724f7f8f9a4de62d6cf4b293f57aaeb8a61138f6c7baccd7559b5707c83b3bcfc854492e6c838fcd976ff542630bc31f
7
- data.tar.gz: 2bf14a68818a51363b2f3e3817dfc88b4e599516a2b2bc7125da773e05b041e2f0445dad4d561aa709ae3bd6e88ff28f3a1d86ea58442c22ac6704db5a628249
6
+ metadata.gz: a6721c8c74d486de9101c54f07909c479416cc49e6838738323c804ea20d82e42f2148dbc218c3ca90d3632b9ebe60bab1cf519a27c1789c6976cb0fa45993d3
7
+ data.tar.gz: b61cb95703f902fd1bdd26ef2c47fa67a230ff496d39ab30b111b5e9c65546c7f371af8f6c1d0fabd6e8fd584771b200c3b863cb1aeddc7f61e380fe14c290fc
@@ -1,10 +1,10 @@
1
1
  # Changelog
2
2
 
3
- ## 1.6.2
3
+ ## 1.6.3
4
4
 
5
5
  Bugfix:
6
6
 
7
- - Flexirest wasn't supporting nested arrays in responses, it does now. Thanks to Rui Ribeiro for pointing this out.
7
+ - Allowing instantiating a class if mapped request method is called for "JSON-API" functionality (thanks to Mike Voets for this PR).
8
8
 
9
9
  ## 1.6.1
10
10
 
@@ -375,7 +375,10 @@ module Flexirest
375
375
  @body = ""
376
376
  else
377
377
  headers["Content-Type"] ||= "application/vnd.api+json"
378
- @body = JsonAPIProxy::Request::Params.create(params || @post_params || {}, @object).to_json
378
+ @body = JsonAPIProxy::Request::Params.create(
379
+ params || @post_params || {},
380
+ object_is_class? ? @object.new : @object
381
+ ).to_json
379
382
  end
380
383
 
381
384
  headers["Accept"] ||= "application/vnd.api+json"
@@ -1,3 +1,3 @@
1
1
  module Flexirest
2
- VERSION = "1.6.2"
2
+ VERSION = "1.6.3"
3
3
  end
@@ -321,10 +321,36 @@ describe 'JSON API' do
321
321
  expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, _, _, options|
322
322
  expect(options[:headers]).to include('Content-Type' => 'application/vnd.api+json')
323
323
  expect(options[:headers]).to include('Accept' => 'application/vnd.api+json')
324
- }.and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{}', response_headers:{})))
324
+ }.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
325
325
  JsonAPIExample::Article.new.create
326
326
  end
327
327
 
328
+ it 'should be able to call #.create on class' do
329
+ expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, path, data|
330
+ hash = MultiJson.load(data)
331
+ expect(path).to eq('/articles')
332
+ expect(hash['data']).to_not be_nil
333
+ expect(hash['data']['id']).to be_nil
334
+ expect(hash['data']['type']).to eq('articles')
335
+ }.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
336
+ JsonAPIExample::Article.create
337
+ end
338
+
339
+ it 'should be able to call #.create with params on class' do
340
+ expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, path, data|
341
+ hash = MultiJson.load(data)
342
+ expect(path).to eq('/articles')
343
+ expect(hash['data']).to_not be_nil
344
+ expect(hash['data']['id']).to be_nil
345
+ expect(hash['data']['type']).to eq('articles')
346
+ expect(hash['data']['relationships']['author']['data']['type']).to eq('authors')
347
+ expect(hash['data']['relationships']['tags']['data'].first['type']).to eq('tags')
348
+ }.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
349
+ author = JsonAPIExample::Author.new
350
+ tag = JsonAPIExample::Tag.new
351
+ JsonAPIExample::Article.create(item: 'item one', author: author, tags: [tag])
352
+ end
353
+
328
354
  it 'should perform a post request in proper json api format' do
329
355
  expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, path, data|
330
356
  hash = MultiJson.load(data)
@@ -334,7 +360,7 @@ describe 'JSON API' do
334
360
  expect(hash['data']['type']).to eq('articles')
335
361
  expect(hash['data']['relationships']['author']['data']['type']).to eq('authors')
336
362
  expect(hash['data']['relationships']['tags']['data'].first['type']).to eq('tags')
337
- }.and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{}', response_headers:{})))
363
+ }.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
338
364
  author = JsonAPIExample::Author.new
339
365
  tag = JsonAPIExample::Tag.new
340
366
  article = JsonAPIExample::Article.new
@@ -350,7 +376,7 @@ describe 'JSON API' do
350
376
  article = JsonAPIExample::Article.new
351
377
  article.item = 'item one'
352
378
  article.tags = [tag, author]
353
- expect(lambda { article.create }).to raise_error(Exception)
379
+ expect(-> { article.create }).to raise_error(Exception)
354
380
  end
355
381
 
356
382
  it 'should perform a patch request in proper json api format' do
@@ -360,7 +386,7 @@ describe 'JSON API' do
360
386
  expect(hash['data']).to_not be_nil
361
387
  expect(hash['data']['id']).to_not be_nil
362
388
  expect(hash['data']['type']).to_not be_nil
363
- }.and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{}', response_headers:{})))
389
+ }.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
364
390
  article = JsonAPIExample::Article.find(1)
365
391
  article.item = 'item one'
366
392
  article.update
@@ -370,7 +396,7 @@ describe 'JSON API' do
370
396
  expect_any_instance_of(Flexirest::Connection).to receive(:delete) { |_, path, data|
371
397
  expect(path).to eq('/articles/1')
372
398
  expect(data).to eq('')
373
- }.and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{}', response_headers:{})))
399
+ }.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
374
400
  JsonAPIExample::Article.find(1).delete
375
401
  end
376
402
 
@@ -379,7 +405,7 @@ describe 'JSON API' do
379
405
  hash = MultiJson.load(data)
380
406
  expect(hash['data']['type']).to eq(JsonAPIExample::ArticleAlias.alias_type.to_s)
381
407
  expect(hash['data']['relationships']['author']['data']['type']).to eq(JsonAPIExample::AuthorAlias.alias_type.to_s)
382
- }.and_return(::FaradayResponseMock.new(OpenStruct.new(body:'{}', response_headers:{})))
408
+ }.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
383
409
  author = JsonAPIExample::AuthorAlias.new
384
410
  author.id = 1
385
411
  article = JsonAPIExample::ArticleAlias.find(1)
@@ -387,6 +413,5 @@ describe 'JSON API' do
387
413
  article.author = author
388
414
  article.update
389
415
  end
390
-
391
416
  end
392
417
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexirest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries