lhs 18.0.0 → 18.0.1

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
  SHA256:
3
- metadata.gz: 7dd8872b9c48b4fa2acd3f2298aa3ae666fa38f1b2ebebeea5117d52b50f0577
4
- data.tar.gz: 47447df65903e2c126f58d9886721f68986f0afbf338a0823cff22b0965e5eeb
3
+ metadata.gz: d04ba2057e1535e9a26b924e5bc9d3e9a86ddf77e6c626f1c7375ea808d928a0
4
+ data.tar.gz: 25532cfc5d304b31e1d61de0e9e059d7ffe94ae147a9c362d3410e6f4979cb75
5
5
  SHA512:
6
- metadata.gz: 6f8e362f9169f983d86a4874995ce5344617929f6e33385f0d23ed2f5e2de291ce8a62a9d05284edae29ac5b475ec8507051de803bb6b91b4b8291e483221a23
7
- data.tar.gz: 8839be8d44bcb8a4298e407bc898a39691d7282c812dae3b6c8625f8a5196b5b8bb05633228e70a07d9fba3dd8c0b15aefb0de6eaac551575c03af4f5855e408
6
+ metadata.gz: 455ded1d51459437e1887c6f81ddf13d4a7f0df80f7b22dc6a7194b0d5e2a30461e410986a406fdda3d7918f639065a1d3d38314504727c6dcbd8381b106122c
7
+ data.tar.gz: 7d5341a694feea1b308823bc7e997128b0ae0f209ed8997473c69804babcbdd1def2d4d6eb5ccaa38ce84a97415e1e8450b9cfb0a4455dbe5d50d921bf5bc8fb
@@ -9,8 +9,30 @@ class LHS::Item < LHS::Proxy
9
9
 
10
10
  def destroy(options = {})
11
11
  options ||= {}
12
- _data._request = _data.class.request(options.merge(method: :delete, url: href))._request
12
+ options = options.merge(method: :delete)
13
+ data = _data._raw.dup
14
+ url = url_for_deletion!(options, data)
15
+ options = options.merge(url: url)
16
+ _data._request = _data.class.request(options)._request
13
17
  _data
14
18
  end
19
+
20
+ private
21
+
22
+ def url_for_deletion!(options, data)
23
+ return href if href.present?
24
+ endpoint = endpoint_for_deletion(data, options)
25
+ endpoint.compile(
26
+ merge_data_with_options(data, options)
27
+ ).tap do
28
+ endpoint.remove_interpolated_params!(data)
29
+ endpoint.remove_interpolated_params!(options.fetch(:params, {}))
30
+ options.merge!(endpoint.options.merge(options)) if endpoint.options
31
+ end
32
+ end
33
+
34
+ def endpoint_for_deletion(data, options)
35
+ record.find_endpoint(merge_data_with_options(data, options))
36
+ end
15
37
  end
16
38
  end
@@ -48,14 +48,6 @@ class LHS::Item < LHS::Proxy
48
48
  record.find_endpoint(merge_data_with_options(data, options))
49
49
  end
50
50
 
51
- def merge_data_with_options(data, options)
52
- if options && options[:params]
53
- data.merge(options[:params])
54
- else
55
- data
56
- end
57
- end
58
-
59
51
  def url_for_persistance!(options, data)
60
52
  return href if href.present?
61
53
  endpoint = endpoint_for_persistance(data, options)
data/lib/lhs/proxy.rb CHANGED
@@ -57,4 +57,12 @@ class LHS::Proxy
57
57
  return { params: { id: as_record.id } } if as_record.id
58
58
  {}
59
59
  end
60
+
61
+ def merge_data_with_options(data, options)
62
+ if options && options[:params]
63
+ data.merge(options[:params])
64
+ else
65
+ data
66
+ end
67
+ end
60
68
  end
data/lib/lhs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LHS
4
- VERSION = '18.0.0'
4
+ VERSION = '18.0.1'
5
5
  end
@@ -60,5 +60,54 @@ describe LHS::Item do
60
60
  item.destroy
61
61
  end
62
62
  end
63
+
64
+ context 'when item does not have any href' do
65
+ let(:business_data) do
66
+ {
67
+ id: '12345',
68
+ name: 'localsearch'
69
+ }
70
+ end
71
+
72
+ let(:business_collection) do
73
+ [business_data]
74
+ end
75
+
76
+ before do
77
+ class Business < LHS::Record
78
+ endpoint 'https://uberall/businesses'
79
+ endpoint 'https://uberall/businesses/{id}'
80
+ end
81
+
82
+ stub_request(:get, "https://uberall/businesses")
83
+ .to_return(body: business_collection.to_json)
84
+
85
+ stub_request(:delete, "https://uberall/businesses/12345")
86
+ .to_return(body: {
87
+ status: 'SUCCESS',
88
+ response: {
89
+ success: true
90
+ }
91
+ }.to_json)
92
+ end
93
+
94
+ it "destroys the item using it's own id (data)" do
95
+ business = Business.fetch.first
96
+ expect(business.destroy._raw).to eq business_data
97
+ end
98
+
99
+ context 'item does not have an id' do
100
+ let(:business_data) do
101
+ {
102
+ name: 'localsearch'
103
+ }
104
+ end
105
+
106
+ it 'destroy the item using the id passed as options' do
107
+ business = Business.fetch.first
108
+ expect(business.destroy(params: { id: '12345' })._raw).to eq business_data
109
+ end
110
+ end
111
+ end
63
112
  end
64
113
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 18.0.0
4
+ version: 18.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors