can_has_validations 1.8.2 → 1.10.0

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: 2f635564611bf5299054332c630d3a8b79f35df7d7043c2c5fa69916fb9b1c6d
4
- data.tar.gz: f4285094a1ce68e23afbadfa184e15a369b80fc17cf7b7f3c3290d03a33ae0b9
3
+ metadata.gz: 6dbc656acb1fae4f12c6fc7a6f8e88e1f2c96ff47ddc612fdb7b56099e5df65b
4
+ data.tar.gz: 9a7ac65e91916c068f61005a408b09e38281bb1c724b077a76bb8e3a4017710a
5
5
  SHA512:
6
- metadata.gz: cf8882a6d062c0cb28820fd8fcdd8807033e9a70a7ad870cf601e3358cba9f583d83e42e64a340da811c4d54e20713266c93d21cc23626098aebbbc02491fc64
7
- data.tar.gz: aaabdb88bc3eded9d74a7bdbaac39a2ea3fb7d66a33a7b9fc6cc3e7b2e6d4975b7203feb18e1e4d7f6f0042b5a5755c942d1886d5f1cae5064e3b9daf88e101a
6
+ metadata.gz: bbc3a6e51590d3d48dceb1ca458b0b14ba3564203e14ff1eb6bb881b7f121e5af58adf683681ecaeef946fa377a2721b098dea2bab699a5e01bd037dfbf67fc9
7
+ data.tar.gz: f219af305b401c3d7e6a4f7b36b219a03022e1979f8b0233b901b423aba502dc937296e48b0ea3da32ce12a7730760092db5b11d966a8e7bd10d5350cf9bc21d
data/README.md CHANGED
@@ -17,7 +17,7 @@ Validations provided:
17
17
  * URL
18
18
  * Write Once
19
19
 
20
- All validators use the newer Rails 3+ syntax:
20
+ All validators use the newer Rails syntax:
21
21
 
22
22
  validates :some_attribute, email: true
23
23
 
@@ -89,7 +89,7 @@ so this is useful with Mongoid as well.
89
89
 
90
90
  ## Grandparent validator ##
91
91
 
92
- Ensures two (or more) associations share a common parent value.
92
+ Ensures two (or more) associations share a common parent value.
93
93
 
94
94
  `allow_nil: true` will not only allow the attribute/association to be nil, but
95
95
  also any of the `:scope` values.
@@ -100,21 +100,21 @@ Consider a model tree like this:
100
100
  has_many :addresses
101
101
  has_many :phones
102
102
  end
103
-
103
+
104
104
  class Address < ActiveRecord::Base
105
105
  belongs_to :user
106
106
  has_many :orders
107
107
  end
108
-
108
+
109
109
  class Phone < ActiveRecord::Base
110
110
  belongs_to :user
111
111
  has_many :orders
112
112
  end
113
-
113
+
114
114
  class Order < ActiveRecord::Base
115
115
  belongs_to :address
116
116
  belongs_to :phone
117
-
117
+
118
118
  validates :phone, grandparent: {scope: :address, parent: :user}
119
119
  end
120
120
 
@@ -123,10 +123,10 @@ For any `Order`, this ensures that both `:address` and `:phone` belong to the sa
123
123
 
124
124
  Basically it starts with the attribute being validated (`:phone` in this case)
125
125
  and the scoped attributes (just `:address` in this case, but you can supply an
126
- array if needed, eg: `scope: [:billing_address, :mailing_address]` ).
126
+ array if needed, eg: `scope: [:billing_address, :mailing_address]` ).
127
127
 
128
128
  Then, it looks for the attribute that is the common parent (`:user` in the above
129
- example). So, it's looking for `phone.user` and `address.user`.
129
+ example). So, it's looking for `phone.user` and `address.user`.
130
130
 
131
131
  Finally, it's comparing those values to make sure they match. In this case, if
132
132
  `phone.user` and `address.user` match, then the validation passes. If the phone and
@@ -245,7 +245,7 @@ Always skips over nil values; use `:presence` to validate those.
245
245
  # These two are the same, except `:now` produces a clearer error message:
246
246
  validates :finish_at, after: :now
247
247
  validates :finish_at, after: ->(r){ Time.now }
248
-
248
+
249
249
  # Long versions, if you need to add extra validation options:
250
250
  validates :start_at, before: {value_of: :finish_at, message: "..." }
251
251
  validates :finish_at, after: {values_of: [:start_at, :alt_start_at], if: ... }
@@ -315,6 +315,11 @@ Default messages are as follows:
315
315
  after: "must be after %{attribute2}"
316
316
 
317
317
 
318
- ## Compatibility ##
318
+ ## Contributing
319
+
320
+ PRs are welcomed.
321
+
322
+
323
+ ## License
319
324
 
320
- The current version is tested with Ruby 2.5-2.6 and ActiveModel 5.2-6.0.
325
+ MIT
@@ -18,7 +18,7 @@ module ActiveModel::Validations
18
18
  next unless value && greater
19
19
  unless value < greater
20
20
  attr2 = attr_name.respond_to?(:call) ? 'it is' : record.class.human_attribute_name(attr_name)
21
- record.errors.add(attribute, :before, **options.except(:before).merge!(attribute2: attr2, value: value))
21
+ record.errors.add(attribute, :before, value:, attribute2: attr2, before_value: greater, **options.except(:before))
22
22
  end
23
23
  end
24
24
  end
@@ -33,7 +33,7 @@ module ActiveModel::Validations
33
33
  next unless value && lesser
34
34
  unless value > lesser
35
35
  attr2 = attr_name.respond_to?(:call) ? 'it is' : record.class.human_attribute_name(attr_name)
36
- record.errors.add(attribute, :after, **options.except(:after).merge!(attribute2: attr2, value: value))
36
+ record.errors.add(attribute, :after, value:, attribute2: attr2, after_value: lesser, **options.except(:after))
37
37
  end
38
38
  end
39
39
  end
@@ -1,3 +1,3 @@
1
1
  module CanHasValidations
2
- VERSION = '1.8.2'
2
+ VERSION = '1.10.0'
3
3
  end
@@ -55,5 +55,23 @@ CanHasValidationsTest: test_truth
55
55
  TRANSACTION (0.0ms) begin transaction
56
56
  ---------------------------------
57
57
  CanHasValidationsTest: test_truth
58
+ ---------------------------------
59
+ TRANSACTION (0.0ms) rollback transaction
60
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
61
+ TRANSACTION (0.0ms) begin transaction
62
+ ---------------------------------
63
+ CanHasValidationsTest: test_truth
64
+ ---------------------------------
65
+ TRANSACTION (0.0ms) rollback transaction
66
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
67
+ TRANSACTION (0.0ms) begin transaction
68
+ ---------------------------------
69
+ CanHasValidationsTest: test_truth
70
+ ---------------------------------
71
+ TRANSACTION (0.0ms) rollback transaction
72
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
73
+ TRANSACTION (0.0ms) begin transaction
74
+ ---------------------------------
75
+ CanHasValidationsTest: test_truth
58
76
  ---------------------------------
59
77
  TRANSACTION (0.0ms) rollback transaction
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_has_validations
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.2
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thomas morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-18 00:00:00.000000000 Z
11
+ date: 2024-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.2'
19
+ version: '7.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.2'
22
+ version: '8.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '5.2'
29
+ version: '7.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.2'
32
+ version: '8.1'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -48,17 +48,17 @@ dependencies:
48
48
  name: sqlite3
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '1.4'
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '1.4'
61
- description: 'Assorted Rails 5.x-7.x validators: Array, Email, Existence, Grandparent,
60
+ version: '0'
61
+ description: 'Assorted Rails 7.x-8.x validators: Array, Email, Existence, Grandparent,
62
62
  Hash keys, Hash values, Hostname, IP address, Ordering, URL, Write Once'
63
63
  email:
64
64
  - tm@iprog.com
@@ -140,7 +140,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
140
  requirements:
141
141
  - - ">="
142
142
  - !ruby/object:Gem::Version
143
- version: '0'
143
+ version: '2.7'
144
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
145
  requirements:
146
146
  - - ">="
@@ -150,7 +150,7 @@ requirements: []
150
150
  rubygems_version: 3.5.11
151
151
  signing_key:
152
152
  specification_version: 4
153
- summary: Assorted Rails 5.x-7.x validators
153
+ summary: Assorted Rails 7.x-8.x validators
154
154
  test_files:
155
155
  - test/can_has_validations_test.rb
156
156
  - test/dummy/README.rdoc