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 +4 -4
- data/lib/lhs/concerns/item/destroy.rb +23 -1
- data/lib/lhs/concerns/item/save.rb +0 -8
- data/lib/lhs/proxy.rb +8 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/item/destroy_spec.rb +49 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d04ba2057e1535e9a26b924e5bc9d3e9a86ddf77e6c626f1c7375ea808d928a0
|
4
|
+
data.tar.gz: 25532cfc5d304b31e1d61de0e9e059d7ffe94ae147a9c362d3410e6f4979cb75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
data/lib/lhs/version.rb
CHANGED
data/spec/item/destroy_spec.rb
CHANGED
@@ -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
|