restify 1.15.1 → 2.0.0
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 +102 -15
- data/README.md +23 -31
- data/lib/restify/adapter/base.rb +4 -0
- data/lib/restify/adapter/telemetry.rb +54 -0
- data/lib/restify/adapter/typhoeus.rb +24 -14
- data/lib/restify/context.rb +7 -11
- data/lib/restify/error.rb +2 -2
- data/lib/restify/global.rb +1 -0
- data/lib/restify/link.rb +4 -4
- data/lib/restify/logging.rb +1 -1
- data/lib/restify/processors/base/parsing.rb +5 -24
- data/lib/restify/processors/base.rb +1 -1
- data/lib/restify/promise.rb +2 -2
- data/lib/restify/registry.rb +1 -1
- data/lib/restify/relation.rb +45 -17
- data/lib/restify/request.rb +6 -6
- data/lib/restify/resource.rb +1 -1
- data/lib/restify/response.rb +0 -2
- data/lib/restify/timeout.rb +2 -2
- data/lib/restify/version.rb +4 -4
- data/lib/restify.rb +0 -1
- data/spec/restify/cache_spec.rb +16 -12
- data/spec/restify/context_spec.rb +15 -7
- data/spec/restify/error_spec.rb +23 -16
- data/spec/restify/features/head_requests_spec.rb +7 -5
- data/spec/restify/features/request_bodies_spec.rb +14 -13
- data/spec/restify/features/request_errors_spec.rb +2 -2
- data/spec/restify/features/request_headers_spec.rb +11 -14
- data/spec/restify/features/response_errors_spec.rb +2 -2
- data/spec/restify/global_spec.rb +13 -13
- data/spec/restify/link_spec.rb +9 -9
- data/spec/restify/processors/base_spec.rb +7 -7
- data/spec/restify/processors/json_spec.rb +22 -62
- data/spec/restify/processors/msgpack_spec.rb +40 -76
- data/spec/restify/promise_spec.rb +38 -34
- data/spec/restify/registry_spec.rb +6 -8
- data/spec/restify/relation_spec.rb +196 -17
- data/spec/restify/resource_spec.rb +55 -60
- data/spec/restify/timeout_spec.rb +7 -7
- data/spec/restify_spec.rb +13 -74
- data/spec/spec_helper.rb +13 -17
- data/spec/support/stub_server.rb +3 -3
- metadata +35 -65
- data/lib/restify/adapter/em.rb +0 -139
- data/lib/restify/adapter/pooled_em.rb +0 -270
@@ -4,7 +4,7 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Restify do
|
6
6
|
let!(:request_stub) do
|
7
|
-
stub_request(:get,
|
7
|
+
stub_request(:get, 'http://stubserver/base').to_return do
|
8
8
|
<<~HTTP
|
9
9
|
HTTP/1.1 200 OK
|
10
10
|
Content-Type: application/json
|
@@ -20,15 +20,14 @@ describe Restify do
|
|
20
20
|
|
21
21
|
it 'sends the headers only for that request' do
|
22
22
|
root = context.get(
|
23
|
-
{},
|
24
|
-
{headers: {'Accept' => 'application/msgpack, application/json'}}
|
23
|
+
headers: {'Accept' => 'application/msgpack, application/json'},
|
25
24
|
).value!
|
26
25
|
|
27
26
|
root.rel(:self).get.value!
|
28
27
|
|
29
28
|
expect(request_stub).to have_been_requested.twice
|
30
29
|
expect(
|
31
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
30
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
32
31
|
).to have_been_requested.once
|
33
32
|
end
|
34
33
|
end
|
@@ -37,7 +36,7 @@ describe Restify do
|
|
37
36
|
let(:context) do
|
38
37
|
Restify.new(
|
39
38
|
'http://localhost:9292/base',
|
40
|
-
headers: {'Accept' => 'application/msgpack, application/json'}
|
39
|
+
headers: {'Accept' => 'application/msgpack, application/json'},
|
41
40
|
)
|
42
41
|
end
|
43
42
|
|
@@ -47,39 +46,37 @@ describe Restify do
|
|
47
46
|
root.rel(:self).get.value!
|
48
47
|
|
49
48
|
expect(
|
50
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
49
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
51
50
|
).to have_been_requested.twice
|
52
51
|
end
|
53
52
|
|
54
53
|
it 'can overwrite headers for single requests' do
|
55
54
|
root = context.get(
|
56
|
-
{},
|
57
|
-
{headers: {'Accept' => 'application/xml'}}
|
55
|
+
headers: {'Accept' => 'application/xml'},
|
58
56
|
).value!
|
59
57
|
|
60
58
|
root.rel(:self).get.value!
|
61
59
|
|
62
60
|
expect(
|
63
|
-
request_stub.with(headers: {'Accept' => 'application/xml'})
|
61
|
+
request_stub.with(headers: {'Accept' => 'application/xml'}),
|
64
62
|
).to have_been_requested.once
|
65
63
|
expect(
|
66
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
64
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
67
65
|
).to have_been_requested.once
|
68
66
|
end
|
69
67
|
|
70
68
|
it 'can add additional headers for single requests' do
|
71
69
|
root = context.get(
|
72
|
-
{},
|
73
|
-
{headers: {'X-Custom' => 'foobar'}}
|
70
|
+
headers: {'X-Custom' => 'foobar'},
|
74
71
|
).value!
|
75
72
|
|
76
73
|
root.rel(:self).get.value!
|
77
74
|
|
78
75
|
expect(
|
79
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'})
|
76
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json'}),
|
80
77
|
).to have_been_requested.twice
|
81
78
|
expect(
|
82
|
-
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json', 'X-Custom' => 'foobar'})
|
79
|
+
request_stub.with(headers: {'Accept' => 'application/msgpack, application/json', 'X-Custom' => 'foobar'}),
|
83
80
|
).to have_been_requested.once
|
84
81
|
end
|
85
82
|
end
|
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Restify do
|
6
|
-
|
6
|
+
before do
|
7
7
|
stub_request(:get, 'http://stubserver/base')
|
8
|
-
.to_return(status: http_status, headers:
|
8
|
+
.to_return(status: http_status, headers:)
|
9
9
|
end
|
10
10
|
|
11
11
|
let(:http_status) { '200 OK' }
|
data/spec/restify/global_spec.rb
CHANGED
@@ -7,34 +7,34 @@ describe Restify::Global do
|
|
7
7
|
|
8
8
|
describe '#new' do
|
9
9
|
context 'with string URI' do
|
10
|
+
subject(:restify) { global.new(uri, **options) }
|
11
|
+
|
10
12
|
let(:uri) { 'http://api.github.com/' }
|
11
13
|
let(:options) { {accept: 'application.vnd.github.v3+json'} }
|
12
14
|
|
13
|
-
subject { global.new uri, **options }
|
14
|
-
|
15
15
|
it 'returns relation for URI' do
|
16
|
-
expect(
|
17
|
-
expect(
|
18
|
-
expect(
|
19
|
-
expect(
|
16
|
+
expect(restify).to be_a Restify::Relation
|
17
|
+
expect(restify.pattern).to eq uri
|
18
|
+
expect(restify.context.uri.to_s).to eq uri
|
19
|
+
expect(restify.context.options).to eq options
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
context 'with registry symbol' do
|
24
|
-
|
24
|
+
subject(:restify) { global.new(uri, **options) }
|
25
|
+
|
26
|
+
let(:name) { :registry_item_name }
|
25
27
|
let(:uri) { 'http://api.github.com/' }
|
26
28
|
let(:options) { {accept: 'application.vnd.github.v3+json'} }
|
27
29
|
let(:context) { Restify::Context.new uri, **options }
|
28
30
|
|
29
|
-
subject { global.new(name, **options) }
|
30
|
-
|
31
31
|
it 'returns relation for stored registry item' do
|
32
32
|
Restify::Registry.store(name, uri, **options)
|
33
33
|
|
34
|
-
expect(
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
expect(
|
34
|
+
expect(restify).to be_a Restify::Relation
|
35
|
+
expect(restify.pattern).to eq uri
|
36
|
+
expect(restify.context.uri.to_s).to eq uri
|
37
|
+
expect(restify.context.options).to eq options
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
data/spec/restify/link_spec.rb
CHANGED
@@ -5,27 +5,27 @@ require 'spec_helper'
|
|
5
5
|
describe Restify::Link do
|
6
6
|
describe 'class' do
|
7
7
|
describe '#parse' do
|
8
|
-
it '
|
8
|
+
it 'parses link with quotes' do
|
9
9
|
links = described_class
|
10
|
-
|
10
|
+
.parse('<http://example.org/search{?query}>; rel="search"')
|
11
11
|
|
12
12
|
expect(links).to have(1).item
|
13
13
|
expect(links[0].uri).to eq 'http://example.org/search{?query}'
|
14
14
|
expect(links[0].metadata).to eq 'rel' => 'search'
|
15
15
|
end
|
16
16
|
|
17
|
-
it '
|
17
|
+
it 'parses link without quotes' do
|
18
18
|
links = described_class
|
19
|
-
|
19
|
+
.parse('<http://example.org/search{?query}>; rel=search')
|
20
20
|
|
21
21
|
expect(links).to have(1).item
|
22
22
|
expect(links[0].uri).to eq 'http://example.org/search{?query}'
|
23
23
|
expect(links[0].metadata).to eq 'rel' => 'search'
|
24
24
|
end
|
25
25
|
|
26
|
-
it '
|
26
|
+
it 'parses multiple links' do
|
27
27
|
links = described_class
|
28
|
-
|
28
|
+
.parse('<p://h.tld/p>; rel=abc, <p://h.tld/b>; a=b; c="d"')
|
29
29
|
|
30
30
|
expect(links).to have(2).item
|
31
31
|
expect(links[0].uri).to eq 'p://h.tld/p'
|
@@ -34,19 +34,19 @@ describe Restify::Link do
|
|
34
34
|
expect(links[1].metadata).to eq 'a' => 'b', 'c' => 'd'
|
35
35
|
end
|
36
36
|
|
37
|
-
it '
|
37
|
+
it 'parses link w/o meta' do
|
38
38
|
links = described_class.parse('<p://h.tld/b>')
|
39
39
|
|
40
40
|
expect(links[0].uri).to eq 'p://h.tld/b'
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
43
|
+
it 'parses on invalid URI' do
|
44
44
|
links = described_class.parse('<hp://:&*^/fwbhg3>')
|
45
45
|
|
46
46
|
expect(links[0].uri).to eq 'hp://:&*^/fwbhg3'
|
47
47
|
end
|
48
48
|
|
49
|
-
it '
|
49
|
+
it 'errors on invalid header' do
|
50
50
|
expect { described_class.parse('</>; rel="s", abc-invalid') }
|
51
51
|
.to raise_error ArgumentError, /Invalid token at \d+:/i
|
52
52
|
end
|
@@ -4,27 +4,27 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Restify::Processors::Base do
|
6
6
|
let(:context) { Restify::Context.new('http://test.host/') }
|
7
|
-
let(:response) {
|
7
|
+
let(:response) { instance_double(Restify::Response) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
allow(response).to
|
11
|
-
allow(response).to receive(:follow_location).and_return nil
|
10
|
+
allow(response).to receive_messages(links: [], follow_location: nil)
|
12
11
|
end
|
13
12
|
|
14
13
|
describe 'class' do
|
15
14
|
describe '#accept?' do
|
16
|
-
subject { described_class.accept?
|
15
|
+
subject(:accept) { described_class.accept?(response) }
|
17
16
|
|
18
17
|
# If no other processor accepts the request, we have an explicit fallback
|
19
18
|
# to the base processor.
|
20
19
|
it 'does not accept any responses' do
|
21
|
-
expect(
|
20
|
+
expect(accept).to be_falsey
|
22
21
|
end
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
26
25
|
describe '#resource' do
|
27
|
-
subject { described_class.new(context, response).resource }
|
26
|
+
subject(:resource) { described_class.new(context, response).resource }
|
27
|
+
|
28
28
|
before { allow(response).to receive(:body).and_return(body) }
|
29
29
|
|
30
30
|
describe 'parsing' do
|
@@ -36,7 +36,7 @@ describe Restify::Processors::Base do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it { is_expected.to be_a Restify::Resource }
|
39
|
-
it { expect(
|
39
|
+
it { expect(resource.response).to be response }
|
40
40
|
it { is_expected.to eq body }
|
41
41
|
end
|
42
42
|
end
|
@@ -4,31 +4,31 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Restify::Processors::Json do
|
6
6
|
let(:context) { Restify::Context.new('http://test.host/') }
|
7
|
-
let(:response) {
|
7
|
+
let(:response) { instance_double(Restify::Response) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
allow(response).to
|
11
|
-
allow(response).to receive(:follow_location).and_return nil
|
10
|
+
allow(response).to receive_messages(links: [], follow_location: nil)
|
12
11
|
end
|
13
12
|
|
14
13
|
describe 'class' do
|
15
14
|
describe '#accept?' do
|
16
|
-
subject { described_class.accept?
|
15
|
+
subject(:accept) { described_class.accept?(response) }
|
17
16
|
|
18
17
|
it 'accepts JSON mime type (I)' do
|
19
|
-
|
20
|
-
expect(
|
18
|
+
allow(response).to receive(:content_type).and_return('application/json')
|
19
|
+
expect(accept).to be_truthy
|
21
20
|
end
|
22
21
|
|
23
22
|
it 'accepts JSON mime type (II)' do
|
24
|
-
|
25
|
-
expect(
|
23
|
+
allow(response).to receive(:content_type).and_return('application/json; abc')
|
24
|
+
expect(accept).to be_truthy
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
29
28
|
|
30
29
|
describe '#resource' do
|
31
|
-
subject { described_class.new(context, response).resource }
|
30
|
+
subject(:resource) { described_class.new(context, response).resource }
|
31
|
+
|
32
32
|
before { allow(response).to receive(:body).and_return(body) }
|
33
33
|
|
34
34
|
describe 'parsing' do
|
@@ -40,7 +40,7 @@ describe Restify::Processors::Json do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it { is_expected.to be_a Restify::Resource }
|
43
|
-
it { expect(
|
43
|
+
it { expect(resource.response).to be response }
|
44
44
|
it { is_expected.to eq 'json' => 'value' }
|
45
45
|
end
|
46
46
|
|
@@ -52,12 +52,12 @@ describe Restify::Processors::Json do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it do
|
55
|
-
|
55
|
+
expect(resource).to eq \
|
56
56
|
'json' => 'value', 'search_url' => 'https://google.com{?q}'
|
57
57
|
end
|
58
58
|
|
59
59
|
it { is_expected.to have_relation :search }
|
60
|
-
it { expect(
|
60
|
+
it { expect(resource.relation(:search)).to eq 'https://google.com{?q}' }
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'object with implicit self relation' do
|
@@ -67,7 +67,7 @@ describe Restify::Processors::Json do
|
|
67
67
|
JSON
|
68
68
|
end
|
69
69
|
|
70
|
-
it { expect(
|
70
|
+
it { expect(resource.relation(:self)).to eq '/self' }
|
71
71
|
end
|
72
72
|
|
73
73
|
context 'single array' do
|
@@ -78,7 +78,7 @@ describe Restify::Processors::Json do
|
|
78
78
|
end
|
79
79
|
|
80
80
|
it { is_expected.to be_a Restify::Resource }
|
81
|
-
it { expect(
|
81
|
+
it { expect(resource.response).to be response }
|
82
82
|
it { is_expected.to eq [1, 2, nil, 'STR'] }
|
83
83
|
end
|
84
84
|
|
@@ -101,11 +101,11 @@ describe Restify::Processors::Json do
|
|
101
101
|
end
|
102
102
|
|
103
103
|
it 'parses objects as resources' do
|
104
|
-
expect(
|
104
|
+
expect(resource).to all(be_a(Restify::Resource))
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'parses relations of resources' do
|
108
|
-
expect(
|
108
|
+
expect(resource.map {|r| r.relation :self }).to eq \
|
109
109
|
['/users/john', '/users/jane']
|
110
110
|
end
|
111
111
|
end
|
@@ -119,14 +119,14 @@ describe Restify::Processors::Json do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it { is_expected.to be_a Restify::Resource }
|
122
|
-
it { expect(
|
122
|
+
it { expect(resource.response).to be response }
|
123
123
|
|
124
124
|
it 'parses objects as resources' do
|
125
|
-
expect(
|
126
|
-
expect(
|
125
|
+
expect(resource['john']).to be_a Restify::Resource
|
126
|
+
expect(resource['jane']).to be_a Restify::Resource
|
127
127
|
|
128
|
-
expect(
|
129
|
-
expect(
|
128
|
+
expect(resource['john']['name']).to eq 'John'
|
129
|
+
expect(resource['jane']['name']).to eq 'Jane'
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -138,49 +138,9 @@ describe Restify::Processors::Json do
|
|
138
138
|
end
|
139
139
|
|
140
140
|
it { is_expected.to be_a Restify::Resource }
|
141
|
-
it { expect(
|
141
|
+
it { expect(resource.response).to be response }
|
142
142
|
it { is_expected.to eq 'BLUB' }
|
143
143
|
end
|
144
|
-
|
145
|
-
context 'with indifferent access' do
|
146
|
-
let(:body) do
|
147
|
-
<<-JSON
|
148
|
-
{"name": "John", "age": 24}
|
149
|
-
JSON
|
150
|
-
end
|
151
|
-
|
152
|
-
it '#key?' do
|
153
|
-
expect(subject).to have_key 'name'
|
154
|
-
expect(subject).to have_key 'age'
|
155
|
-
|
156
|
-
expect(subject).to have_key :name
|
157
|
-
expect(subject).to have_key :age
|
158
|
-
end
|
159
|
-
|
160
|
-
it '#[]' do
|
161
|
-
expect(subject['name']).to eq 'John'
|
162
|
-
expect(subject['age']).to eq 24
|
163
|
-
|
164
|
-
expect(subject[:name]).to eq 'John'
|
165
|
-
expect(subject[:age]).to eq 24
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
context 'with method getter access' do
|
170
|
-
let(:body) do
|
171
|
-
<<-JSON
|
172
|
-
{"name": "John", "age": 24}
|
173
|
-
JSON
|
174
|
-
end
|
175
|
-
|
176
|
-
it '#<method getter>' do
|
177
|
-
expect(subject).to respond_to :name
|
178
|
-
expect(subject).to respond_to :age
|
179
|
-
|
180
|
-
expect(subject.name).to eq 'John'
|
181
|
-
expect(subject.age).to eq 24
|
182
|
-
end
|
183
|
-
end
|
184
144
|
end
|
185
145
|
end
|
186
146
|
end
|
@@ -4,94 +4,94 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
describe Restify::Processors::Msgpack do
|
6
6
|
let(:context) { Restify::Context.new('http://test.host/') }
|
7
|
-
let(:response) {
|
7
|
+
let(:response) { instance_double(Restify::Response) }
|
8
8
|
|
9
9
|
before do
|
10
|
-
allow(response).to
|
11
|
-
allow(response).to receive(:follow_location).and_return nil
|
10
|
+
allow(response).to receive_messages(links: [], follow_location: nil)
|
12
11
|
end
|
13
12
|
|
14
13
|
describe 'class' do
|
15
14
|
describe '#accept?' do
|
16
|
-
subject { described_class.accept?
|
15
|
+
subject(:accept) { described_class.accept?(response) }
|
17
16
|
|
18
17
|
it 'accepts msgpack mime type (I)' do
|
19
|
-
|
20
|
-
expect(
|
18
|
+
allow(response).to receive(:content_type).and_return('application/msgpack')
|
19
|
+
expect(accept).to be_truthy
|
21
20
|
end
|
22
21
|
|
23
22
|
it 'accepts msgpack mime type (II)' do
|
24
|
-
|
25
|
-
expect(
|
23
|
+
allow(response).to receive(:content_type).and_return('application/msgpack; abc')
|
24
|
+
expect(accept).to be_truthy
|
26
25
|
end
|
27
26
|
|
28
27
|
it 'accepts x-msgpack mime type (I)' do
|
29
|
-
|
30
|
-
expect(
|
28
|
+
allow(response).to receive(:content_type).and_return('application/x-msgpack')
|
29
|
+
expect(accept).to be_truthy
|
31
30
|
end
|
32
31
|
|
33
32
|
it 'accepts x-msgpack mime type (II)' do
|
34
|
-
|
35
|
-
expect(
|
33
|
+
allow(response).to receive(:content_type).and_return('application/x-msgpack; abc')
|
34
|
+
expect(accept).to be_truthy
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
38
|
|
40
39
|
describe '#resource' do
|
41
|
-
subject { described_class.new(context, response).resource }
|
40
|
+
subject(:resource) { described_class.new(context, response).resource }
|
41
|
+
|
42
42
|
before { allow(response).to receive(:body).and_return(body) }
|
43
43
|
|
44
44
|
describe 'parsing' do
|
45
45
|
context 'single object' do
|
46
46
|
let(:body) do
|
47
|
-
|
47
|
+
MessagePack.dump('msg' => 'value')
|
48
48
|
end
|
49
49
|
|
50
50
|
it { is_expected.to be_a Restify::Resource }
|
51
|
-
it { expect(
|
51
|
+
it { expect(resource.response).to be response }
|
52
52
|
it { is_expected.to eq 'msg' => 'value' }
|
53
53
|
end
|
54
54
|
|
55
55
|
context 'object with relation fields' do
|
56
56
|
let(:body) do
|
57
|
-
|
57
|
+
MessagePack.dump(
|
58
58
|
'msg' => 'value',
|
59
|
-
'search_url' => 'https://google.com{?q}'
|
59
|
+
'search_url' => 'https://google.com{?q}',
|
60
60
|
)
|
61
61
|
end
|
62
62
|
|
63
63
|
it do
|
64
|
-
|
64
|
+
expect(resource).to eq \
|
65
65
|
'msg' => 'value', 'search_url' => 'https://google.com{?q}'
|
66
66
|
end
|
67
67
|
|
68
68
|
it { is_expected.to have_relation :search }
|
69
|
-
it { expect(
|
69
|
+
it { expect(resource.relation(:search)).to eq 'https://google.com{?q}' }
|
70
70
|
end
|
71
71
|
|
72
72
|
context 'object with implicit self relation' do
|
73
73
|
let(:body) do
|
74
|
-
|
75
|
-
'url' => '/self'
|
74
|
+
MessagePack.dump(
|
75
|
+
'url' => '/self',
|
76
76
|
)
|
77
77
|
end
|
78
78
|
|
79
|
-
it { expect(
|
79
|
+
it { expect(resource.relation(:self)).to eq '/self' }
|
80
80
|
end
|
81
81
|
|
82
82
|
context 'single array' do
|
83
83
|
let(:body) do
|
84
|
-
|
84
|
+
MessagePack.dump([1, 2, nil, 'STR'])
|
85
85
|
end
|
86
86
|
|
87
87
|
it { is_expected.to be_a Restify::Resource }
|
88
|
-
it { expect(
|
88
|
+
it { expect(resource.response).to be response }
|
89
89
|
it { is_expected.to eq [1, 2, nil, 'STR'] }
|
90
90
|
end
|
91
91
|
|
92
92
|
context 'array with objects' do
|
93
93
|
let(:body) do
|
94
|
-
|
94
|
+
MessagePack.dump([{'a' => 0}, {'b' => 1}])
|
95
95
|
end
|
96
96
|
|
97
97
|
it { is_expected.to eq [{'a' => 0}, {'b' => 1}] }
|
@@ -99,87 +99,51 @@ describe Restify::Processors::Msgpack do
|
|
99
99
|
|
100
100
|
context 'array with resources' do
|
101
101
|
let(:body) do
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
102
|
+
MessagePack.dump([
|
103
|
+
{'name' => 'John', 'self_url' => '/users/john'},
|
104
|
+
{'name' => 'Jane', 'self_url' => '/users/jane'},
|
105
|
+
])
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'parses objects as resources' do
|
109
|
-
expect(
|
109
|
+
expect(resource).to all(be_a(Restify::Resource))
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'parses relations of resources' do
|
113
|
-
expect(
|
113
|
+
expect(resource.map {|r| r.relation :self }).to eq \
|
114
114
|
['/users/john', '/users/jane']
|
115
115
|
end
|
116
116
|
end
|
117
117
|
|
118
118
|
context 'nested objects' do
|
119
119
|
let(:body) do
|
120
|
-
|
120
|
+
MessagePack.dump(
|
121
121
|
'john' => {'name' => 'John'},
|
122
|
-
'jane' => {'name' => 'Jane'}
|
122
|
+
'jane' => {'name' => 'Jane'},
|
123
123
|
)
|
124
124
|
end
|
125
125
|
|
126
126
|
it { is_expected.to be_a Restify::Resource }
|
127
|
-
it { expect(
|
127
|
+
it { expect(resource.response).to be response }
|
128
128
|
|
129
129
|
it 'parses objects as resources' do
|
130
|
-
expect(
|
131
|
-
expect(
|
130
|
+
expect(resource['john']).to be_a Restify::Resource
|
131
|
+
expect(resource['jane']).to be_a Restify::Resource
|
132
132
|
|
133
|
-
expect(
|
134
|
-
expect(
|
133
|
+
expect(resource['john']['name']).to eq 'John'
|
134
|
+
expect(resource['jane']['name']).to eq 'Jane'
|
135
135
|
end
|
136
136
|
end
|
137
137
|
|
138
138
|
context 'single value' do
|
139
139
|
let(:body) do
|
140
|
-
|
140
|
+
MessagePack.dump('BLUB')
|
141
141
|
end
|
142
142
|
|
143
143
|
it { is_expected.to be_a Restify::Resource }
|
144
|
-
it { expect(
|
144
|
+
it { expect(resource.response).to be response }
|
145
145
|
it { is_expected.to eq 'BLUB' }
|
146
146
|
end
|
147
|
-
|
148
|
-
context 'with indifferent access' do
|
149
|
-
let(:body) do
|
150
|
-
::MessagePack.dump('name' => 'John', 'age' => 24)
|
151
|
-
end
|
152
|
-
|
153
|
-
it '#key?' do
|
154
|
-
expect(subject).to have_key 'name'
|
155
|
-
expect(subject).to have_key 'age'
|
156
|
-
|
157
|
-
expect(subject).to have_key :name
|
158
|
-
expect(subject).to have_key :age
|
159
|
-
end
|
160
|
-
|
161
|
-
it '#[]' do
|
162
|
-
expect(subject['name']).to eq 'John'
|
163
|
-
expect(subject['age']).to eq 24
|
164
|
-
|
165
|
-
expect(subject[:name]).to eq 'John'
|
166
|
-
expect(subject[:age]).to eq 24
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context 'with method getter access' do
|
171
|
-
let(:body) do
|
172
|
-
::MessagePack.dump('name' => 'John', 'age' => 24)
|
173
|
-
end
|
174
|
-
|
175
|
-
it '#<method getter>' do
|
176
|
-
expect(subject).to respond_to :name
|
177
|
-
expect(subject).to respond_to :age
|
178
|
-
|
179
|
-
expect(subject.name).to eq 'John'
|
180
|
-
expect(subject.age).to eq 24
|
181
|
-
end
|
182
|
-
end
|
183
147
|
end
|
184
148
|
end
|
185
149
|
end
|