artirix_data_models 1.0.0.beta3 → 1.0.0.beta4
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 +3 -0
- data/lib/artirix_data_models/dao.rb +1 -0
- data/lib/artirix_data_models/daos/basic_model_dao.rb +25 -0
- data/lib/artirix_data_models/gateways/data_gateway.rb +8 -0
- data/lib/artirix_data_models/spec_support/gateway_mock.rb +9 -0
- data/lib/artirix_data_models/version.rb +1 -1
- data/spec/artirix_data_models/gateways/data_gateway_spec.rb +82 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6102f754068a06912168285f6750c2cddd81006b
|
4
|
+
data.tar.gz: 2e2ead184a6b5a205a2091f90fd7d985e5561f3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a1ee757493b0c96fffdc5aba04f084686a04927be943cf7803872d905f5593e5c439eaefbf9f39a49f0cce62b0641d51f352ffa26c1a4dfa9c08310f26ac522a
|
7
|
+
data.tar.gz: 84059d8547429369921935dffb516ddad851a8f71b709ab1818c50ffcc52c341d4fa095b5c081ba2e092a79ca6da24104fd42696d66968162b43362192783ba6
|
data/README.md
CHANGED
@@ -388,6 +388,9 @@ config.x.artirix_data_models.attributes_always_in_partial_mode = [:_timestamp, :
|
|
388
388
|
]
|
389
389
|
```
|
390
390
|
|
391
|
+
### 1.0.0.beta4
|
392
|
+
- add `patch` besides `put`.
|
393
|
+
|
391
394
|
### Breaking Changes!!: version 1.0.0.beta1
|
392
395
|
|
393
396
|
- rename `DAORegistry` to `ADMRegistry`, and `dao_registry` to `adm_registry`. Passed the rename to all places (`adm_registry_loader`, etc.)
|
@@ -245,6 +245,30 @@ class ArtirixDataModels::BasicModelDAO
|
|
245
245
|
headers: headers
|
246
246
|
end
|
247
247
|
|
248
|
+
def perform_patch(path,
|
249
|
+
fake: nil,
|
250
|
+
response_adaptor: nil,
|
251
|
+
body: nil,
|
252
|
+
fake_response: nil,
|
253
|
+
cache_adaptor: nil,
|
254
|
+
timeout: nil,
|
255
|
+
gateway: nil,
|
256
|
+
headers: nil)
|
257
|
+
|
258
|
+
fake = fake.nil? ? fake? : fake
|
259
|
+
g = gateway.presence || preloaded_gateway
|
260
|
+
raise_no_gateway unless g.present?
|
261
|
+
|
262
|
+
g.patch path,
|
263
|
+
response_adaptor: response_adaptor,
|
264
|
+
body: body,
|
265
|
+
timeout: timeout,
|
266
|
+
fake: fake,
|
267
|
+
fake_response: fake_response,
|
268
|
+
cache_adaptor: cache_adaptor,
|
269
|
+
headers: headers
|
270
|
+
end
|
271
|
+
|
248
272
|
def perform_delete(path,
|
249
273
|
fake: nil,
|
250
274
|
response_adaptor: nil,
|
@@ -273,6 +297,7 @@ class ArtirixDataModels::BasicModelDAO
|
|
273
297
|
alias_method :_get, :perform_get
|
274
298
|
alias_method :_post, :perform_post
|
275
299
|
alias_method :_put, :perform_put
|
300
|
+
alias_method :_patch, :perform_patch
|
276
301
|
alias_method :_delete, :perform_delete
|
277
302
|
|
278
303
|
end
|
@@ -31,6 +31,10 @@ class ArtirixDataModels::DataGateway
|
|
31
31
|
call :put, path, **opts
|
32
32
|
end
|
33
33
|
|
34
|
+
def patch(path, **opts)
|
35
|
+
call :patch, path, **opts
|
36
|
+
end
|
37
|
+
|
34
38
|
def delete(path, **opts)
|
35
39
|
call :delete, path, **opts
|
36
40
|
end
|
@@ -103,6 +107,10 @@ class ArtirixDataModels::DataGateway
|
|
103
107
|
perform :put, path: path, **opts
|
104
108
|
end
|
105
109
|
|
110
|
+
def perform_patch(path, **opts)
|
111
|
+
perform :patch, path: path, **opts
|
112
|
+
end
|
113
|
+
|
106
114
|
def perform_delete(path, **opts)
|
107
115
|
perform :delete, path: path, **opts
|
108
116
|
end
|
@@ -118,6 +118,15 @@ def mock_gateway_put_not_found_response(**params)
|
|
118
118
|
mock_gateway_not_found_response method: :put, **params
|
119
119
|
end
|
120
120
|
|
121
|
+
# PATCH
|
122
|
+
def mock_gateway_patch_response(**params)
|
123
|
+
mock_gateway_response method: :patch, **params
|
124
|
+
end
|
125
|
+
|
126
|
+
def mock_gateway_patch_not_found_response(**params)
|
127
|
+
mock_gateway_not_found_response method: :patch, **params
|
128
|
+
end
|
129
|
+
|
121
130
|
# DELETE
|
122
131
|
def mock_gateway_delete_response(**params)
|
123
132
|
mock_gateway_response method: :delete, **params
|
@@ -363,7 +363,13 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
363
363
|
connection_stubs.put(path_to_be_bad_json) { |env| [200, {}, 'oh yeah'] }
|
364
364
|
connection_stubs.put(path_to_be_empty) { |env| [200, {}, ''] }
|
365
365
|
|
366
|
-
# stub
|
366
|
+
# stub patch
|
367
|
+
connection_stubs.patch(path_to_be_not_found) { |env| [404, {}, ''] }
|
368
|
+
connection_stubs.patch(path_to_fail) { |env| [500, {}, ''] }
|
369
|
+
connection_stubs.patch(path_to_be_bad_json) { |env| [200, {}, 'oh yeah'] }
|
370
|
+
connection_stubs.patch(path_to_be_empty) { |env| [200, {}, ''] }
|
371
|
+
|
372
|
+
# stub delete
|
367
373
|
connection_stubs.delete(path_to_be_not_found) { |env| [404, {}, ''] }
|
368
374
|
connection_stubs.delete(path_to_fail) { |env| [500, {}, ''] }
|
369
375
|
connection_stubs.delete(path_to_be_bad_json) { |env| [200, {}, 'oh yeah'] }
|
@@ -579,6 +585,81 @@ RSpec.describe ArtirixDataModels::DataGateway, type: :model do
|
|
579
585
|
end
|
580
586
|
end
|
581
587
|
|
588
|
+
describe '#patch' do
|
589
|
+
context 'without body' do
|
590
|
+
Given do
|
591
|
+
connection_stubs.patch(path, nil) do |env|
|
592
|
+
[200, {}, response_string]
|
593
|
+
end
|
594
|
+
end
|
595
|
+
|
596
|
+
context 'when failure (500 error)' do
|
597
|
+
When(:result) { gateway.patch path_to_fail }
|
598
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::GatewayError) }
|
599
|
+
end
|
600
|
+
|
601
|
+
context 'when not found (404 error)' do
|
602
|
+
When(:result) { gateway.patch path_to_be_not_found }
|
603
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::NotFound) }
|
604
|
+
end
|
605
|
+
|
606
|
+
context 'when receiving bad json' do
|
607
|
+
When(:result) { gateway.patch path_to_be_bad_json }
|
608
|
+
Then { result == Failure(ArtirixDataModels::DataGateway::ParseError) }
|
609
|
+
end
|
610
|
+
|
611
|
+
context 'when receiving empty response' do
|
612
|
+
When(:result) { gateway.patch path_to_be_empty }
|
613
|
+
Then { result.nil? }
|
614
|
+
end
|
615
|
+
|
616
|
+
context 'only path given -> return parsed response (JSON -> Hash)' do
|
617
|
+
When(:result) { gateway.patch path }
|
618
|
+
Then { result == response_hash }
|
619
|
+
end
|
620
|
+
|
621
|
+
context 'with adaptor -> call the adaptor with the parsed response (JSON -> Hash -> AdaptedObject)' do
|
622
|
+
Given(:model_class) do
|
623
|
+
Class.new do
|
624
|
+
attr_reader :data
|
625
|
+
|
626
|
+
def initialize(data)
|
627
|
+
@data = { given: data }
|
628
|
+
end
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
Given(:adaptor) { ArtirixDataModels::GatewayResponseAdaptors::ModelAdaptor.single model_class }
|
633
|
+
|
634
|
+
When(:result) { gateway.get path, response_adaptor: adaptor }
|
635
|
+
Then { result.class == model_class }
|
636
|
+
And { result.data == { given: response_hash } }
|
637
|
+
end
|
638
|
+
|
639
|
+
end
|
640
|
+
context 'with body', focus: true do
|
641
|
+
Given(:body) { test_hash }
|
642
|
+
Given(:body_json) { body.to_json }
|
643
|
+
|
644
|
+
Given do
|
645
|
+
connection_stubs.patch(path, body_json, { 'Content-Type' => 'application/json' }) do
|
646
|
+
response_body = response_string_with_body.call(body_json)
|
647
|
+
[200, {}, response_body]
|
648
|
+
end
|
649
|
+
end
|
650
|
+
|
651
|
+
context 'STRING body => use body as is' do
|
652
|
+
When(:result) { gateway.patch path, body: body_json }
|
653
|
+
Then { result == { body: test_hash } }
|
654
|
+
end
|
655
|
+
|
656
|
+
context 'object (or hash) body => use body.to_json' do
|
657
|
+
When(:result) { gateway.patch path, body: body }
|
658
|
+
Then { result == { body: test_hash } }
|
659
|
+
end
|
660
|
+
end
|
661
|
+
end
|
662
|
+
|
582
663
|
describe '#delete' do
|
583
664
|
Given do
|
584
665
|
connection_stubs.delete(path) do |env|
|
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: 1.0.0.
|
4
|
+
version: 1.0.0.beta4
|
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: 2017-
|
11
|
+
date: 2017-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -312,7 +312,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
312
312
|
version: 1.3.1
|
313
313
|
requirements: []
|
314
314
|
rubyforge_project:
|
315
|
-
rubygems_version: 2.
|
315
|
+
rubygems_version: 2.6.13
|
316
316
|
signing_key:
|
317
317
|
specification_version: 4
|
318
318
|
summary: Data Models (read only model) and Data Layer connection lib
|