lhs 14.3.4 → 14.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +4 -2
- data/lib/lhs/problems/base.rb +4 -1
- data/lib/lhs/problems/errors.rb +2 -0
- data/lib/lhs/problems/warnings.rb +1 -0
- data/lib/lhs/version.rb +1 -1
- data/spec/item/error_codes_spec.rb +53 -0
- data/spec/item/errors_spec.rb +2 -0
- data/spec/item/warning_codes_spec.rb +53 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 915b54df82b092a12fef1395a21e854e4f95738d
|
4
|
+
data.tar.gz: ff5e0fbca423676b763606ebcdf2d2b2a4562084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fbbe1749a1266a6b4fc2df4d4aaf9b55b4d24a69d3af3af000c6c9d4b159eea16d7435e93799fcbfc28f0db46f4e86a84283938578edb62b05b4bdf47f1ca2f
|
7
|
+
data.tar.gz: 4f2652ef35ec40aa670901203fcbbf02de58fffe900090f90af7acb9fcdc032b40dbe86a350a2cc8c83efb7e25cb7bbb21aa34e74a7586956c6d313c88e2df80
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -775,7 +775,8 @@ end
|
|
775
775
|
user.errors #<LHS::Problems::Errors>
|
776
776
|
user.errors.include?(:email) # true
|
777
777
|
user.errors[:email] # ['REQUIRED_PROPERTY_VALUE']
|
778
|
-
user.errors.messages # {:email=>["
|
778
|
+
user.errors.messages # {:email=>["Translated error message that this value is required"]}
|
779
|
+
user.errors.codes # {:email=>["REQUIRED_PROPERTY_VALUE"]}
|
779
780
|
user.errors.message # email must be set when user is created."
|
780
781
|
```
|
781
782
|
|
@@ -885,7 +886,8 @@ LHS makes those errors available when accessing `.errors`:
|
|
885
886
|
)
|
886
887
|
|
887
888
|
presence.errors.any? # true
|
888
|
-
presence.place.errors.messages[:opening_hours] # ['
|
889
|
+
presence.place.errors.messages[:opening_hours] # ['This field needs to be present']
|
890
|
+
presence.place.errors.codes[:opening_hours] # ['REQUIRED_PROPERTY_VALUE']
|
889
891
|
```
|
890
892
|
|
891
893
|
### Non blocking validation errors, so called warnings
|
data/lib/lhs/problems/base.rb
CHANGED
@@ -6,7 +6,7 @@ module LHS::Problems
|
|
6
6
|
class Base
|
7
7
|
include Enumerable
|
8
8
|
|
9
|
-
attr_reader :raw, :messages, :record
|
9
|
+
attr_reader :raw, :messages, :codes, :record
|
10
10
|
|
11
11
|
def include?(attribute)
|
12
12
|
messages[attribute].present?
|
@@ -55,6 +55,7 @@ module LHS::Problems
|
|
55
55
|
def clear
|
56
56
|
@raw = nil
|
57
57
|
@messages.clear
|
58
|
+
@codes.clear
|
58
59
|
end
|
59
60
|
|
60
61
|
delegate :values, to: :messages
|
@@ -73,6 +74,8 @@ module LHS::Problems
|
|
73
74
|
|
74
75
|
def add_error(messages, key, value)
|
75
76
|
key = key.to_sym
|
77
|
+
codes[key] ||= []
|
78
|
+
codes[key].push(value)
|
76
79
|
messages[key] ||= []
|
77
80
|
messages[key].push(generate_message(key, value))
|
78
81
|
end
|
data/lib/lhs/problems/errors.rb
CHANGED
@@ -6,11 +6,13 @@ module LHS::Problems
|
|
6
6
|
def initialize(response = nil, record = nil)
|
7
7
|
@raw = response.body if response
|
8
8
|
@record = record
|
9
|
+
@codes = {}.with_indifferent_access
|
9
10
|
@messages = messages_from_response(response).with_indifferent_access
|
10
11
|
@message = message_from_response(response)
|
11
12
|
@status_code = response.code if response
|
12
13
|
rescue JSON::ParserError
|
13
14
|
@messages = (messages || {}).with_indifferent_access
|
15
|
+
@codes = (codes || {}).with_indifferent_access
|
14
16
|
@message = 'parse error'
|
15
17
|
add_error(@messages, 'body', 'parse error')
|
16
18
|
end
|
data/lib/lhs/version.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Item do
|
4
|
+
context 'error codes' do
|
5
|
+
before(:each) do
|
6
|
+
I18n.reload!
|
7
|
+
I18n.backend.store_translations(:en, YAML.safe_load(translation)) if translation.present?
|
8
|
+
class Record < LHS::Record
|
9
|
+
endpoint 'http://datastore/records'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:translation) do
|
14
|
+
%q{
|
15
|
+
lhs:
|
16
|
+
errors:
|
17
|
+
fallback_message: 'This value is wrong'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'provides error codes along side with translated messages' do
|
22
|
+
stub_request(:post, 'http://datastore/records')
|
23
|
+
.to_return(body: {
|
24
|
+
field_errors: [{
|
25
|
+
code: 'UNSUPPORTED_PROPERTY_VALUE',
|
26
|
+
path: ['gender'],
|
27
|
+
message: 'The property value is unsupported.'
|
28
|
+
}, {
|
29
|
+
code: 'INCOMPLETE_PROPERTY_VALUE',
|
30
|
+
path: ['gender'],
|
31
|
+
message: 'The property value is incomplete. It misses some data'
|
32
|
+
}, {
|
33
|
+
code: 'INCOMPLETE_PROPERTY_VALUE',
|
34
|
+
path: ['contract', 'entry_id'],
|
35
|
+
message: 'The property value is incomplete. It misses some data'
|
36
|
+
}]
|
37
|
+
}.to_json)
|
38
|
+
record = Record.create
|
39
|
+
expect(record.errors.messages['gender']).to eq(
|
40
|
+
['This value is wrong', 'This value is wrong']
|
41
|
+
)
|
42
|
+
expect(record.errors.codes['gender']).to eq(
|
43
|
+
['UNSUPPORTED_PROPERTY_VALUE', 'INCOMPLETE_PROPERTY_VALUE']
|
44
|
+
)
|
45
|
+
expect(record.errors.messages['contract.entry_id']).to eq(
|
46
|
+
['This value is wrong']
|
47
|
+
)
|
48
|
+
expect(record.errors.codes['contract.entry_id']).to eq(
|
49
|
+
['INCOMPLETE_PROPERTY_VALUE']
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/spec/item/errors_spec.rb
CHANGED
@@ -51,6 +51,8 @@ describe LHS::Item do
|
|
51
51
|
end
|
52
52
|
|
53
53
|
before(:each) do
|
54
|
+
I18n.reload!
|
55
|
+
I18n.backend.store_translations(:en, {}) if defined? translations
|
54
56
|
LHC.config.placeholder(:datastore, datastore)
|
55
57
|
class Record < LHS::Record
|
56
58
|
endpoint ':datastore/:campaign_id/feedbacks'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe LHS::Item do
|
4
|
+
context 'error codes' do
|
5
|
+
before(:each) do
|
6
|
+
I18n.reload!
|
7
|
+
I18n.backend.store_translations(:en, YAML.safe_load(translation)) if translation.present?
|
8
|
+
class Record < LHS::Record
|
9
|
+
endpoint 'http://datastore/records'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:translation) do
|
14
|
+
%q{
|
15
|
+
lhs:
|
16
|
+
warnings:
|
17
|
+
fallback_message: 'This value is problematic'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'provides error codes along side with translated messages' do
|
22
|
+
stub_request(:post, 'http://datastore/records')
|
23
|
+
.to_return(body: {
|
24
|
+
field_warnings: [{
|
25
|
+
code: 'UNSUPPORTED_PROPERTY_VALUE',
|
26
|
+
path: ['gender'],
|
27
|
+
message: 'The property value is unsupported.'
|
28
|
+
}, {
|
29
|
+
code: 'INCOMPLETE_PROPERTY_VALUE',
|
30
|
+
path: ['gender'],
|
31
|
+
message: 'The property value is incomplete. It misses some data'
|
32
|
+
}, {
|
33
|
+
code: 'INCOMPLETE_PROPERTY_VALUE',
|
34
|
+
path: ['contract', 'entry_id'],
|
35
|
+
message: 'The property value is incomplete. It misses some data'
|
36
|
+
}]
|
37
|
+
}.to_json)
|
38
|
+
record = Record.create
|
39
|
+
expect(record.warnings.messages['gender']).to eq(
|
40
|
+
['This value is problematic', 'This value is problematic']
|
41
|
+
)
|
42
|
+
expect(record.warnings.codes['gender']).to eq(
|
43
|
+
['UNSUPPORTED_PROPERTY_VALUE', 'INCOMPLETE_PROPERTY_VALUE']
|
44
|
+
)
|
45
|
+
expect(record.warnings.messages['contract.entry_id']).to eq(
|
46
|
+
['This value is problematic']
|
47
|
+
)
|
48
|
+
expect(record.warnings.codes['contract.entry_id']).to eq(
|
49
|
+
['INCOMPLETE_PROPERTY_VALUE']
|
50
|
+
)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
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: 14.
|
4
|
+
version: 14.4.0
|
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: 2017-10-
|
11
|
+
date: 2017-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|
@@ -328,6 +328,7 @@ files:
|
|
328
328
|
- spec/item/delegate_spec.rb
|
329
329
|
- spec/item/destroy_spec.rb
|
330
330
|
- spec/item/dig_spec.rb
|
331
|
+
- spec/item/error_codes_spec.rb
|
331
332
|
- spec/item/errors_spec.rb
|
332
333
|
- spec/item/getter_spec.rb
|
333
334
|
- spec/item/internal_data_structure_spec.rb
|
@@ -340,6 +341,7 @@ files:
|
|
340
341
|
- spec/item/translate_errors_spec.rb
|
341
342
|
- spec/item/update_spec.rb
|
342
343
|
- spec/item/validation_spec.rb
|
344
|
+
- spec/item/warning_codes_spec.rb
|
343
345
|
- spec/item/warnings_spec.rb
|
344
346
|
- spec/pagination/pages_left_spec.rb
|
345
347
|
- spec/proxy/create_sub_resource_spec.rb
|
@@ -508,6 +510,7 @@ test_files:
|
|
508
510
|
- spec/item/delegate_spec.rb
|
509
511
|
- spec/item/destroy_spec.rb
|
510
512
|
- spec/item/dig_spec.rb
|
513
|
+
- spec/item/error_codes_spec.rb
|
511
514
|
- spec/item/errors_spec.rb
|
512
515
|
- spec/item/getter_spec.rb
|
513
516
|
- spec/item/internal_data_structure_spec.rb
|
@@ -520,6 +523,7 @@ test_files:
|
|
520
523
|
- spec/item/translate_errors_spec.rb
|
521
524
|
- spec/item/update_spec.rb
|
522
525
|
- spec/item/validation_spec.rb
|
526
|
+
- spec/item/warning_codes_spec.rb
|
523
527
|
- spec/item/warnings_spec.rb
|
524
528
|
- spec/pagination/pages_left_spec.rb
|
525
529
|
- spec/proxy/create_sub_resource_spec.rb
|