activerecord_json_validator 1.2.0 → 1.3.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 +5 -5
- data/.travis.yml +12 -5
- data/Gemfile +2 -0
- data/Rakefile +3 -1
- data/activerecord_json_validator.gemspec +2 -2
- data/gemfiles/Gemfile.activerecord-4.2.x +1 -0
- data/gemfiles/Gemfile.activerecord-6.0.x +5 -0
- data/lib/active_record/json_validator/validator.rb +3 -0
- data/lib/active_record/json_validator/version.rb +3 -1
- data/lib/activerecord_json_validator.rb +2 -0
- data/spec/json_validator_spec.rb +5 -3
- 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 +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d9dce365377ebd51d3f5b8156e3cf928507014ed1278c0ca794675b4fecd3d2c
|
4
|
+
data.tar.gz: b1f58a7b215df70ff616dd80ee31dd24dd8fa0b0020189ee99318fb577a38621
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b0f0f8e654453f06fd16d31324b8d3cfa069411e206cbc3b58575987984bda9ece9156411121d5202c701fd4dcece6ed5ab7b40eac5d5116a02f3347f2e0a4c
|
7
|
+
data.tar.gz: 355f0fec168526d3e881efb0b9ef5434089d2bc531adeb6f6dc9af61ea96dbb4a30600d744babd82dd57df2b6157d36a1d4e9ed837af902295d8419b7e5bfe91
|
data/.travis.yml
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.3
|
4
|
+
- 2.4.6
|
5
|
+
- 2.6.3
|
6
6
|
|
7
7
|
gemfile:
|
8
8
|
- gemfiles/Gemfile.activerecord-4.2.x
|
9
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/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
|
|
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
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.2.0', '<
|
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
30
|
spec.add_dependency 'json-schema', '~> 2.8'
|
31
|
-
spec.add_dependency 'activerecord', '>= 4.2.0', '<
|
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)
|
@@ -61,6 +63,7 @@ protected
|
|
61
63
|
|
62
64
|
def validatable_value(value)
|
63
65
|
return value if value.is_a?(String)
|
66
|
+
|
64
67
|
::ActiveSupport::JSON.encode(value)
|
65
68
|
end
|
66
69
|
|
data/spec/json_validator_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# rubocop:disable Metrics/BlockLength
|
2
4
|
require 'spec_helper'
|
3
5
|
|
@@ -94,7 +96,7 @@ describe JsonValidator do
|
|
94
96
|
|
95
97
|
before do
|
96
98
|
expect(validator_errors).to receive(:empty?).and_return(false)
|
97
|
-
expect(validator_errors).to receive(:to_a).and_return(%i
|
99
|
+
expect(validator_errors).to receive(:to_a).and_return(%i[first_error second_error])
|
98
100
|
expect(record).not_to receive(:"#{attribute}_invalid_json")
|
99
101
|
expect(record_errors).to receive(:add).with(attribute, :first_error, value: value)
|
100
102
|
expect(record_errors).to receive(:add).with(attribute, :second_error, value: value)
|
@@ -173,7 +175,7 @@ describe JsonValidator do
|
|
173
175
|
let(:validator) { JsonValidator.new(options) }
|
174
176
|
let(:options) { { attributes: [:foo], message: message_option } }
|
175
177
|
let(:message) { validator.send(:message, errors) }
|
176
|
-
let(:errors) { %i
|
178
|
+
let(:errors) { %i[first_error second_error] }
|
177
179
|
|
178
180
|
context 'with Symbol message' do
|
179
181
|
let(:message_option) { :invalid_json }
|
@@ -182,7 +184,7 @@ describe JsonValidator do
|
|
182
184
|
|
183
185
|
context 'with String value' do
|
184
186
|
let(:message_option) { ->(errors) { errors } }
|
185
|
-
it { expect(message).to eql(%i
|
187
|
+
it { expect(message).to eql(%i[first_error second_error]) }
|
186
188
|
end
|
187
189
|
end
|
188
190
|
end
|
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: 1.
|
4
|
+
version: 1.3.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: 2019-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -89,7 +89,7 @@ dependencies:
|
|
89
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
|
@@ -99,7 +99,7 @@ dependencies:
|
|
99
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
|
@@ -151,7 +151,7 @@ dependencies:
|
|
151
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
|
@@ -161,7 +161,7 @@ dependencies:
|
|
161
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:
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- activerecord_json_validator.gemspec
|
182
182
|
- gemfiles/Gemfile.activerecord-4.2.x
|
183
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.6.8
|
214
|
+
rubygems_version: 3.0.3
|
215
215
|
signing_key:
|
216
216
|
specification_version: 4
|
217
217
|
summary: ActiveRecord::JSONValidator makes it easy to validate JSON attributes with
|