activerecord_json_validator 2.1.3 → 2.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f6f85c2656b56c867aa06f583528e3d315026c0537369311d6302adaeda42ad6
4
- data.tar.gz: 34894b9ed770db328de8011be097b72f59bb08431b45ddeb3024af01d1cf29b3
3
+ metadata.gz: 851b94edf54cbfdcd0a66a80dab95bcdeeea0e1c4a8831f634bc55aad5cba226
4
+ data.tar.gz: bf3a8280ffa8300469e793422adc68e83ab444047db67d9e6cbafec528f69803
5
5
  SHA512:
6
- metadata.gz: db0d5e91cbbefb083b7c55d2633ef82e87868943a54dd09254f27b4ab85a5d6474eaa277ab0e23ad988a6b7f6bfc35ca870a0b735d9007b32ef5ce638fe9e198
7
- data.tar.gz: a5cc28a84fd2037ec6623fce0cbbb665723a8481b89afb07139c46e6c7a8a047c885dfb1848aca667542196cd0e6c29fabf81081ad7b98c633644dbe4af4de7b
6
+ metadata.gz: 33766dfbea4cf464c499709f76b742f3bfe9b37dcc656206a15794f93733ec6711f127057ff2efb67bb75b6e439e64e75ada856d62fcdb2fece42e4ddd81b6ff
7
+ data.tar.gz: 7192194e8663dfbd9d343b66866ebab63d843200581bbe59be2c3f3bd485819fb13bba58bfb29241afa661c180399acce0d6fa3cf24a9d6fd5852b1d300a1be8
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', '~> 2.0.0'
19
+ gem 'activerecord_json_validator', '~> 2.1.0'
20
20
  ```
21
21
 
22
22
  ## Usage
@@ -25,9 +25,10 @@ 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| JSONSchemer::Errors.pretty(e) }
28
29
  message(errors).each do |error|
29
- error = error.is_a?(Hash) ? JSONSchemer::Errors.pretty(error) : error
30
- record.errors.add(attribute, error, value: value)
30
+ error = JSONSchemer::Errors.pretty(error) if error.is_a?(Hash)
31
+ record.errors.add(attribute, error, errors: details, value: value)
31
32
  end
32
33
  end
33
34
 
@@ -68,10 +69,7 @@ protected
68
69
 
69
70
  def message(errors)
70
71
  message = options.fetch(:message)
71
-
72
- case message
73
- when Proc then [message.call(errors)].flatten if message.is_a?(Proc)
74
- else [message]
75
- end
72
+ message = message.call(errors) if message.is_a?(Proc)
73
+ [message].flatten
76
74
  end
77
75
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveRecord
4
4
  module JSONValidator
5
- VERSION = '2.1.3'
5
+ VERSION = '2.1.4'
6
6
  end
7
7
  end
@@ -48,6 +48,12 @@ describe JsonValidator do
48
48
  specify do
49
49
  expect(user).not_to be_valid
50
50
  expect(user.errors.full_messages).to eql(['Data root is missing required keys: country', 'Other data missing_keys country'])
51
+ expect(user.errors.group_by_attribute[:data].first).to have_attributes(
52
+ options: include(errors: ['root is missing required keys: country'])
53
+ )
54
+ expect(user.errors.group_by_attribute[:other_data].first).to have_attributes(
55
+ options: include(errors: ['root is missing required keys: country'])
56
+ )
51
57
  expect(user.data).to eql({ 'city' => 'Quebec City' })
52
58
  expect(user.data_invalid_json).to be_nil
53
59
  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.3
4
+ version: 2.1.4
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: 2022-11-24 00:00:00.000000000 Z
11
+ date: 2023-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler