artirix_data_models 0.7.5 → 0.8.3
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/README.md +30 -22
- data/lib/artirix_data_models/daos/basic_model_dao.rb +8 -0
- data/lib/artirix_data_models/gateways/data_gateway.rb +60 -54
- data/lib/artirix_data_models/model.rb +32 -1
- data/lib/artirix_data_models/spec_support/gateway_mock.rb +51 -4
- data/lib/artirix_data_models/version.rb +1 -1
- data/spec/artirix_data_models/gateways/data_gateway_spec.rb +139 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2359922337aa2624392a98ae869724c2a3afa640
|
|
4
|
+
data.tar.gz: ec9c7dfcc6fe58d603176940e0e0e4f39314fc41
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 08cce0d7e14055cc719a79a202266becd424dc9a53689e00c45d788531bd9928f6880a597f28fd9b8c91cf780f33daab2fafefb713c83edfe421b90355046eb9
|
|
7
|
+
data.tar.gz: b68d7c20dc2741561c482917edd897abd97bb80d8bc77d0e9a9a27790a855ca3625657d38a271fa76a12dfa633ba53d0c17039e5f5f8195a4f24524dcde792e9
|
data/README.md
CHANGED
|
@@ -250,6 +250,17 @@ end
|
|
|
250
250
|
|
|
251
251
|
## Changes
|
|
252
252
|
|
|
253
|
+
### 0.8.3
|
|
254
|
+
|
|
255
|
+
- `DataGateway` refactor, plus adding `put` and `delete` support.
|
|
256
|
+
- `BasicModelDAO` with `_put` and `_delete` support.
|
|
257
|
+
- adding gateway mock helpers for `post`, `put` and `delete`, and adapting them to the new behaviour
|
|
258
|
+
- including `ArtirixDataModels::Model::PublicWriters` after `ArtirixDataModels::Model::Attributes` (or after `ArtirixDataModels::Model` or `ArtirixDataModels::Model::OnlyData`) and before calling `attribute` method to make attribute writers public.
|
|
259
|
+
|
|
260
|
+
### ~0.8.0~, ~0.8.1~, ~0.8.2~ (YANKED)
|
|
261
|
+
|
|
262
|
+
Yanked because of the gateway mock helpers were missing an option, which made them not mocking properly. (moved all to `0.8.3`)
|
|
263
|
+
|
|
253
264
|
### 0.7.5
|
|
254
265
|
|
|
255
266
|
- `FakeResponseFactory` using given `_score` if > 0.
|
|
@@ -278,6 +289,10 @@ end
|
|
|
278
289
|
- changed classes to stop inheriting from `Struct`, had some problems with inheritance.
|
|
279
290
|
- `Aggregation`, `Aggregation::Value` and `MetricAggregation` now using the same inspection as models.
|
|
280
291
|
|
|
292
|
+
### ~0.7.0~ (YANKED)
|
|
293
|
+
|
|
294
|
+
Yanked because of bug on Aggregations. Released 0.7.1 with the fix. Changeset moved too to 0.7.1
|
|
295
|
+
|
|
281
296
|
### 0.6.7
|
|
282
297
|
|
|
283
298
|
- aggregations use `key_as_string` as name of the bucket value if it exists, if not then it uses `key` and if that also does not exist then it uses `name`
|
|
@@ -301,26 +316,7 @@ end
|
|
|
301
316
|
- Fix in EsCollection's aggregation parsing (nested + single from RAW now work ok)
|
|
302
317
|
- `SortedBucketAggregationBase` introduced. now `ArtirixDataModels::AggregationsFactory.sorted_aggregation_class_based_on_index_on(index_array)` available to create a class for Aggregations which will sort the buckets based on the position of the elements on a given array.
|
|
303
318
|
|
|
304
|
-
### 0.6.
|
|
305
|
-
|
|
306
|
-
*Fixed Breaking Change*: removal of `Aggregation.from_json` static method. Now back but delegating to default factory method is `aggregation_factory.aggregation_from_json` in the Aggregation Factory *instance*.
|
|
307
|
-
|
|
308
|
-
- EsCollection's aggregations can now be build based on raw ElasticSearch responses, including nested aggregations. It ignores any aggregation that does not have "buckets", so that nested aggs for `global` or `filtered` are skipped and only the ones with real data are used. (TODO: write docs. In the mean time, have a look at the specs).
|
|
309
|
-
- added `aggregation` method to `Aggregation::Value` class, and also the aggs to the `data_hash` if they are present.
|
|
310
|
-
|
|
311
|
-
### 0.5.0
|
|
312
|
-
|
|
313
|
-
- opening gem as is to the public.
|
|
314
|
-
- still a lot of TODOs in the documentation
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
## Yanked versions
|
|
318
|
-
|
|
319
|
-
### ~0.7.0~
|
|
320
|
-
|
|
321
|
-
Yanked because of bug on Aggregations. Released 0.7.1 with the fix. Changeset moved too to 0.7.1
|
|
322
|
-
|
|
323
|
-
### ~0.6.3~
|
|
319
|
+
### ~0.6.3~ (YANKED)
|
|
324
320
|
|
|
325
321
|
Yanked because of typo bug on SortedBucketAggregationBase. Released 0.6.3.1 with the fix.
|
|
326
322
|
|
|
@@ -328,15 +324,27 @@ Yanked because of typo bug on SortedBucketAggregationBase. Released 0.6.3.1 with
|
|
|
328
324
|
- Fix in EsCollection's aggregation parsing (nested + single from RAW now work ok)
|
|
329
325
|
- `SortedBucketAggregationBase` introduced. now `ArtirixDataModels::AggregationsFactory.sorted_aggregation_class_based_on_index_on(index_array)` available to create a class for Aggregations which will sort the buckets based on the position of the elements on a given array.
|
|
330
326
|
|
|
327
|
+
### 0.6.2
|
|
328
|
+
|
|
329
|
+
*Fixed Breaking Change*: removal of `Aggregation.from_json` static method. Now back but delegating to default factory method is `aggregation_factory.aggregation_from_json` in the Aggregation Factory *instance*.
|
|
330
|
+
|
|
331
|
+
- EsCollection's aggregations can now be build based on raw ElasticSearch responses, including nested aggregations. It ignores any aggregation that does not have "buckets", so that nested aggs for `global` or `filtered` are skipped and only the ones with real data are used. (TODO: write docs. In the mean time, have a look at the specs).
|
|
332
|
+
- added `aggregation` method to `Aggregation::Value` class, and also the aggs to the `data_hash` if they are present.
|
|
331
333
|
|
|
332
|
-
### ~0.6.1~
|
|
334
|
+
### ~0.6.1~ (YANKED)
|
|
333
335
|
|
|
334
336
|
Yanked because of breaking change introduction: removal of `Aggregation.from_json` method
|
|
335
337
|
|
|
336
338
|
- added `aggregation` method to `Aggregation::Value` class, and also the aggs to the `data_hash` if they are present.
|
|
337
339
|
|
|
338
|
-
### ~v0.6.0~
|
|
340
|
+
### ~v0.6.0~ (YANKED)
|
|
339
341
|
|
|
340
342
|
Yanked because of breaking change introduction: removal of `Aggregation.from_json` method
|
|
341
343
|
|
|
342
344
|
- EsCollection's aggregations can now be build based on raw ElasticSearch responses, including nested aggregations. It ignores any aggregation that does not have "buckets", so that nested aggs for `global` or `filtered` are skipped and only the ones with real data are used. (TODO: write docs. In the mean time, have a look at the specs).
|
|
345
|
+
|
|
346
|
+
### 0.5.0
|
|
347
|
+
|
|
348
|
+
- opening gem as is to the public.
|
|
349
|
+
- still a lot of TODOs in the documentation
|
|
350
|
+
|
|
@@ -124,6 +124,14 @@ class ArtirixDataModels::BasicModelDAO
|
|
|
124
124
|
gateway.post path, response_adaptor: response_adaptor, body: body, fake: fake?, fake_response: fake_response, cache_adaptor: cache_adaptor
|
|
125
125
|
end
|
|
126
126
|
|
|
127
|
+
def _put(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil)
|
|
128
|
+
gateway.put path, response_adaptor: response_adaptor, body: body, fake: fake?, fake_response: fake_response, cache_adaptor: cache_adaptor
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def _delete(path, response_adaptor: nil, body: nil, fake_response: nil, cache_adaptor: nil)
|
|
132
|
+
gateway.delete path, response_adaptor: response_adaptor, body: body, fake: fake?, fake_response: fake_response, cache_adaptor: cache_adaptor
|
|
133
|
+
end
|
|
134
|
+
|
|
127
135
|
def fake?
|
|
128
136
|
return true if forced_fake_enabled?
|
|
129
137
|
return false if forced_fake_disabled?
|
|
@@ -6,87 +6,93 @@ class ArtirixDataModels::DataGateway
|
|
|
6
6
|
@post_as_json = !!post_as_json
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def get(path,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
def get(path, **opts)
|
|
10
|
+
call :get, path, **opts
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def post(path, **opts)
|
|
14
|
+
call :post, path, **opts
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def put(path, **opts)
|
|
18
|
+
call :put, path, **opts
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def delete(path, **opts)
|
|
22
|
+
call :delete, path, **opts
|
|
18
23
|
end
|
|
19
24
|
|
|
20
|
-
def
|
|
25
|
+
def call(method, path, json_body: true, response_adaptor: nil, body: nil, fake: false, fake_response: nil, cache_adaptor: nil, **_ignored_options)
|
|
21
26
|
if fake
|
|
22
27
|
response_body = fake_response
|
|
28
|
+
elsif cache_adaptor.present?
|
|
29
|
+
response_body = cache_adaptor.call { perform(method, path, body, json_body) }
|
|
23
30
|
else
|
|
24
|
-
response_body =
|
|
31
|
+
response_body = perform(method, path, body, json_body)
|
|
25
32
|
end
|
|
26
|
-
|
|
33
|
+
parse_response(response_body, response_adaptor)
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
private
|
|
30
37
|
|
|
31
|
-
def perform_get(path, body = nil)
|
|
32
|
-
|
|
33
|
-
if response.success?
|
|
34
|
-
response.body
|
|
35
|
-
elsif response.status.to_i == 404
|
|
36
|
-
raise NotFound, path
|
|
37
|
-
else
|
|
38
|
-
raise GatewayError, "method: get, path: #{path}, status: #{response.status}, body: #{response.body}"
|
|
39
|
-
end
|
|
38
|
+
def perform_get(path, body = nil, json_body = true)
|
|
39
|
+
perform :get, path, body, json_body
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
-
def perform_post(path, body = nil)
|
|
43
|
-
|
|
44
|
-
if response.success?
|
|
45
|
-
response.body
|
|
46
|
-
elsif response.status.to_i == 404
|
|
47
|
-
raise NotFound, path
|
|
48
|
-
else
|
|
49
|
-
raise GatewayError, "method: post, path: #{path}, status: #{response.status}, body: #{response.body}"
|
|
50
|
-
end
|
|
42
|
+
def perform_post(path, body = nil, json_body = true)
|
|
43
|
+
perform :post, path, body, json_body
|
|
51
44
|
end
|
|
52
45
|
|
|
53
|
-
def
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
46
|
+
def perform_put(path, body = nil, json_body = true)
|
|
47
|
+
perform :put, path, body, json_body
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def perform_delete(path, body = nil, json_body = true)
|
|
51
|
+
perform :delete, path, body, json_body
|
|
59
52
|
end
|
|
60
53
|
|
|
61
|
-
def
|
|
62
|
-
|
|
54
|
+
def perform(method, path, body = nil, json_body = true)
|
|
55
|
+
response = connect(method, path, body, json_body)
|
|
56
|
+
treat_response(response, method, path)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def connect(method, path, body = nil, json_body = true)
|
|
60
|
+
# binding.pry if method == :delete
|
|
61
|
+
connection.send(method, path) do |req|
|
|
62
|
+
# binding.pry if method == :delete
|
|
63
63
|
unless body.nil?
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
if json_body
|
|
65
|
+
req.body = body_to_json body
|
|
66
|
+
req.headers['Content-Type'] = 'application/json'
|
|
67
|
+
else
|
|
68
|
+
req.body = body
|
|
69
|
+
end
|
|
66
70
|
end
|
|
67
71
|
end
|
|
68
72
|
rescue Faraday::ConnectionFailed => e
|
|
69
|
-
raise ConnectionError, "method:
|
|
73
|
+
raise ConnectionError, "method: #{method}, path: #{path}, error: #{e}"
|
|
70
74
|
end
|
|
71
75
|
|
|
72
|
-
def
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
def treat_response(response, method, path)
|
|
77
|
+
if response.success?
|
|
78
|
+
response.body
|
|
79
|
+
elsif response.status.to_i == 404
|
|
80
|
+
raise NotFound, path
|
|
81
|
+
else
|
|
82
|
+
raise GatewayError, "method: #{method}, path: #{path}, status: #{response.status}, body: #{response.body}"
|
|
78
83
|
end
|
|
79
84
|
end
|
|
80
85
|
|
|
81
|
-
def
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
def body_to_json(body)
|
|
87
|
+
case body
|
|
88
|
+
when String
|
|
89
|
+
body
|
|
90
|
+
else
|
|
91
|
+
body.to_json
|
|
92
|
+
end
|
|
87
93
|
end
|
|
88
94
|
|
|
89
|
-
def
|
|
95
|
+
def parse_response(result, response_adaptor)
|
|
90
96
|
if result.present?
|
|
91
97
|
parsed_response = Oj.load result, symbol_keys: true
|
|
92
98
|
else
|
|
@@ -51,6 +51,14 @@ module ArtirixDataModels
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
module PublicWriters
|
|
55
|
+
extend ActiveSupport::Concern
|
|
56
|
+
|
|
57
|
+
included do
|
|
58
|
+
include Attributes::PublicWriters
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
54
62
|
module WithBaseEntity
|
|
55
63
|
extend ActiveSupport::Concern
|
|
56
64
|
|
|
@@ -144,6 +152,15 @@ module ArtirixDataModels
|
|
|
144
152
|
child_class.attribute_config.parent_attribute_config = attribute_config
|
|
145
153
|
end
|
|
146
154
|
|
|
155
|
+
def writer_visibility
|
|
156
|
+
@writer_visibility ||= :private
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def writer_visibility=(visibility)
|
|
160
|
+
raise InvalidArgumentError, "Invalid visibility #{visibility.inspect}" unless [:public, :private, :protected].include? visibility
|
|
161
|
+
@writer_visibility = visibility
|
|
162
|
+
end
|
|
163
|
+
|
|
147
164
|
private
|
|
148
165
|
def _define_attribute(attribute)
|
|
149
166
|
at = attribute.to_sym
|
|
@@ -157,7 +174,14 @@ module ArtirixDataModels
|
|
|
157
174
|
def _define_writer(attribute)
|
|
158
175
|
attr_writer attribute
|
|
159
176
|
writer = "#{attribute}="
|
|
160
|
-
|
|
177
|
+
|
|
178
|
+
if writer_visibility == :private
|
|
179
|
+
private writer
|
|
180
|
+
elsif writer_visibility == :protected
|
|
181
|
+
protected writer
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
writer
|
|
161
185
|
end
|
|
162
186
|
|
|
163
187
|
def _define_presence(attribute)
|
|
@@ -186,6 +210,13 @@ module ArtirixDataModels
|
|
|
186
210
|
end
|
|
187
211
|
end
|
|
188
212
|
|
|
213
|
+
module PublicWriters
|
|
214
|
+
extend ActiveSupport::Concern
|
|
215
|
+
included do
|
|
216
|
+
self.writer_visibility = :public
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
189
220
|
module OnlyData
|
|
190
221
|
# return nil as it is, we do not have DAO for an OnlyData model
|
|
191
222
|
def nil_attribute(_)
|
|
@@ -11,16 +11,63 @@ def given_gateway_config(connection_url = nil)
|
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
def mock_gateway_response(response:, method:, path:, body: nil, json_body: true, gateway: nil)
|
|
15
16
|
gateway ||= ArtirixDataModels::DAORegistry.gateway
|
|
17
|
+
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_return response
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
# check with body already parsed
|
|
20
|
+
unless body.nil?
|
|
21
|
+
body = body.kind_of?(String) ? body : body.to_json
|
|
22
|
+
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_return response
|
|
23
|
+
end
|
|
18
24
|
end
|
|
19
25
|
|
|
20
|
-
def
|
|
26
|
+
def mock_gateway_not_found_response(method:, path:, body: nil, json_body: true, gateway: nil)
|
|
21
27
|
gateway ||= ArtirixDataModels::DAORegistry.gateway
|
|
28
|
+
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_raise ArtirixDataModels::DataGateway::NotFound
|
|
29
|
+
|
|
30
|
+
# check with body already parsed
|
|
31
|
+
unless body.nil?
|
|
32
|
+
body = body.kind_of?(String) ? body : body.to_json
|
|
33
|
+
allow(gateway).to receive(:perform).with(method, path, body, json_body).and_raise ArtirixDataModels::DataGateway::NotFound
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# GET
|
|
38
|
+
def mock_gateway_get_response(**params)
|
|
39
|
+
mock_gateway_response method: :get, **params
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def mock_gateway_get_not_found_response(**params)
|
|
43
|
+
mock_gateway_not_found_response method: :get, **params
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# POST
|
|
47
|
+
def mock_gateway_post_response(**params)
|
|
48
|
+
mock_gateway_response method: :post, **params
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def mock_gateway_post_not_found_response(**params)
|
|
52
|
+
mock_gateway_not_found_response method: :post, **params
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# PUT
|
|
56
|
+
def mock_gateway_put_response(**params)
|
|
57
|
+
mock_gateway_response method: :put, **params
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def mock_gateway_put_not_found_response(**params)
|
|
61
|
+
mock_gateway_not_found_response method: :put, **params
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# DELETE
|
|
65
|
+
def mock_gateway_delete_response(**params)
|
|
66
|
+
mock_gateway_response method: :delete, **params
|
|
67
|
+
end
|
|
22
68
|
|
|
23
|
-
|
|
69
|
+
def mock_gateway_delete_not_found_response(**params)
|
|
70
|
+
mock_gateway_not_found_response method: :delete, **params
|
|
24
71
|
end
|
|
25
72
|
|
|
26
73
|
# :nocov:
|
|
@@ -48,7 +48,7 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
|
48
48
|
Given(:connection_stubs) { Faraday::Adapter::Test::Stubs.new }
|
|
49
49
|
Given(:connection) do
|
|
50
50
|
Faraday.new(url: connection_url, request: { params_encoder: Faraday::FlatParamsEncoder }) do |faraday|
|
|
51
|
-
faraday.request :url_encoded # form-encode
|
|
51
|
+
faraday.request :url_encoded # form-encode without body only path params
|
|
52
52
|
faraday.response :logger # log requests to STDOUT
|
|
53
53
|
faraday.adapter :test, connection_stubs
|
|
54
54
|
end
|
|
@@ -101,6 +101,18 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
|
101
101
|
connection_stubs.post(path_to_fail) { |env| [500, {}, ''] }
|
|
102
102
|
connection_stubs.post(path_to_be_bad_json) { |env| [200, {}, 'oh yeah'] }
|
|
103
103
|
connection_stubs.post(path_to_be_empty) { |env| [200, {}, ''] }
|
|
104
|
+
|
|
105
|
+
# stub put
|
|
106
|
+
connection_stubs.put(path_to_be_not_found) { |env| [404, {}, ''] }
|
|
107
|
+
connection_stubs.put(path_to_fail) { |env| [500, {}, ''] }
|
|
108
|
+
connection_stubs.put(path_to_be_bad_json) { |env| [200, {}, 'oh yeah'] }
|
|
109
|
+
connection_stubs.put(path_to_be_empty) { |env| [200, {}, ''] }
|
|
110
|
+
|
|
111
|
+
# stub put
|
|
112
|
+
connection_stubs.delete(path_to_be_not_found) { |env| [404, {}, ''] }
|
|
113
|
+
connection_stubs.delete(path_to_fail) { |env| [500, {}, ''] }
|
|
114
|
+
connection_stubs.delete(path_to_be_bad_json) { |env| [200, {}, 'oh yeah'] }
|
|
115
|
+
connection_stubs.delete(path_to_be_empty) { |env| [200, {}, ''] }
|
|
104
116
|
end
|
|
105
117
|
|
|
106
118
|
describe '#get' do
|
|
@@ -236,6 +248,132 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
|
236
248
|
end
|
|
237
249
|
end
|
|
238
250
|
end
|
|
251
|
+
|
|
252
|
+
describe '#put' do
|
|
253
|
+
context 'without body' do
|
|
254
|
+
Given do
|
|
255
|
+
connection_stubs.put(path, nil) do |env|
|
|
256
|
+
[200, {}, response_string]
|
|
257
|
+
end
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
context 'when failure (500 error)' do
|
|
261
|
+
When(:result) { gateway.put path_to_fail }
|
|
262
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::GatewayError) }
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
context 'when not found (404 error)' do
|
|
266
|
+
When(:result) { gateway.put path_to_be_not_found }
|
|
267
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::NotFound) }
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
context 'when receiving bad json' do
|
|
271
|
+
When(:result) { gateway.put path_to_be_bad_json }
|
|
272
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::ParseError) }
|
|
273
|
+
end
|
|
274
|
+
|
|
275
|
+
context 'when receiving empty response' do
|
|
276
|
+
When(:result) { gateway.put path_to_be_empty }
|
|
277
|
+
Then { result.nil? }
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
context 'only path given -> return parsed response (JSON -> Hash)' do
|
|
281
|
+
When(:result) { gateway.put path }
|
|
282
|
+
Then { result == response_hash }
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
context 'with adaptor -> call the adaptor with the parsed response (JSON -> Hash -> AdaptedObject)' do
|
|
286
|
+
Given(:model_class) do
|
|
287
|
+
Class.new do
|
|
288
|
+
attr_reader :data
|
|
289
|
+
|
|
290
|
+
def initialize(data)
|
|
291
|
+
@data = { given: data }
|
|
292
|
+
end
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
Given(:adaptor) { ArtirixDataModels::GatewayResponseAdaptors::ModelAdaptor.single model_class }
|
|
297
|
+
|
|
298
|
+
When(:result) { gateway.get path, response_adaptor: adaptor }
|
|
299
|
+
Then { result.class == model_class }
|
|
300
|
+
And { result.data == { given: response_hash } }
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
end
|
|
304
|
+
context 'with body', focus: true do
|
|
305
|
+
Given(:body) { test_hash }
|
|
306
|
+
Given(:body_json) { body.to_json }
|
|
307
|
+
|
|
308
|
+
Given do
|
|
309
|
+
connection_stubs.put(path, body_json, { 'Content-Type' => 'application/json' }) do
|
|
310
|
+
response_body = response_string_with_body.call(body_json)
|
|
311
|
+
[200, {}, response_body]
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
context 'STRING body => use body as is' do
|
|
316
|
+
When(:result) { gateway.put path, body: body_json }
|
|
317
|
+
Then { result == { body: test_hash } }
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
context 'object (or hash) body => use body.to_json' do
|
|
321
|
+
When(:result) { gateway.put path, body: body }
|
|
322
|
+
Then { result == { body: test_hash } }
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
describe '#delete' do
|
|
328
|
+
Given do
|
|
329
|
+
connection_stubs.delete(path) do |env|
|
|
330
|
+
[200, {}, response_string]
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
334
|
+
context 'when failure (500 error)' do
|
|
335
|
+
When(:result) { gateway.delete path_to_fail }
|
|
336
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::GatewayError) }
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
context 'when not found (404 error)' do
|
|
340
|
+
When(:result) { gateway.delete path_to_be_not_found }
|
|
341
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::NotFound) }
|
|
342
|
+
end
|
|
343
|
+
|
|
344
|
+
context 'when receiving bad json' do
|
|
345
|
+
When(:result) { gateway.delete path_to_be_bad_json }
|
|
346
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::ParseError) }
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
context 'when receiving empty response' do
|
|
350
|
+
When(:result) { gateway.delete path_to_be_empty }
|
|
351
|
+
Then { result.nil? }
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
context 'only path given -> return parsed response (JSON -> Hash)' do
|
|
355
|
+
When(:result) { gateway.delete path }
|
|
356
|
+
Then { result == response_hash }
|
|
357
|
+
end
|
|
358
|
+
|
|
359
|
+
context 'with adaptor -> call the adaptor with the parsed response (JSON -> Hash -> AdaptedObject)' do
|
|
360
|
+
Given(:model_class) do
|
|
361
|
+
Class.new do
|
|
362
|
+
attr_reader :data
|
|
363
|
+
|
|
364
|
+
def initialize(data)
|
|
365
|
+
@data = { given: data }
|
|
366
|
+
end
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
Given(:adaptor) { ArtirixDataModels::GatewayResponseAdaptors::ModelAdaptor.single model_class }
|
|
371
|
+
|
|
372
|
+
When(:result) { gateway.delete path, response_adaptor: adaptor }
|
|
373
|
+
Then { result.class == model_class }
|
|
374
|
+
And { result.data == { given: response_hash } }
|
|
375
|
+
end
|
|
376
|
+
end
|
|
239
377
|
end
|
|
240
378
|
end
|
|
241
379
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: artirix_data_models
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eduardo Turiño
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-01-
|
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|