activerecord_json_validator 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d73e408cd69522e53d830509f0a4772607eeee5b7a0102b25aea4a0e3f2fb62
4
- data.tar.gz: 9f3b97d92b0c5f8a55608fdd590e906b576d00036c87cff151967392244b7ada
3
+ metadata.gz: 1ebef8de77a6adb6c1ea4ff00c49c9e91b843952c4d226f4b149c04df9d585a6
4
+ data.tar.gz: 7efc4fa80a8dc82343bf1c7148e20f06df2acf127cbdbf9bc98e591e706940db
5
5
  SHA512:
6
- metadata.gz: f2fcf0da7354630f8619d075988f904dbb8b61b977e2f2fdd87f2f29fc545d5aaf0a0331e57c5e8d2bce5eeef9913900392a3a2978f6df17dd840546b9a706ca
7
- data.tar.gz: 7fd00e24032a036bccf04d1e9c677de07ae085ee7d46f658b8dcda0e2bc35d0cb0c263662b18c0fb86ed144eb3d248cfc213f9216641abae84d0c5afd9403675
6
+ metadata.gz: 1f096c0becc38bcdfb81cf70f59174509ea463f088ae02e514c612b397200aaef4dc76e7fd5cfe44ff0bf7c17fe2715a77d41d02101bac55afad19bbb076497a
7
+ data.tar.gz: e94f0da67f515a20eeb5699be8823c267144eeb36d09c6a1a892d24faab9bc65ca8d2d70edbe4388f088505d75875ede5cd91366393f2b71d42675713f8423ed
data/README.md CHANGED
@@ -47,7 +47,7 @@ end
47
47
 
48
48
  class User < ActiveRecord::Base
49
49
  # Constants
50
- PROFILE_JSON_SCHEMA = Pathname.new(Rails.root.join('config', 'schemas', 'profile.json'))
50
+ PROFILE_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile.json')
51
51
 
52
52
  # Validations
53
53
  validates :name, presence: true
@@ -85,8 +85,8 @@ context of the validated record (`Symbol` will be sent as a method and the
85
85
  ```ruby
86
86
  class User < ActiveRecord::Base
87
87
  # Constants
88
- PROFILE_REGULAR_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile.json_schema').to_s
89
- PROFILE_ADMIN_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile_admin.json_schema').to_s
88
+ PROFILE_REGULAR_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile.json_schema')
89
+ PROFILE_ADMIN_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'profile_admin.json_schema')
90
90
 
91
91
  # Validations
92
92
  validates :profile, presence: true, json: { schema: lambda { dynamic_profile_schema } } # `schema: :dynamic_profile_schema` would also work
@@ -22,6 +22,7 @@ class JsonValidator < ActiveModel::EachValidator
22
22
 
23
23
  # Add error message to the attribute
24
24
  message(errors).each do |error|
25
+ error = error.is_a?(Hash) ? JSONSchemer::Errors.pretty(error) : error
25
26
  record.errors.add(attribute, error, value: value)
26
27
  end
27
28
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module JSONValidator
5
- VERSION = '2.1.0'
5
+ VERSION = '2.1.1'
6
6
  end
7
7
  end
@@ -24,16 +24,18 @@ describe JsonValidator do
24
24
  }
25
25
  '
26
26
  serialize :data, JSON
27
- validates :data, json: { schema: schema, message: ->(errors) { errors.map { |error| error['details'].to_a.flatten.join(' ') } } }
27
+ serialize :other_data, JSON
28
+ validates :data, json: { schema: schema, message: ->(errors) { errors } }
29
+ validates :other_data, json: { schema: schema, message: ->(errors) { errors.map { |error| error['details'].to_a.flatten.join(' ') } } }
28
30
  end
29
31
  end
30
32
 
31
33
  context 'with valid JSON data but schema errors' do
32
- let(:user) { User.new(data: '{"city":"Quebec City"}') }
34
+ let(:user) { User.new(data: '{"city":"Quebec City"}', other_data: '{"city":"Quebec City"}') }
33
35
 
34
36
  specify do
35
37
  expect(user).not_to be_valid
36
- expect(user.errors.full_messages).to eql(['Data missing_keys country'])
38
+ expect(user.errors.full_messages).to eql(['Data root is missing required keys: country', 'Other data missing_keys country'])
37
39
  expect(user.data).to eql({ 'city' => 'Quebec City' })
38
40
  expect(user.data_invalid_json).to be_nil
39
41
  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.0
4
+ version: 2.1.1
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: 2021-12-08 00:00:00.000000000 Z
11
+ date: 2022-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler