activerecord_json_validator 2.1.5 → 3.0.0
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/LICENSE.md +1 -1
- data/README.md +2 -2
- data/activerecord_json_validator.gemspec +1 -1
- data/lib/active_record/json_validator/validator.rb +2 -2
- data/lib/active_record/json_validator/version.rb +1 -1
- data/spec/json_validator_spec.rb +5 -5
- data/spec/support/macros/database_macros.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 669da2ce3ee468c5d588289edf6842fbec2e90a04058b110db4fc81fe10cb0e7
|
4
|
+
data.tar.gz: 76b04ff20e88c285ffd5711dc1ce6bee16c7e9bdf519a3ef95dac637d7a4b147
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40ccc0aa96e3601e49a6cb38fa35b83158f5b9a4597916577416b316f144534d271c56b17b42b5fe7071cdffd8f87c2b1ac3d84bfaa0da5794372eff6c5b9d89
|
7
|
+
data.tar.gz: 8a79553fc7bb7ab146ab77ed0ac57e186b7f9fd0f6cb6f47dd5e7bd94b920796abafd8d3d09e99a3954cf520f4aab6bb208341cd06aa29bb68ba0175763e949d
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
Add this line to your application's Gemfile:
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'activerecord_json_validator', '~>
|
19
|
+
gem 'activerecord_json_validator', '~> 3.0.0'
|
20
20
|
```
|
21
21
|
|
22
22
|
## Usage
|
@@ -175,7 +175,7 @@ appropriately.
|
|
175
175
|
|
176
176
|
## License
|
177
177
|
|
178
|
-
`ActiveRecord::JSONValidator` is © 2013-
|
178
|
+
`ActiveRecord::JSONValidator` is © 2013-2024 [Mirego](https://www.mirego.com) and may be freely distributed under the [New BSD license](https://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/activerecord_json_validator/blob/master/LICENSE.md) file.
|
179
179
|
|
180
180
|
The tree logo is based on [this lovely icon](https://thenounproject.com/term/tree/51004/) by [Sara Quintana](https://thenounproject.com/sara.quintana.75), from The Noun Project. Used under a [Creative Commons BY 3.0](https://creativecommons.org/licenses/by/3.0/) license.
|
181
181
|
|
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'rubocop-rspec', '~> 1.44'
|
28
28
|
spec.add_development_dependency 'rubocop-standard', '~> 6.0'
|
29
29
|
|
30
|
-
spec.add_dependency 'json_schemer', '~>
|
30
|
+
spec.add_dependency 'json_schemer', '~> 2.2'
|
31
31
|
spec.add_dependency 'activerecord', '>= 4.2.0', '< 8'
|
32
32
|
end
|
@@ -25,9 +25,9 @@ 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|
|
28
|
+
details = errors.map { |e| e.fetch('error') }
|
29
29
|
message(errors).each do |error|
|
30
|
-
error =
|
30
|
+
error = error.fetch('error') if error.is_a?(Hash)
|
31
31
|
record.errors.add(attribute, error, errors: details, value: value)
|
32
32
|
end
|
33
33
|
end
|
data/spec/json_validator_spec.rb
CHANGED
@@ -41,8 +41,8 @@ describe JsonValidator do
|
|
41
41
|
|
42
42
|
default_country_attribute :smart_data, country: 'Canada'
|
43
43
|
|
44
|
-
serialize :data, JSON
|
45
|
-
serialize :other_data, JSON
|
44
|
+
serialize :data, coder: JSON
|
45
|
+
serialize :other_data, coder: JSON
|
46
46
|
validates :data, json: { schema: schema, message: ->(errors) { errors } }
|
47
47
|
validates :other_data, json: { schema: schema, message: ->(errors) { errors.map { |error| error['details'].to_a.flatten.join(' ') } } }
|
48
48
|
validates :smart_data, json: { value: ->(record, _, _) { record[:smart_data] }, schema: schema, message: ->(errors) { errors } }
|
@@ -64,12 +64,12 @@ describe JsonValidator do
|
|
64
64
|
|
65
65
|
specify do
|
66
66
|
expect(user).not_to be_valid
|
67
|
-
expect(user.errors.full_messages).to eql(['Data root is missing required
|
67
|
+
expect(user.errors.full_messages).to eql(['Data object at root is missing required properties: country', 'Other data missing_keys country'])
|
68
68
|
expect(user.errors.group_by_attribute[:data].first).to have_attributes(
|
69
|
-
options: include(errors: ['root is missing required
|
69
|
+
options: include(errors: ['object at root is missing required properties: country'])
|
70
70
|
)
|
71
71
|
expect(user.errors.group_by_attribute[:other_data].first).to have_attributes(
|
72
|
-
options: include(errors: ['root is missing required
|
72
|
+
options: include(errors: ['object at root is missing required properties: country'])
|
73
73
|
)
|
74
74
|
expect(user.data).to eql({ 'city' => 'Quebec City' })
|
75
75
|
expect(user.data_invalid_json).to be_nil
|
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:
|
4
|
+
version: 3.0.0
|
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: 2024-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,14 +134,14 @@ dependencies:
|
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
137
|
+
version: '2.2'
|
138
138
|
type: :runtime
|
139
139
|
prerelease: false
|
140
140
|
version_requirements: !ruby/object:Gem::Requirement
|
141
141
|
requirements:
|
142
142
|
- - "~>"
|
143
143
|
- !ruby/object:Gem::Version
|
144
|
-
version:
|
144
|
+
version: '2.2'
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: activerecord
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|