activerecord_json_validator 2.1.5 → 3.1.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 +3 -3
- 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 +12 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 90252b743670b3c94e3ac700b868c698cf9b94124f115fa7b39b27b63f66445a
|
|
4
|
+
data.tar.gz: 8de9a2eeb74864be691a63ecb9a27f286d669949221b78f70db62ecbb3f9b62c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: abdacc70526c1c9be8b5d3585283eaa594fe0c48116aab7eac9ca19a5553fcae69a409986e3793eb96c9ab80624d74f8556c69c0f3994a88987a5d83f9a84266
|
|
7
|
+
data.tar.gz: a170d66db92dcc1bc0e3eb9ebe75fb939ccecb85d952cc18b590aa8404562ddf0093edbe4993d1a16b11ba1efa5135e78e2b957f5ef114a41e8e0399cfcc08c5
|
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
|
|
|
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.add_development_dependency 'rake'
|
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.5'
|
|
24
24
|
spec.add_development_dependency 'pg'
|
|
25
|
-
spec.add_development_dependency 'activesupport', '>= 4.2.0', '<
|
|
25
|
+
spec.add_development_dependency 'activesupport', '>= 4.2.0', '< 9'
|
|
26
26
|
spec.add_development_dependency 'rubocop', '~> 0.28'
|
|
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', '~>
|
|
31
|
-
spec.add_dependency 'activerecord', '>= 4.2.0', '<
|
|
30
|
+
spec.add_dependency 'json_schemer', '~> 2.2'
|
|
31
|
+
spec.add_dependency 'activerecord', '>= 4.2.0', '< 9'
|
|
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.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rémi Prévost
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -75,7 +75,7 @@ dependencies:
|
|
|
75
75
|
version: 4.2.0
|
|
76
76
|
- - "<"
|
|
77
77
|
- !ruby/object:Gem::Version
|
|
78
|
-
version: '
|
|
78
|
+
version: '9'
|
|
79
79
|
type: :development
|
|
80
80
|
prerelease: false
|
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -85,7 +85,7 @@ dependencies:
|
|
|
85
85
|
version: 4.2.0
|
|
86
86
|
- - "<"
|
|
87
87
|
- !ruby/object:Gem::Version
|
|
88
|
-
version: '
|
|
88
|
+
version: '9'
|
|
89
89
|
- !ruby/object:Gem::Dependency
|
|
90
90
|
name: rubocop
|
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -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
|
|
@@ -151,7 +151,7 @@ dependencies:
|
|
|
151
151
|
version: 4.2.0
|
|
152
152
|
- - "<"
|
|
153
153
|
- !ruby/object:Gem::Version
|
|
154
|
-
version: '
|
|
154
|
+
version: '9'
|
|
155
155
|
type: :runtime
|
|
156
156
|
prerelease: false
|
|
157
157
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -161,7 +161,7 @@ dependencies:
|
|
|
161
161
|
version: 4.2.0
|
|
162
162
|
- - "<"
|
|
163
163
|
- !ruby/object:Gem::Version
|
|
164
|
-
version: '
|
|
164
|
+
version: '9'
|
|
165
165
|
description: ActiveRecord::JSONValidator makes it easy to validate JSON attributes
|
|
166
166
|
with a JSON schema.
|
|
167
167
|
email:
|
|
@@ -194,7 +194,7 @@ homepage: https://github.com/mirego/activerecord_json_validator
|
|
|
194
194
|
licenses:
|
|
195
195
|
- BSD 3-Clause
|
|
196
196
|
metadata: {}
|
|
197
|
-
post_install_message:
|
|
197
|
+
post_install_message:
|
|
198
198
|
rdoc_options: []
|
|
199
199
|
require_paths:
|
|
200
200
|
- lib
|
|
@@ -209,8 +209,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
209
209
|
- !ruby/object:Gem::Version
|
|
210
210
|
version: '0'
|
|
211
211
|
requirements: []
|
|
212
|
-
rubygems_version: 3.
|
|
213
|
-
signing_key:
|
|
212
|
+
rubygems_version: 3.5.11
|
|
213
|
+
signing_key:
|
|
214
214
|
specification_version: 4
|
|
215
215
|
summary: ActiveRecord::JSONValidator makes it easy to validate JSON attributes with
|
|
216
216
|
a JSON schema.
|