activerecord_json_validator 2.1.3 → 2.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 851b94edf54cbfdcd0a66a80dab95bcdeeea0e1c4a8831f634bc55aad5cba226
|
4
|
+
data.tar.gz: bf3a8280ffa8300469e793422adc68e83ab444047db67d9e6cbafec528f69803
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33766dfbea4cf464c499709f76b742f3bfe9b37dcc656206a15794f93733ec6711f127057ff2efb67bb75b6e439e64e75ada856d62fcdb2fece42e4ddd81b6ff
|
7
|
+
data.tar.gz: 7192194e8663dfbd9d343b66866ebab63d843200581bbe59be2c3f3bd485819fb13bba58bfb29241afa661c180399acce0d6fa3cf24a9d6fd5852b1d300a1be8
|
data/README.md
CHANGED
@@ -25,9 +25,10 @@ class JsonValidator < ActiveModel::EachValidator
|
|
25
25
|
return if errors.empty? && record.send(:"#{attribute}_invalid_json").blank?
|
26
26
|
|
27
27
|
# Add error message to the attribute
|
28
|
+
details = errors.map { |e| JSONSchemer::Errors.pretty(e) }
|
28
29
|
message(errors).each do |error|
|
29
|
-
error =
|
30
|
-
record.errors.add(attribute, error, value: value)
|
30
|
+
error = JSONSchemer::Errors.pretty(error) if error.is_a?(Hash)
|
31
|
+
record.errors.add(attribute, error, errors: details, value: value)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -68,10 +69,7 @@ protected
|
|
68
69
|
|
69
70
|
def message(errors)
|
70
71
|
message = options.fetch(:message)
|
71
|
-
|
72
|
-
|
73
|
-
when Proc then [message.call(errors)].flatten if message.is_a?(Proc)
|
74
|
-
else [message]
|
75
|
-
end
|
72
|
+
message = message.call(errors) if message.is_a?(Proc)
|
73
|
+
[message].flatten
|
76
74
|
end
|
77
75
|
end
|
data/spec/json_validator_spec.rb
CHANGED
@@ -48,6 +48,12 @@ describe JsonValidator do
|
|
48
48
|
specify do
|
49
49
|
expect(user).not_to be_valid
|
50
50
|
expect(user.errors.full_messages).to eql(['Data root is missing required keys: country', 'Other data missing_keys country'])
|
51
|
+
expect(user.errors.group_by_attribute[:data].first).to have_attributes(
|
52
|
+
options: include(errors: ['root is missing required keys: country'])
|
53
|
+
)
|
54
|
+
expect(user.errors.group_by_attribute[:other_data].first).to have_attributes(
|
55
|
+
options: include(errors: ['root is missing required keys: country'])
|
56
|
+
)
|
51
57
|
expect(user.data).to eql({ 'city' => 'Quebec City' })
|
52
58
|
expect(user.data_invalid_json).to be_nil
|
53
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord_json_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rémi Prévost
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|