lhs 11.3.0 → 11.3.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/errors/base.rb +7 -6
- data/lib/lhs/version.rb +1 -1
- data/spec/item/errors_spec.rb +22 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5038abb8bd075bd7aba160cdcf81b0e3de7cda4
|
4
|
+
data.tar.gz: 297b1925f5aedc7973493511a1ae318e39064a01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a252ae3732d5dc6e93e5ea5a625d8ec01d2f1e857b0e1f2e22146f1ec6d4a0057d2ef1f8ae0f42b4fce5ca0bf22ceadac3e6656b2c03f3ecbeadcf97383224ae
|
7
|
+
data.tar.gz: cbd5a929459c15e3bc02cd3094228215e63d3f987f851729a174045c0522f21c8e16a82ec55a7568b210bfc29856d0330a5660f1c0ceb4b007c88183c10a2ff2
|
data/lib/lhs/errors/base.rb
CHANGED
@@ -32,23 +32,24 @@ module LHS::Errors
|
|
32
32
|
messages[key]
|
33
33
|
end
|
34
34
|
|
35
|
-
def set(key,
|
36
|
-
|
35
|
+
def set(key, message)
|
36
|
+
return if message.blank?
|
37
|
+
messages[key] = [generate_message(key, message)]
|
37
38
|
end
|
38
39
|
|
39
40
|
delegate :delete, to: :messages
|
40
41
|
|
41
42
|
def [](attribute)
|
42
|
-
get(attribute.to_sym) ||
|
43
|
+
get(attribute.to_sym) || messages[attribute] = []
|
43
44
|
end
|
44
45
|
|
45
|
-
def []=(attribute,
|
46
|
-
self[attribute] << generate_message(attribute,
|
46
|
+
def []=(attribute, message)
|
47
|
+
self[attribute] << generate_message(attribute, message)
|
47
48
|
end
|
48
49
|
|
49
50
|
def each
|
50
51
|
messages.each_key do |attribute|
|
51
|
-
self[attribute].each { |
|
52
|
+
self[attribute].each { |message| yield attribute, message }
|
52
53
|
end
|
53
54
|
end
|
54
55
|
|
data/lib/lhs/version.rb
CHANGED
data/spec/item/errors_spec.rb
CHANGED
@@ -197,7 +197,7 @@ describe LHS::Item do
|
|
197
197
|
|
198
198
|
let(:record) do
|
199
199
|
Record.build(
|
200
|
-
reviews: [{ name: 123 }],
|
200
|
+
reviews: [{ name: 123, suggested: false }],
|
201
201
|
address: {
|
202
202
|
additional_line1: '',
|
203
203
|
street: {
|
@@ -241,5 +241,26 @@ describe LHS::Item do
|
|
241
241
|
record.save
|
242
242
|
expect(record.errors.status_code).to eq 400
|
243
243
|
end
|
244
|
+
|
245
|
+
context 'with general error fallback message configured' do
|
246
|
+
before(:each) do
|
247
|
+
I18n.reload!
|
248
|
+
I18n.backend.store_translations(:en, YAML.safe_load(translation)) if translation.present?
|
249
|
+
end
|
250
|
+
|
251
|
+
let(:translation) do
|
252
|
+
%q{
|
253
|
+
lhs:
|
254
|
+
errors:
|
255
|
+
fallback_message: 'This value is wrong'
|
256
|
+
}
|
257
|
+
end
|
258
|
+
|
259
|
+
it 'is capable to access errors/attributes that dont have any validation errors' do
|
260
|
+
record.save
|
261
|
+
expect(record.reviews.first.errors[:suggested]).to be_kind_of Array
|
262
|
+
expect(record.reviews.first.errors[:suggested]).to be_empty
|
263
|
+
end
|
264
|
+
end
|
244
265
|
end
|
245
266
|
end
|