activerecord_json_validator 0.5.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +1 -1
- data/.travis.yml +13 -6
- data/Gemfile +2 -0
- data/LICENSE.md +1 -1
- data/README.md +66 -66
- data/Rakefile +3 -1
- data/activerecord_json_validator.gemspec +5 -5
- data/gemfiles/Gemfile.activerecord-4.2.x +1 -0
- data/gemfiles/{Gemfile.activerecord-4.1.x → Gemfile.activerecord-5.0.x} +1 -1
- data/gemfiles/Gemfile.activerecord-6.0.x +5 -0
- data/lib/active_record/json_validator/validator.rb +16 -19
- data/lib/active_record/json_validator/version.rb +3 -1
- data/lib/activerecord_json_validator.rb +3 -1
- data/spec/json_validator_spec.rb +37 -15
- data/spec/spec_helper.rb +4 -2
- data/spec/support/macros/database/database_adapter.rb +2 -0
- data/spec/support/macros/database/mysql_adapter.rb +2 -0
- data/spec/support/macros/database/postgresql_adapter.rb +2 -0
- data/spec/support/macros/database_macros.rb +9 -1
- data/spec/support/macros/model_macros.rb +2 -0
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0f5b518bda8ab28520f561dc840f47223e252530a9182ef31a164c12fb831451
|
4
|
+
data.tar.gz: 79e01fcce3c8cb0e27f6e3e24df4db54a312f6cef7285f38cec05689e897d042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4e5420f0c6aaad0e1e13ed296bc598e88b16974bfbaa7e55cc1680ad4ca499ba0b570de3ee26d72a993cbb9e712370f7e23fcf14e56e46ba40d7c601c5695f1
|
7
|
+
data.tar.gz: 93cf5acde18b71f512f2f68eaec1ba8191a721e1ace7853604d9e6ac4c6c7d03ae88a19c402a4c8b8545e8bfa5546de4ced97dfa032536f18747a5658419b752
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
4
|
+
- 2.4.6
|
5
|
+
- 2.6.3
|
6
6
|
|
7
7
|
gemfile:
|
8
8
|
- gemfiles/Gemfile.activerecord-4.2.x
|
9
|
-
- gemfiles/Gemfile.activerecord-
|
9
|
+
- gemfiles/Gemfile.activerecord-5.0.x
|
10
|
+
- gemfiles/Gemfile.activerecord-6.0.x
|
11
|
+
|
12
|
+
matrix:
|
13
|
+
exclude:
|
14
|
+
- gemfile: gemfiles/Gemfile.activerecord-6.0.x
|
15
|
+
rvm: 2.4.6
|
10
16
|
|
11
17
|
sudo: false
|
12
18
|
|
19
|
+
services:
|
20
|
+
- mysql
|
21
|
+
- postgresql
|
22
|
+
|
13
23
|
env:
|
14
24
|
- DB_ADAPTER=mysql2
|
15
25
|
- DB_ADAPTER=postgresql
|
@@ -21,6 +31,3 @@ before_script:
|
|
21
31
|
script:
|
22
32
|
- 'echo "Checking code style" && bundle exec phare'
|
23
33
|
- 'echo "Running tests" && bundle exec rake spec'
|
24
|
-
|
25
|
-
addons:
|
26
|
-
postgresql: 9.3
|
data/Gemfile
CHANGED
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
<p align="center">
|
2
|
+
<a href="https://github.com/mirego/activerecord_json_validator">
|
3
|
+
<img src="https://cloud.githubusercontent.com/assets/11348/6099354/cffcf35e-afc3-11e4-9a4d-d872941bbcf6.png" alt="" />
|
4
|
+
</a>
|
5
|
+
<br />
|
6
|
+
<code>ActiveRecord::JSONValidator</code> makes it easy to validate<br /> JSON attributes against a <a href="http://json-schema.org/">JSON schema</a>.
|
7
|
+
<br /><br />
|
8
|
+
<a href="https://rubygems.org/gems/activerecord_json_validator"><img src="http://img.shields.io/gem/v/activerecord_json_validator.svg" /></a>
|
9
|
+
<a href="https://travis-ci.org/mirego/activerecord_json_validator"><img src="http://img.shields.io/travis/mirego/activerecord_json_validator.svg" /></a>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
---
|
7
13
|
|
8
14
|
## Installation
|
9
15
|
|
@@ -16,15 +22,31 @@ gem 'activerecord_json_validator'
|
|
16
22
|
## Usage
|
17
23
|
|
18
24
|
### JSON Schema
|
25
|
+
Schemas must use be a JSON string or use string keys.
|
19
26
|
|
20
27
|
```json
|
21
|
-
{
|
28
|
+
'{
|
22
29
|
"type": "object",
|
23
|
-
"$schema": "http://json-schema.org/draft-
|
30
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
24
31
|
"properties": {
|
25
|
-
"city": { "type": "string"
|
26
|
-
"country": { "type": "string"
|
27
|
-
}
|
32
|
+
"city": { "type": "string" },
|
33
|
+
"country": { "type": "string" }
|
34
|
+
},
|
35
|
+
"required": ["country"]
|
36
|
+
}'
|
37
|
+
```
|
38
|
+
|
39
|
+
or
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
{
|
43
|
+
"type" => "object",
|
44
|
+
"$schema" => "http://json-schema.org/draft-04/schema#",
|
45
|
+
"properties" => {
|
46
|
+
"city" => { "type" => "string" },
|
47
|
+
"country" => { "type" => "string" }
|
48
|
+
},
|
49
|
+
"required" => ["country"]
|
28
50
|
}
|
29
51
|
```
|
30
52
|
|
@@ -60,85 +82,63 @@ user.profile_invalid_json # => '{invalid JSON":}'
|
|
60
82
|
|
61
83
|
| Option | Description
|
62
84
|
|------------|-----------------------------------------------------
|
63
|
-
| `:schema` | The JSON schema to validate the data against (see **
|
64
|
-
| `:message` | The ActiveRecord message added to the record errors (
|
85
|
+
| `:schema` | The JSON schema to validate the data against (see **Schema** section)
|
86
|
+
| `:message` | The ActiveRecord message added to the record errors (see **Message** section)
|
87
|
+
| `:options` | A `Hash` of [`json_schemer`](https://github.com/davishmcclurg/json_schemer#options)-supported options to pass to the validator
|
65
88
|
|
66
|
-
#####
|
89
|
+
##### Schema
|
67
90
|
|
68
|
-
|
91
|
+
`ActiveRecord::JSONValidator` uses the [json_schemer](https://github.com/davishmcclurg/json_schemer) gem to validate the JSON
|
92
|
+
data against a JSON schema.
|
69
93
|
|
70
|
-
|
94
|
+
Additionally, you can use a `Symbol` or a `Proc`. Both will be executed in the
|
95
|
+
context of the validated record (`Symbol` will be sent as a method and the
|
96
|
+
`Proc` will be `instance_exec`ed)
|
71
97
|
|
72
98
|
```ruby
|
73
99
|
class User < ActiveRecord::Base
|
74
100
|
# Constants
|
75
|
-
|
101
|
+
PROFILE_REGULAR_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile.json_schema').to_s
|
102
|
+
PROFILE_ADMIN_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile_admin.json_schema').to_s
|
76
103
|
|
77
104
|
# Validations
|
78
|
-
validates :profile, presence: true, json: { schema:
|
79
|
-
end
|
80
|
-
```
|
105
|
+
validates :profile, presence: true, json: { schema: lambda { dynamic_profile_schema } } # `schema: :dynamic_profile_schema` would also work
|
81
106
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
class User < ActiveRecord::Base
|
86
|
-
# Constants
|
87
|
-
PROFILE_JSON_SCHEMA = {
|
88
|
-
type: 'object',
|
89
|
-
:'$schema' => 'http://json-schema.org/draft-03/schema',
|
90
|
-
properties: {
|
91
|
-
city: { type: 'string', required: false },
|
92
|
-
country: { type: 'string', required: true }
|
93
|
-
}
|
94
|
-
}
|
95
|
-
|
96
|
-
# Validations
|
97
|
-
validates :profile, presence: true, json: { schema: PROFILE_JSON_SCHEMA }
|
107
|
+
def dynamic_profile_schema
|
108
|
+
admin? ? PROFILE_ADMIN_JSON_SCHEMA : PROFILE_REGULAR_JSON_SCHEMA
|
109
|
+
end
|
98
110
|
end
|
99
111
|
```
|
100
112
|
|
101
|
-
|
102
|
-
|
103
|
-
```ruby
|
104
|
-
class User < ActiveRecord::Base
|
105
|
-
# Constants
|
106
|
-
PROFILE_JSON_SCHEMA = '{
|
107
|
-
"type": "object",
|
108
|
-
"$schema": "http://json-schema.org/draft-03/schema",
|
109
|
-
"properties": {
|
110
|
-
"city": { "type": "string", "required": false },
|
111
|
-
"country": { "type": "string", "required": true }
|
112
|
-
}
|
113
|
-
}'
|
114
|
-
|
115
|
-
# Validations
|
116
|
-
validates :profile, presence: true, json: { schema: PROFILE_JSON_SCHEMA }
|
117
|
-
end
|
118
|
-
```
|
113
|
+
##### Message
|
119
114
|
|
120
|
-
|
115
|
+
Like any other ActiveModel validation, you can specify either a `Symbol` or
|
116
|
+
`String` value for the `:message` option. The default value is `:invalid_json`.
|
121
117
|
|
122
|
-
|
118
|
+
However, you can also specify a `Proc` that returns an array of errors. The
|
119
|
+
`Proc` will be called with a single argument — an array of errors returned by
|
120
|
+
the JSON schema validator. So, if you’d like to add each of these errors as
|
121
|
+
a first-level error for the record, you can do this:
|
123
122
|
|
124
123
|
```ruby
|
125
124
|
class User < ActiveRecord::Base
|
126
|
-
# Constants
|
127
|
-
PROFILE_REGULAR_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile.json_schema').to_s
|
128
|
-
PROFILE_ADMIN_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile_admin.json_schema').to_s
|
129
|
-
|
130
125
|
# Validations
|
131
|
-
validates :profile, presence: true, json: {
|
132
|
-
|
133
|
-
def dynamic_profile_schema
|
134
|
-
admin? ? PROFILE_ADMIN_JSON_SCHEMA : PROFILE_REGULAR_JSON_SCHEMA
|
135
|
-
end
|
126
|
+
validates :profile, presence: true, json: { message: ->(errors) { errors }, schema: 'foo.json_schema' }
|
136
127
|
end
|
128
|
+
|
129
|
+
user = User.new.tap(&:valid?)
|
130
|
+
user.errors.full_messages
|
131
|
+
# => [
|
132
|
+
# 'The property '#/email' of type Fixnum did not match the following type: string in schema 2d44293f-cd9d-5dca-8a6a-fb9db1de722b#',
|
133
|
+
# 'The property '#/full_name' of type Fixnum did not match the following type: string in schema 2d44293f-cd9d-5dca-8a6a-fb9db1de722b#',
|
134
|
+
# ]
|
137
135
|
```
|
138
136
|
|
139
137
|
## License
|
140
138
|
|
141
|
-
`ActiveRecord::JSONValidator` is © 2013-
|
139
|
+
`ActiveRecord::JSONValidator` is © 2013-2016 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/activerecord_json_validator/blob/master/LICENSE.md) file.
|
140
|
+
|
141
|
+
The tree logo is based on [this lovely icon](http://thenounproject.com/term/tree/51004/) by [Sara Quintana](http://thenounproject.com/sara.quintana.75), from The Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
|
142
142
|
|
143
143
|
## About Mirego
|
144
144
|
|
data/Rakefile
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'bundler'
|
2
4
|
require 'rake'
|
3
5
|
require 'bundler/gem_tasks'
|
@@ -12,7 +14,7 @@ end
|
|
12
14
|
|
13
15
|
desc 'Start an IRB session with the gem'
|
14
16
|
task :console do
|
15
|
-
$LOAD_PATH.unshift File.expand_path(
|
17
|
+
$LOAD_PATH.unshift File.expand_path(__dir__)
|
16
18
|
require 'activerecord_json_validator'
|
17
19
|
require 'irb'
|
18
20
|
|
@@ -18,15 +18,15 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_development_dependency 'bundler', '~> 1.
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
22
22
|
spec.add_development_dependency 'rake'
|
23
|
-
spec.add_development_dependency 'rspec', '~> 3.
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
24
24
|
spec.add_development_dependency 'pg'
|
25
25
|
spec.add_development_dependency 'mysql2'
|
26
|
-
spec.add_development_dependency 'activesupport', '>= 4.
|
26
|
+
spec.add_development_dependency 'activesupport', '>= 4.2.0', '< 7'
|
27
27
|
spec.add_development_dependency 'phare'
|
28
28
|
spec.add_development_dependency 'rubocop', '~> 0.28'
|
29
29
|
|
30
|
-
spec.add_dependency '
|
31
|
-
spec.add_dependency 'activerecord', '>= 4.
|
30
|
+
spec.add_dependency 'json_schemer', '~> 0.2.18'
|
31
|
+
spec.add_dependency 'activerecord', '>= 4.2.0', '< 7'
|
32
32
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class JsonValidator < ActiveModel::EachValidator
|
2
4
|
def initialize(options)
|
3
5
|
options.reverse_merge!(message: :invalid_json)
|
@@ -7,30 +9,21 @@ class JsonValidator < ActiveModel::EachValidator
|
|
7
9
|
|
8
10
|
super
|
9
11
|
|
10
|
-
|
11
|
-
if options[:class]
|
12
|
-
inject_setter_method(options[:class], @attributes)
|
13
|
-
|
14
|
-
# Rails 4.0 and below calls a `#setup` method
|
15
|
-
elsif !respond_to?(:setup)
|
16
|
-
class_eval do
|
17
|
-
define_method :setup do |model|
|
18
|
-
inject_setter_method(model, @attributes)
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
12
|
+
inject_setter_method(options[:class], @attributes)
|
22
13
|
end
|
23
14
|
|
24
15
|
# Validate the JSON value with a JSON schema path or String
|
25
16
|
def validate_each(record, attribute, value)
|
26
|
-
# Validate value with JSON
|
27
|
-
errors =
|
17
|
+
# Validate value with JSON Schemer
|
18
|
+
errors = JSONSchemer.schema(schema(record), options.fetch(:options)).validate(value).to_a
|
28
19
|
|
29
20
|
# Everything is good if we don’t have any errors and we got valid JSON value
|
30
21
|
return if errors.empty? && record.send(:"#{attribute}_invalid_json").blank?
|
31
22
|
|
32
23
|
# Add error message to the attribute
|
33
|
-
|
24
|
+
message(errors).each do |error|
|
25
|
+
record.errors.add(attribute, error, value: value)
|
26
|
+
end
|
34
27
|
end
|
35
28
|
|
36
29
|
protected
|
@@ -56,7 +49,7 @@ protected
|
|
56
49
|
end
|
57
50
|
end
|
58
51
|
|
59
|
-
# Return a valid schema
|
52
|
+
# Return a valid schema, recursively calling
|
60
53
|
# itself until it gets a non-Proc/non-Symbol value.
|
61
54
|
def schema(record, schema = nil)
|
62
55
|
schema ||= options.fetch(:schema)
|
@@ -68,8 +61,12 @@ protected
|
|
68
61
|
end
|
69
62
|
end
|
70
63
|
|
71
|
-
def
|
72
|
-
|
73
|
-
|
64
|
+
def message(errors)
|
65
|
+
message = options.fetch(:message)
|
66
|
+
|
67
|
+
case message
|
68
|
+
when Proc then [message.call(errors)].flatten if message.is_a?(Proc)
|
69
|
+
else [message]
|
70
|
+
end
|
74
71
|
end
|
75
72
|
end
|
data/spec/json_validator_spec.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Metrics/BlockLength
|
1
4
|
require 'spec_helper'
|
2
5
|
|
3
6
|
describe JsonValidator do
|
@@ -39,7 +42,7 @@ describe JsonValidator do
|
|
39
42
|
|
40
43
|
describe :validate_each do
|
41
44
|
let(:validator) { JsonValidator.new(options) }
|
42
|
-
let(:options) { { attributes: [attribute], options: {
|
45
|
+
let(:options) { { attributes: [attribute], options: { format: true } } }
|
43
46
|
let(:validate_each!) { validator.validate_each(record, attribute, value) }
|
44
47
|
|
45
48
|
# Doubles
|
@@ -48,16 +51,18 @@ describe JsonValidator do
|
|
48
51
|
let(:record_errors) { double(:errors) }
|
49
52
|
let(:value) { double(:value) }
|
50
53
|
let(:schema) { double(:schema) }
|
51
|
-
let(:
|
54
|
+
let(:schema_validator) { double(:schema_validator) }
|
55
|
+
let(:raw_errors) { double(:raw_errors) }
|
52
56
|
let(:validator_errors) { double(:validator_errors) }
|
53
57
|
|
54
58
|
before do
|
55
59
|
expect(validator).to receive(:schema).with(record).and_return(schema)
|
56
|
-
expect(
|
57
|
-
expect(
|
60
|
+
expect(JSONSchemer).to receive(:schema).with(schema, options[:options]).and_return(schema_validator)
|
61
|
+
expect(schema_validator).to receive(:validate).with(value).and_return(raw_errors)
|
62
|
+
expect(raw_errors).to receive(:to_a).and_return(validator_errors)
|
58
63
|
end
|
59
64
|
|
60
|
-
context 'with JSON
|
65
|
+
context 'with JSON Schemer errors' do
|
61
66
|
before do
|
62
67
|
expect(validator_errors).to receive(:empty?).and_return(false)
|
63
68
|
expect(record).not_to receive(:"#{attribute}_invalid_json")
|
@@ -67,7 +72,7 @@ describe JsonValidator do
|
|
67
72
|
specify { validate_each! }
|
68
73
|
end
|
69
74
|
|
70
|
-
context 'without JSON
|
75
|
+
context 'without JSON Schemer errors but with invalid JSON data' do
|
71
76
|
before do
|
72
77
|
expect(validator_errors).to receive(:empty?).and_return(true)
|
73
78
|
expect(record).to receive(:"#{attribute}_invalid_json").and_return('foo"{]')
|
@@ -77,7 +82,7 @@ describe JsonValidator do
|
|
77
82
|
specify { validate_each! }
|
78
83
|
end
|
79
84
|
|
80
|
-
context 'without JSON
|
85
|
+
context 'without JSON Schemer errors and valid JSON data' do
|
81
86
|
before do
|
82
87
|
expect(validator_errors).to receive(:empty?).and_return(true)
|
83
88
|
expect(record).to receive(:"#{attribute}_invalid_json").and_return(nil)
|
@@ -86,6 +91,21 @@ describe JsonValidator do
|
|
86
91
|
|
87
92
|
specify { validate_each! }
|
88
93
|
end
|
94
|
+
|
95
|
+
context 'with multiple error messages' do
|
96
|
+
let(:options) { { attributes: [attribute], message: message, options: { strict: true } } }
|
97
|
+
let(:message) { ->(errors) { errors.to_a } }
|
98
|
+
|
99
|
+
before do
|
100
|
+
expect(validator_errors).to receive(:empty?).and_return(false)
|
101
|
+
expect(validator_errors).to receive(:to_a).and_return(%i[first_error second_error])
|
102
|
+
expect(record).not_to receive(:"#{attribute}_invalid_json")
|
103
|
+
expect(record_errors).to receive(:add).with(attribute, :first_error, value: value)
|
104
|
+
expect(record_errors).to receive(:add).with(attribute, :second_error, value: value)
|
105
|
+
end
|
106
|
+
|
107
|
+
specify { validate_each! }
|
108
|
+
end
|
89
109
|
end
|
90
110
|
|
91
111
|
describe :schema do
|
@@ -137,19 +157,21 @@ describe JsonValidator do
|
|
137
157
|
end
|
138
158
|
end
|
139
159
|
|
140
|
-
describe :
|
160
|
+
describe :message do
|
141
161
|
let(:validator) { JsonValidator.new(options) }
|
142
|
-
let(:options) { { attributes: [:foo] } }
|
143
|
-
let(:
|
162
|
+
let(:options) { { attributes: [:foo], message: message_option } }
|
163
|
+
let(:message) { validator.send(:message, errors) }
|
164
|
+
let(:errors) { %i[first_error second_error] }
|
144
165
|
|
145
|
-
context 'with
|
146
|
-
let(:
|
147
|
-
it { expect(
|
166
|
+
context 'with Symbol message' do
|
167
|
+
let(:message_option) { :invalid_json }
|
168
|
+
it { expect(message).to eql([:invalid_json]) }
|
148
169
|
end
|
149
170
|
|
150
171
|
context 'with String value' do
|
151
|
-
let(:
|
152
|
-
it { expect(
|
172
|
+
let(:message_option) { ->(errors) { errors } }
|
173
|
+
it { expect(message).to eql(%i[first_error second_error]) }
|
153
174
|
end
|
154
175
|
end
|
155
176
|
end
|
177
|
+
# rubocop:enable Metrics/BlockLength
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift File.expand_path('lib', __dir__)
|
2
4
|
|
3
5
|
require 'active_support/all'
|
4
6
|
require 'rspec'
|
@@ -8,7 +10,7 @@ require 'pg'
|
|
8
10
|
require 'activerecord_json_validator'
|
9
11
|
|
10
12
|
# Require our macros and extensions
|
11
|
-
Dir[File.expand_path('
|
13
|
+
Dir[File.expand_path('../spec/support/macros/**/*.rb', __dir__)].map(&method(:require))
|
12
14
|
|
13
15
|
RSpec.configure do |config|
|
14
16
|
# Include our macros
|
@@ -1,8 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module DatabaseMacros
|
2
4
|
# Run migrations in the test database
|
3
5
|
def run_migration(&block)
|
6
|
+
migration_class = if ActiveRecord::Migration.respond_to?(:[])
|
7
|
+
ActiveRecord::Migration[4.2]
|
8
|
+
else
|
9
|
+
ActiveRecord::Migration
|
10
|
+
end
|
11
|
+
|
4
12
|
# Create a new migration class
|
5
|
-
klass = Class.new(
|
13
|
+
klass = Class.new(migration_class)
|
6
14
|
|
7
15
|
# Create a new `up` that executes the argument
|
8
16
|
klass.send(:define_method, :up) { instance_exec(&block) }
|
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: 0.
|
4
|
+
version: 2.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: 2021-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.12'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '1.
|
26
|
+
version: '1.12'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
47
|
+
version: '3.5'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
54
|
+
version: '3.5'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pg
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,20 +86,20 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 4.
|
89
|
+
version: 4.2.0
|
90
90
|
- - "<"
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version: '
|
92
|
+
version: '7'
|
93
93
|
type: :development
|
94
94
|
prerelease: false
|
95
95
|
version_requirements: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
97
|
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: 4.
|
99
|
+
version: 4.2.0
|
100
100
|
- - "<"
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: '
|
102
|
+
version: '7'
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: phare
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -129,39 +129,39 @@ dependencies:
|
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0.28'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
132
|
+
name: json_schemer
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
135
|
- - "~>"
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
137
|
+
version: 0.2.18
|
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: 0.2.18
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: activerecord
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
149
|
- - ">="
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version: 4.
|
151
|
+
version: 4.2.0
|
152
152
|
- - "<"
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version: '
|
154
|
+
version: '7'
|
155
155
|
type: :runtime
|
156
156
|
prerelease: false
|
157
157
|
version_requirements: !ruby/object:Gem::Requirement
|
158
158
|
requirements:
|
159
159
|
- - ">="
|
160
160
|
- !ruby/object:Gem::Version
|
161
|
-
version: 4.
|
161
|
+
version: 4.2.0
|
162
162
|
- - "<"
|
163
163
|
- !ruby/object:Gem::Version
|
164
|
-
version: '
|
164
|
+
version: '7'
|
165
165
|
description: ActiveRecord::JSONValidator makes it easy to validate JSON attributes
|
166
166
|
with a JSON schema.
|
167
167
|
email:
|
@@ -179,8 +179,9 @@ files:
|
|
179
179
|
- README.md
|
180
180
|
- Rakefile
|
181
181
|
- activerecord_json_validator.gemspec
|
182
|
-
- gemfiles/Gemfile.activerecord-4.1.x
|
183
182
|
- gemfiles/Gemfile.activerecord-4.2.x
|
183
|
+
- gemfiles/Gemfile.activerecord-5.0.x
|
184
|
+
- gemfiles/Gemfile.activerecord-6.0.x
|
184
185
|
- lib/active_record/json_validator/validator.rb
|
185
186
|
- lib/active_record/json_validator/version.rb
|
186
187
|
- lib/activerecord_json_validator.rb
|
@@ -210,8 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
210
211
|
- !ruby/object:Gem::Version
|
211
212
|
version: '0'
|
212
213
|
requirements: []
|
213
|
-
|
214
|
-
rubygems_version: 2.2.2
|
214
|
+
rubygems_version: 3.1.6
|
215
215
|
signing_key:
|
216
216
|
specification_version: 4
|
217
217
|
summary: ActiveRecord::JSONValidator makes it easy to validate JSON attributes with
|