flexirest 1.13.1 → 1.13.2
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/flexirest.gemspec +1 -1
- data/lib/flexirest/lazy_association_loader.rb +1 -1
- data/lib/flexirest/proxy_base.rb +1 -1
- data/lib/flexirest/request.rb +2 -2
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/base_without_validation_spec.rb +2 -2
- data/spec/lib/json_api_spec.rb +5 -5
- data/spec/lib/multi_json_api_spec.rb +58 -0
- data/spec/lib/request_spec.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8b2caeda24cf6df9d105be2899483c18887dfa8903e54e0142d05f4be406ba4
|
|
4
|
+
data.tar.gz: 4072891a3796efbfa0323977dc922c57acbf77cce41f94ed50f95a63911dc70e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f07a2703870fbcd9c4d7b1862ccd95b8cf38a6e67c0caeca51706361b1bd871c4b49698fb69719747890e18adf22f1b809d8c3cf8e13d977758f88780d23db24
|
|
7
|
+
data.tar.gz: 3d4051535dda8ecac777686b506008cdb104aa832cd1fa4ac668ae01c1d129d53f92ac863ca69e3abebc3da55f6275a19ab259d3bdabf2bf477f9bf4059f73c4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.13.2
|
|
4
|
+
|
|
5
|
+
Bugfix:
|
|
6
|
+
|
|
7
|
+
- multi_json 1.21 renamed its module to `MultiJSON` and replaced `load`/`dump` with `parse`/`generate`, deprecating the old names with one-time warnings that appeared in host applications' test output. Flexirest now calls the current API (and `symbolize_names` rather than the deprecated `symbolize_keys`), so it requires multi_json >= 1.21
|
|
8
|
+
|
|
3
9
|
## 1.13.1
|
|
4
10
|
|
|
5
11
|
Bugfix:
|
data/flexirest.gemspec
CHANGED
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
|
|
|
42
42
|
# rather than assume the host application provides it.
|
|
43
43
|
spec.add_runtime_dependency "ostruct"
|
|
44
44
|
spec.add_runtime_dependency "mime-types"
|
|
45
|
-
spec.add_runtime_dependency "multi_json"
|
|
45
|
+
spec.add_runtime_dependency "multi_json", ">= 1.21"
|
|
46
46
|
spec.add_runtime_dependency "crack"
|
|
47
47
|
spec.add_runtime_dependency "faraday", "~> 2.7"
|
|
48
48
|
|
|
@@ -87,7 +87,7 @@ module Flexirest
|
|
|
87
87
|
|
|
88
88
|
def ensure_lazy_loaded
|
|
89
89
|
if @object.nil?
|
|
90
|
-
method =
|
|
90
|
+
method = MultiJSON.parse(MultiJSON.generate(@request.method), symbolize_names: true)
|
|
91
91
|
method[:method] = :get
|
|
92
92
|
method[:options][:url] = @url
|
|
93
93
|
method[:options][:overridden_name] = @options[:overridden_name]
|
data/lib/flexirest/proxy_base.rb
CHANGED
|
@@ -99,7 +99,7 @@ module Flexirest
|
|
|
99
99
|
if incoming_content_type && incoming_content_type["xml"]
|
|
100
100
|
result.body = yield Crack::XML.parse(result.body)
|
|
101
101
|
else
|
|
102
|
-
result.body = yield
|
|
102
|
+
result.body = yield MultiJSON.parse(result.body)
|
|
103
103
|
end
|
|
104
104
|
end
|
|
105
105
|
result
|
data/lib/flexirest/request.rb
CHANGED
|
@@ -872,9 +872,9 @@ module Flexirest
|
|
|
872
872
|
body = @response.body
|
|
873
873
|
elsif is_json_response?
|
|
874
874
|
begin
|
|
875
|
-
body = @response.body.blank? ? {} :
|
|
875
|
+
body = @response.body.blank? ? {} : MultiJSON.parse(@response.body)
|
|
876
876
|
body = {} if body.nil?
|
|
877
|
-
rescue
|
|
877
|
+
rescue MultiJSON::ParseError
|
|
878
878
|
raise ResponseParseException.new(status:@response.status, body:@response.body, headers:@response.headers)
|
|
879
879
|
end
|
|
880
880
|
|
data/lib/flexirest/version.rb
CHANGED
|
@@ -520,11 +520,11 @@ describe Flexirest::BaseWithoutValidation do
|
|
|
520
520
|
let(:location) { EmptyExample.new(place:"Room 1408") }
|
|
521
521
|
let(:lazy) { Laz }
|
|
522
522
|
let(:object) { EmptyExample.new(name:"Programming 101", location:location, students:[student1, student2]) }
|
|
523
|
-
let(:json_parsed_object) {
|
|
523
|
+
let(:json_parsed_object) { MultiJSON.parse(object.to_json) }
|
|
524
524
|
|
|
525
525
|
it "should be able to export to valid json" do
|
|
526
526
|
expect(object.to_json).to_not be_blank
|
|
527
|
-
expect{
|
|
527
|
+
expect{MultiJSON.parse(object.to_json)}.to_not raise_error
|
|
528
528
|
end
|
|
529
529
|
|
|
530
530
|
it "should not be using Object's #to_json method" do
|
data/spec/lib/json_api_spec.rb
CHANGED
|
@@ -479,7 +479,7 @@ describe 'JSON API' do
|
|
|
479
479
|
|
|
480
480
|
it 'should be able to call #.create on class' do
|
|
481
481
|
expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, path, data|
|
|
482
|
-
hash =
|
|
482
|
+
hash = MultiJSON.parse(data)
|
|
483
483
|
expect(path).to eq('/articles')
|
|
484
484
|
expect(hash['data']).to_not be_nil
|
|
485
485
|
expect(hash['data']['id']).to be_nil
|
|
@@ -490,7 +490,7 @@ describe 'JSON API' do
|
|
|
490
490
|
|
|
491
491
|
it 'should be able to call #.create with params on class' do
|
|
492
492
|
expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, path, data|
|
|
493
|
-
hash =
|
|
493
|
+
hash = MultiJSON.parse(data)
|
|
494
494
|
expect(path).to eq('/articles')
|
|
495
495
|
expect(hash['data']).to_not be_nil
|
|
496
496
|
expect(hash['data']['id']).to be_nil
|
|
@@ -505,7 +505,7 @@ describe 'JSON API' do
|
|
|
505
505
|
|
|
506
506
|
it 'should perform a post request in proper json api format' do
|
|
507
507
|
expect_any_instance_of(Flexirest::Connection).to receive(:post) { |_, path, data|
|
|
508
|
-
hash =
|
|
508
|
+
hash = MultiJSON.parse(data)
|
|
509
509
|
expect(path).to eq('/articles')
|
|
510
510
|
expect(hash['data']).to_not be_nil
|
|
511
511
|
expect(hash['data']['id']).to be_nil
|
|
@@ -533,7 +533,7 @@ describe 'JSON API' do
|
|
|
533
533
|
|
|
534
534
|
it 'should perform a patch request in proper json api format' do
|
|
535
535
|
expect_any_instance_of(Flexirest::Connection).to receive(:patch) { |_, path, data|
|
|
536
|
-
hash =
|
|
536
|
+
hash = MultiJSON.parse(data)
|
|
537
537
|
expect(path).to eq('/articles/1')
|
|
538
538
|
expect(hash['data']).to_not be_nil
|
|
539
539
|
expect(hash['data']['id']).to_not be_nil
|
|
@@ -554,7 +554,7 @@ describe 'JSON API' do
|
|
|
554
554
|
|
|
555
555
|
it 'should have placed the right type value in the request' do
|
|
556
556
|
expect_any_instance_of(Flexirest::Connection).to receive(:patch) { |_, _, data|
|
|
557
|
-
hash =
|
|
557
|
+
hash = MultiJSON.parse(data)
|
|
558
558
|
expect(hash['data']['type']).to eq(JsonAPIExample::ArticleAlias.alias_type.to_s)
|
|
559
559
|
expect(hash['data']['relationships']['author']['data']['type']).to eq(JsonAPIExample::AuthorAlias.alias_type.to_s)
|
|
560
560
|
}.and_return(::FaradayResponseMock.new(OpenStruct.new(body: '{}', response_headers: {})))
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "multi_json API" do
|
|
4
|
+
before :each do
|
|
5
|
+
class MultiJsonChildExample < Flexirest::Base
|
|
6
|
+
base_url "http://www.example.com"
|
|
7
|
+
|
|
8
|
+
get :find, "/child/:id"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class MultiJsonExampleClient < Flexirest::Base
|
|
12
|
+
base_url "http://www.example.com"
|
|
13
|
+
|
|
14
|
+
get :find, "/find/:id"
|
|
15
|
+
get :parent, "/parent", lazy: { children: MultiJsonChildExample }, fake: "{\"children\": [\"http://www.example.com/child/1\"]}"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# multi_json warns once per process for each deprecated entry point, so a
|
|
20
|
+
# warning emitted by an earlier spec would make a later one look clean.
|
|
21
|
+
# Message expectations on the deprecated surface - the legacy MultiJson module
|
|
22
|
+
# (whose const_missing serves MultiJson::ParseError) and the load/dump aliases
|
|
23
|
+
# on MultiJSON itself - hold regardless of spec order.
|
|
24
|
+
def expect_no_deprecated_json_api
|
|
25
|
+
[MultiJson, MultiJSON].each do |target|
|
|
26
|
+
%i[load dump decode encode const_missing].each do |name|
|
|
27
|
+
expect(target).to_not receive(name) if target.respond_to?(name)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def response_for(body)
|
|
33
|
+
::FaradayResponseMock.new(OpenStruct.new(status: 200, response_headers: { "Content-Type" => "application/json" }, body: body))
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "parses a response body" do
|
|
37
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with(any_args).and_return(response_for("{\"name\":\"Billy\"}"))
|
|
38
|
+
expect_no_deprecated_json_api
|
|
39
|
+
|
|
40
|
+
expect(MultiJsonExampleClient.find(id: 1).name).to eq("Billy")
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "reports a body it cannot parse" do
|
|
44
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with(any_args).and_return(response_for("{\"name\": Billy"))
|
|
45
|
+
expect_no_deprecated_json_api
|
|
46
|
+
|
|
47
|
+
expect { MultiJsonExampleClient.find(id: 1) }.to raise_error(Flexirest::ResponseParseException)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "loads a lazy association" do
|
|
51
|
+
loader = MultiJsonExampleClient.parent.children.first
|
|
52
|
+
expect(loader).to be_an_instance_of(Flexirest::LazyAssociationLoader)
|
|
53
|
+
expect_any_instance_of(Flexirest::Connection).to receive(:get).with(any_args).and_return(response_for("{\"name\":\"Jane\"}"))
|
|
54
|
+
expect_no_deprecated_json_api
|
|
55
|
+
|
|
56
|
+
expect(loader.name).to eq("Jane")
|
|
57
|
+
end
|
|
58
|
+
end
|
data/spec/lib/request_spec.rb
CHANGED
|
@@ -206,7 +206,7 @@ describe Flexirest::Request do
|
|
|
206
206
|
class CallbackBodyExampleClient < ExampleClient
|
|
207
207
|
base_url "http://www.example.com"
|
|
208
208
|
before_request do |name, request|
|
|
209
|
-
request.body =
|
|
209
|
+
request.body = MultiJSON.generate(request.post_params)
|
|
210
210
|
end
|
|
211
211
|
|
|
212
212
|
post :save, "/save"
|
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.13.
|
|
4
|
+
version: 1.13.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andy Jeffries
|
|
@@ -225,14 +225,14 @@ dependencies:
|
|
|
225
225
|
requirements:
|
|
226
226
|
- - ">="
|
|
227
227
|
- !ruby/object:Gem::Version
|
|
228
|
-
version: '
|
|
228
|
+
version: '1.21'
|
|
229
229
|
type: :runtime
|
|
230
230
|
prerelease: false
|
|
231
231
|
version_requirements: !ruby/object:Gem::Requirement
|
|
232
232
|
requirements:
|
|
233
233
|
- - ">="
|
|
234
234
|
- !ruby/object:Gem::Version
|
|
235
|
-
version: '
|
|
235
|
+
version: '1.21'
|
|
236
236
|
- !ruby/object:Gem::Dependency
|
|
237
237
|
name: crack
|
|
238
238
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -390,6 +390,7 @@ files:
|
|
|
390
390
|
- spec/lib/lazy_loader_spec.rb
|
|
391
391
|
- spec/lib/logger_spec.rb
|
|
392
392
|
- spec/lib/mapping_spec.rb
|
|
393
|
+
- spec/lib/multi_json_api_spec.rb
|
|
393
394
|
- spec/lib/plain_response_spec.rb
|
|
394
395
|
- spec/lib/proxy_spec.rb
|
|
395
396
|
- spec/lib/recording_spec.rb
|
|
@@ -444,6 +445,7 @@ test_files:
|
|
|
444
445
|
- spec/lib/lazy_loader_spec.rb
|
|
445
446
|
- spec/lib/logger_spec.rb
|
|
446
447
|
- spec/lib/mapping_spec.rb
|
|
448
|
+
- spec/lib/multi_json_api_spec.rb
|
|
447
449
|
- spec/lib/plain_response_spec.rb
|
|
448
450
|
- spec/lib/proxy_spec.rb
|
|
449
451
|
- spec/lib/recording_spec.rb
|