lhs 11.2.1 → 11.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 03ef3cf453e687b887eecf083b9db24027367077
4
- data.tar.gz: 813cf6662e7e1b84fc88f7bbea58e9ede0bd78f9
3
+ metadata.gz: 3dfd9e57f04eb43210b4178efe52fd0fddcbe7de
4
+ data.tar.gz: 41c60bc23a3c4ad5ad4e215c62ea96d969e4f479
5
5
  SHA512:
6
- metadata.gz: bbab32a774d4fc31d35cec8a4a58d4ab9727f8605073ff4887b01fe6714248d77140987767e2d7c58a086869784d322114daebe637387440feb0286a26935163
7
- data.tar.gz: e8e4c55d6c74e2286d0adc4cb77295d95df5bf902a8984e552ee5e719eee7db55222c604356e79a63296f0b94c9dcea91c343bc78931744433d478e1b5cb13c6
6
+ metadata.gz: 971b794d749267d8c055ce020828632f5575bff89d0005052e8600babec47d6ae64121a86ab2d2d34ae85eb570ef739938662b60e9d2dc5760a744d55be104d7
7
+ data.tar.gz: f9ae285b2f0aa39aae2a4dc547f384e3890ca2cde1359c29d535bcac3bdaf3542c8cba8b6860b5d60a487a6f439fcdd3370ced438b08c6cf56337182aed6d5c1
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.requirements << 'Ruby >= 2.0.0'
21
21
  s.required_ruby_version = '>= 2.0.0'
22
22
 
23
- s.add_dependency 'lhc', '>= 5.0.3'
23
+ s.add_dependency 'lhc', '>= 5.1.1'
24
24
  s.add_dependency 'activesupport', '> 4.2'
25
25
 
26
26
  s.add_development_dependency 'rspec-rails', '>= 3.0.0'
@@ -56,7 +56,6 @@ class LHS::Record
56
56
 
57
57
  # Computes the url from params
58
58
  # by identifiying endpoint and compiles it if necessary.
59
- # Id in params is threaded in a special way.
60
59
  def compute_url!(params)
61
60
  endpoint = find_endpoint(params)
62
61
  url = endpoint.compile(params)
@@ -64,6 +63,11 @@ class LHS::Record
64
63
  url
65
64
  end
66
65
 
66
+ def compute_url(params)
67
+ find_endpoint(params)
68
+ .compile(params)
69
+ end
70
+
67
71
  private
68
72
 
69
73
  def validates_deprecation_check!(options)
@@ -50,7 +50,7 @@ class LHS::Record
50
50
  return unless endpoint
51
51
  template = endpoint.url
52
52
  new_options = options.deep_merge(
53
- params: LHC::Endpoint.values_as_params(template, url).merge(values_from_get_params(url))
53
+ params: LHC::Endpoint.values_as_params(template, url).merge(values_from_get_params(url, options))
54
54
  )
55
55
  new_options[:url] = template
56
56
  new_options
@@ -58,13 +58,23 @@ class LHS::Record
58
58
 
59
59
  # Extracts values from url's get parameters
60
60
  # and return them as a ruby hash
61
- def values_from_get_params(url)
62
- uri = URI.parse(url)
61
+ def values_from_get_params(url, options)
62
+ uri = parse_uri(url, options)
63
63
  return {} unless uri.query.present?
64
64
  params = Rack::Utils.parse_nested_query(uri.query)
65
65
  params
66
66
  end
67
67
 
68
+ def parse_uri(url, options)
69
+ URI.parse(
70
+ if url.match(LHC::Endpoint::PLACEHOLDER)
71
+ compute_url(options[:params])
72
+ else
73
+ url
74
+ end
75
+ )
76
+ end
77
+
68
78
  # Extends existing raw data with additionaly fetched data
69
79
  def extend_raw_data!(data, addition, key)
70
80
  if data.collection?
@@ -292,7 +302,7 @@ class LHS::Record
292
302
  # as we have to fetch all resources on this level first, before we continue_including
293
303
  def prepare_option_for_include_all_request!(option)
294
304
  return option if option.empty? || option[:url].nil?
295
- uri = URI.parse(option[:url])
305
+ uri = parse_uri(option[:url], option)
296
306
  get_params = Rack::Utils.parse_nested_query(uri.query)
297
307
  .symbolize_keys
298
308
  .except(limit_key, pagination_key)
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "11.2.1"
2
+ VERSION = "11.2.2"
3
3
  end
@@ -211,5 +211,54 @@ describe LHS::Record do
211
211
  end
212
212
  end
213
213
  end
214
+
215
+ context 'include a known/identifiable record' do
216
+ before(:each) do
217
+ class Contract < LHS::Record
218
+ endpoint 'http://datastore/contracts/:id'
219
+ end
220
+
221
+ class Entry < LHS::Record
222
+ endpoint ':datastore/entry/v1/:id.json'
223
+ end
224
+
225
+ LHC.config.placeholder(:datastore, 'http://datastore')
226
+ end
227
+
228
+ let!(:customer_request) do
229
+ stub_request(:get, %r{http://datastore/customers/\d+})
230
+ .to_return(
231
+ body: {
232
+ contracts: [{ href: 'http://datastore/contracts/1' }, { href: 'http://datastore/contracts/2' }]
233
+ }.to_json
234
+ )
235
+ end
236
+
237
+ let!(:contracts_request) do
238
+ stub_request(:get, %r{http://datastore/contracts/\d+})
239
+ .to_return(
240
+ body: {
241
+ type: 'contract',
242
+ entry: { href: 'http://datastore/entry/v1/1.json' }
243
+ }.to_json
244
+ )
245
+ end
246
+
247
+ let!(:entry_request) do
248
+ stub_request(:get, %r{http://datastore/entry/v1/\d+.json})
249
+ .to_return(
250
+ body: {
251
+ name: 'Casa Ferlin'
252
+ }.to_json
253
+ )
254
+ end
255
+
256
+ it 'loads included identifiable records without raising exceptions' do
257
+ customer = Customer.includes_all(contracts: :entry).find(1, 2).first
258
+ expect(customer.contracts.first.href).to eq 'http://datastore/contracts/1'
259
+ expect(customer.contracts.first.type).to eq 'contract'
260
+ expect(customer.contracts.first.entry.name).to eq 'Casa Ferlin'
261
+ end
262
+ end
214
263
  end
215
264
  end
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.2.1
4
+ version: 11.2.2
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-06-07 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 5.0.3
19
+ version: 5.1.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 5.0.3
26
+ version: 5.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement