lhs 11.0.2 → 11.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhs/concerns/record/request.rb +8 -2
- data/lib/lhs/version.rb +1 -1
- data/spec/concerns/record/request_spec.rb +76 -0
- data/spec/record/includes_all_spec.rb +53 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc9d93456e8c4ad57a3883f582dd868169272980
|
4
|
+
data.tar.gz: d741c6a54fcdbe5c7b72a8f226fd290485d5e218
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1dbba4cf7b6d320d0a16ff0582159a50565d6f5e5ba037e0c0bbebc3c708d3e50403df9846a35b26879dc48f116349ec961cd4c418c3a97ac6302c916280c91
|
7
|
+
data.tar.gz: d6d14efc2d3558dd996aba3bcc9da903e8a19ca118dd8d2b760a3bab415b13807512740ae947524f0894984f1e373c7e9d96cfa49e0cb29de6d95c3fd30b2156
|
@@ -291,9 +291,15 @@ class LHS::Record
|
|
291
291
|
# When including all resources on one level, don't forward :includes & :references
|
292
292
|
# as we have to fetch all resources on this level first, before we continue_including
|
293
293
|
def prepare_option_for_include_all_request!(option)
|
294
|
-
return option
|
294
|
+
return option if option.empty? || option[:url].nil?
|
295
|
+
uri = URI.parse(option[:url])
|
296
|
+
get_params = Rack::Utils.parse_nested_query(uri.query)
|
297
|
+
.symbolize_keys
|
298
|
+
.except(limit_key, pagination_key)
|
295
299
|
option[:params] ||= {}
|
296
|
-
option[:params].
|
300
|
+
option[:params].reverse_merge!(get_params)
|
301
|
+
option[:params][limit_key] ||= LHS::Pagination::Base::DEFAULT_LIMIT
|
302
|
+
option[:url] = option[:url].gsub("?#{uri.query}", '')
|
297
303
|
option.delete(:including)
|
298
304
|
option.delete(:referencing)
|
299
305
|
option
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Record::Request do
|
4
|
+
subject do
|
5
|
+
Class.new do
|
6
|
+
include LHS::Record::Configuration
|
7
|
+
include LHS::Record::Request
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'prepare_options_for_include_all_request' do
|
12
|
+
it 'calls correct prepare method for nil' do
|
13
|
+
expect(subject).to receive(:prepare_option_for_include_all_request!)
|
14
|
+
.with(nil).and_return('ignore')
|
15
|
+
expect(subject.send(:prepare_options_for_include_all_request!, nil)).to be_nil
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'calls correct prepare method for a Hash' do
|
19
|
+
expect(subject).to receive(:prepare_option_for_include_all_request!)
|
20
|
+
.with(abc: 'def').and_return('ignore')
|
21
|
+
expect(subject.send(:prepare_options_for_include_all_request!, abc: 'def')).to eq(abc: 'def')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'calls correct prepare method for a Hash' do
|
25
|
+
expect(subject).to receive(:prepare_option_for_include_all_request!)
|
26
|
+
.with(abc: 'def').and_return('ignore')
|
27
|
+
expect(subject).to receive(:prepare_option_for_include_all_request!)
|
28
|
+
.with(hij: 'kel').and_return('ignore')
|
29
|
+
expect(subject.send(:prepare_options_for_include_all_request!, [{ abc: 'def' }, { hij: 'kel' }]))
|
30
|
+
.to eq([{ abc: 'def' }, { hij: 'kel' }])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe 'prepare_option_for_incldue_all_request' do
|
35
|
+
it 'removes all limit and offset parameters' do
|
36
|
+
option = { url: 'http://localhost:3000/test/resource?abc=def&limit=1&offset=3&test=2' }
|
37
|
+
expect(subject.send(:prepare_option_for_include_all_request!, option))
|
38
|
+
.to eq(option)
|
39
|
+
expect(option).to eq(url: 'http://localhost:3000/test/resource',
|
40
|
+
params: { limit: 100, abc: 'def', test: '2' })
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'do nothing without url' do
|
44
|
+
option = { param: { abc: 'def' } }
|
45
|
+
expect(subject.send(:prepare_option_for_include_all_request!, option))
|
46
|
+
.to eq(option)
|
47
|
+
expect(option).to eq(param: { abc: 'def' })
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'raises an exception when url invalid' do
|
51
|
+
option = { param: { abc: 'def' }, url: 'http://ab de.com/resource' }
|
52
|
+
expect { subject.send(:prepare_option_for_include_all_request!, option) }
|
53
|
+
.to raise_exception(URI::InvalidURIError)
|
54
|
+
expect(option).to eq(param: { abc: 'def' }, url: 'http://ab de.com/resource')
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'keeps current params over url params' do
|
58
|
+
option = { url: 'http://localhost:3000/test/resource?abc=def&limit=1&offset=3&test=2',
|
59
|
+
params: { abc: '123' } }
|
60
|
+
expect(subject.send(:prepare_option_for_include_all_request!, option))
|
61
|
+
.to eq(option)
|
62
|
+
expect(option).to eq(url: 'http://localhost:3000/test/resource',
|
63
|
+
params: { limit: 100, abc: '123', test: '2' })
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'removes including and referening options' do
|
67
|
+
option = { url: 'http://localhost:3000/test/resource',
|
68
|
+
including: 'all',
|
69
|
+
referencing: 'nothing' }
|
70
|
+
expect(subject.send(:prepare_option_for_include_all_request!, option))
|
71
|
+
.to eq(option)
|
72
|
+
expect(option).to eq(url: 'http://localhost:3000/test/resource',
|
73
|
+
params: { limit: 100 })
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -116,6 +116,59 @@ describe LHS::Record do
|
|
116
116
|
expect(products_request_page_3).to have_been_requested.at_least_once
|
117
117
|
end
|
118
118
|
|
119
|
+
context 'links already contain pagination parameters' do
|
120
|
+
let!(:customer_request) do
|
121
|
+
stub_request(:get, 'http://datastore/customers/1')
|
122
|
+
.to_return(
|
123
|
+
body: {
|
124
|
+
contracts: { href: 'http://datastore/customers/1/contracts?limit=5&offset=0' }
|
125
|
+
}.to_json
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
129
|
+
let!(:contracts_request) do
|
130
|
+
stub_request(:get, "http://datastore/customers/1/contracts?limit=100")
|
131
|
+
.to_return(
|
132
|
+
body: {
|
133
|
+
items: 10.times.map do
|
134
|
+
{
|
135
|
+
products: { href: 'http://datastore/products' }
|
136
|
+
}
|
137
|
+
end,
|
138
|
+
limit: 10,
|
139
|
+
offset: 0,
|
140
|
+
total: amount_of_contracts
|
141
|
+
}.to_json
|
142
|
+
)
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'overwrites existing pagination paramters if they are already contained in a string' do
|
146
|
+
expect(LHC).to receive(:request)
|
147
|
+
.with(url: "http://datastore/customers/1").and_call_original
|
148
|
+
|
149
|
+
expect(LHC).to receive(:request)
|
150
|
+
.with(url: "http://datastore/customers/1/contracts",
|
151
|
+
all: true,
|
152
|
+
params: { limit: 100 }).and_call_original
|
153
|
+
|
154
|
+
expect(LHC).to receive(:request)
|
155
|
+
.with([{ url: "http://datastore/customers/1/contracts",
|
156
|
+
all: true,
|
157
|
+
params: { limit: 10, offset: 10 } },
|
158
|
+
{ url: "http://datastore/customers/1/contracts",
|
159
|
+
all: true,
|
160
|
+
params: { limit: 10, offset: 20 } },
|
161
|
+
{ url: "http://datastore/customers/1/contracts",
|
162
|
+
all: true,
|
163
|
+
params: { limit: 10, offset: 30 } }]).and_call_original
|
164
|
+
|
165
|
+
customer = Customer
|
166
|
+
.includes_all(:contracts)
|
167
|
+
.find(1)
|
168
|
+
expect(customer.contracts.length).to eq amount_of_contracts
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
119
172
|
context 'includes for an empty array' do
|
120
173
|
before(:each) do
|
121
174
|
class Contract < LHS::Record
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 11.0.
|
4
|
+
version: 11.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -239,6 +239,7 @@ files:
|
|
239
239
|
- spec/collection/respond_to_spec.rb
|
240
240
|
- spec/collection/without_object_items_spec.rb
|
241
241
|
- spec/complex/reduce_spec.rb
|
242
|
+
- spec/concerns/record/request_spec.rb
|
242
243
|
- spec/data/collection_spec.rb
|
243
244
|
- spec/data/equality_spec.rb
|
244
245
|
- spec/data/inspect_spec.rb
|
@@ -385,7 +386,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
385
386
|
requirements:
|
386
387
|
- Ruby >= 2.0.0
|
387
388
|
rubyforge_project:
|
388
|
-
rubygems_version: 2.
|
389
|
+
rubygems_version: 2.5.1
|
389
390
|
signing_key:
|
390
391
|
specification_version: 4
|
391
392
|
summary: Rails gem providing an easy, active-record-like interface for http json services
|
@@ -401,6 +402,7 @@ test_files:
|
|
401
402
|
- spec/collection/respond_to_spec.rb
|
402
403
|
- spec/collection/without_object_items_spec.rb
|
403
404
|
- spec/complex/reduce_spec.rb
|
405
|
+
- spec/concerns/record/request_spec.rb
|
404
406
|
- spec/data/collection_spec.rb
|
405
407
|
- spec/data/equality_spec.rb
|
406
408
|
- spec/data/inspect_spec.rb
|