flexirest 1.6.2 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +2 -2
- data/lib/flexirest/request.rb +4 -1
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/json_api_spec.rb +32 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 395be9d32a66854a03dfee23f11da2773fce4852
|
4
|
+
data.tar.gz: 624db41375f5919e5495eef37d1bb5a2362e3f7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6721c8c74d486de9101c54f07909c479416cc49e6838738323c804ea20d82e42f2148dbc218c3ca90d3632b9ebe60bab1cf519a27c1789c6976cb0fa45993d3
|
7
|
+
data.tar.gz: b61cb95703f902fd1bdd26ef2c47fa67a230ff496d39ab30b111b5e9c65546c7f371af8f6c1d0fabd6e8fd584771b200c3b863cb1aeddc7f61e380fe14c290fc
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 1.6.
|
3
|
+
## 1.6.3
|
4
4
|
|
5
5
|
Bugfix:
|
6
6
|
|
7
|
-
-
|
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
|
|
data/lib/flexirest/request.rb
CHANGED
@@ -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(
|
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"
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/json_api_spec.rb
CHANGED
@@ -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(
|
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
|