lhs 16.1.3 → 16.1.4
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/data/becomes.rb +5 -2
- data/lib/lhs/concerns/proxy/accessors.rb +4 -2
- data/lib/lhs/version.rb +1 -1
- data/spec/item/errors_spec.rb +46 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4d0c9693012ec5fe38601976c89443114654f6a59de9a875c5a713ae2e01b0c
|
4
|
+
data.tar.gz: c23ed566bdfc10840fc0dfd7e0be0b8475a558669424f44e081da7ed3c38fbc6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d67775a51aac4da7cd8024932b7f03b521277f6128bab375673ff464bbd300a294d06c9fc6ef8b6f599f519f2aab92552aefa4bf58497ef22462df3778800d09
|
7
|
+
data.tar.gz: b4f7cc36403f8fcfbdb93864f231a40949b74946e1a26a0632fba8d1ccce3a25265093d81ea2ba02840b5ac87d9f15e12376921232ddd2c44d9b33bc28744d8a
|
@@ -5,9 +5,12 @@ class LHS::Data
|
|
5
5
|
module Becomes
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
-
def becomes(klass)
|
8
|
+
def becomes(klass, options = {})
|
9
9
|
return self if self.class == klass && !is_a?(LHS::Data)
|
10
|
-
|
10
|
+
data = LHS::Data.new(_raw, _parent, klass)
|
11
|
+
data.errors = options[:errors] if options[:errors]
|
12
|
+
data.warnings = options[:warnings] if options[:warnings]
|
13
|
+
klass.new(data)
|
11
14
|
end
|
12
15
|
end
|
13
16
|
end
|
@@ -79,9 +79,11 @@ class LHS::Proxy
|
|
79
79
|
data.warnings = LHS::Problems::Nested::Warnings.new(warnings, name) if warnings.any?
|
80
80
|
if _record && _record._relations[name]
|
81
81
|
klass = _record._relations[name][:record_class_name].constantize
|
82
|
-
return cache.compute_if_absent(klass)
|
82
|
+
return cache.compute_if_absent(klass) do
|
83
|
+
data.becomes(klass, errors: data.errors, warnings: data.warnings)
|
84
|
+
end
|
83
85
|
elsif record && !value.is_a?(LHS::Record)
|
84
|
-
return data.becomes(record)
|
86
|
+
return data.becomes(record, errors: data.errors, warnings: data.warnings)
|
85
87
|
end
|
86
88
|
data
|
87
89
|
end
|
data/lib/lhs/version.rb
CHANGED
data/spec/item/errors_spec.rb
CHANGED
@@ -273,4 +273,50 @@ describe LHS::Item do
|
|
273
273
|
end
|
274
274
|
end
|
275
275
|
end
|
276
|
+
|
277
|
+
context 'forwards errors to nested data when associations are defined' do
|
278
|
+
before do
|
279
|
+
class AppointmentProposal < LHS::Record
|
280
|
+
endpoint 'http://dataste/appointment_proposals'
|
281
|
+
endpoint 'http://dataste/appointment_proposals/{id}'
|
282
|
+
|
283
|
+
has_many :appointments
|
284
|
+
end
|
285
|
+
|
286
|
+
class Appointment < LHS::Record
|
287
|
+
end
|
288
|
+
|
289
|
+
stub_request(:get, 'http://dataste/appointment_proposals/1')
|
290
|
+
.to_return(body: {
|
291
|
+
appointments: [
|
292
|
+
{ 'date_time' => '13.12.2018' },
|
293
|
+
{ 'date_time' => '18.10.2028' }
|
294
|
+
]
|
295
|
+
}.to_json)
|
296
|
+
|
297
|
+
stub_request(:post, 'http://dataste/appointment_proposals')
|
298
|
+
.to_return(
|
299
|
+
status: 400,
|
300
|
+
body: {
|
301
|
+
field_errors: [{
|
302
|
+
'code' => 'DATE_PROPERTY_NOT_IN_FUTURE',
|
303
|
+
'path' => ['appointments', 0, 'date_time']
|
304
|
+
}]
|
305
|
+
}.to_json
|
306
|
+
)
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'translates errors automatically when they are around' do
|
310
|
+
appointment_proposal = AppointmentProposal.find(1)
|
311
|
+
appointment_proposal.update(
|
312
|
+
'appointments_attributes' => {
|
313
|
+
'0' => { 'date_time' => '13.12.2018' },
|
314
|
+
'1' => { 'date_time' => '18.10.2028' }
|
315
|
+
}
|
316
|
+
)
|
317
|
+
appointment_proposal.appointments
|
318
|
+
appointment = appointment_proposal.appointments[0]
|
319
|
+
expect(appointment.errors[:date_time]).to eq ['DATE_PROPERTY_NOT_IN_FUTURE']
|
320
|
+
end
|
321
|
+
end
|
276
322
|
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: 16.1.
|
4
|
+
version: 16.1.4
|
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: 2019-01-
|
11
|
+
date: 2019-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|