Skip to content

Commit dec8343

Browse files
authored
Merge pull request #1297 from ChaelCodes/1295-rails-validations-covers-comparison
[Fix #1295] Covers validates_comparison_of in Rails/Validations
2 parents 906e18c + 7e77248 commit dec8343

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1295](https://github.com/rubocop/rubocop-rails/issues/1295): Cover validates_comparison_of in `Rails/Validation`. ([@ChaelCodes][])

lib/rubocop/cop/rails/validation.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ module Rails
88
# @example
99
# # bad
1010
# validates_acceptance_of :foo
11+
# validates_comparison_of :foo
1112
# validates_confirmation_of :foo
1213
# validates_exclusion_of :foo
1314
# validates_format_of :foo
@@ -22,6 +23,7 @@ module Rails
2223
# # good
2324
# validates :foo, acceptance: true
2425
# validates :foo, confirmation: true
26+
# validates :foo, comparison: true
2527
# validates :foo, exclusion: true
2628
# validates :foo, format: true
2729
# validates :foo, inclusion: true
@@ -39,6 +41,7 @@ class Validation < Base
3941

4042
TYPES = %w[
4143
acceptance
44+
comparison
4245
confirmation
4346
exclusion
4447
format

spec/rubocop/cop/rails/validation_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@
159159
include_examples 'autocorrects'
160160
end
161161

162+
context 'with a proc' do
163+
let(:autocorrected_source) do
164+
'validates :a, :b, comparison: { greater_than: -> { Time.zone.today } }'
165+
end
166+
167+
let(:source) do
168+
'validates_comparison_of :a, :b, greater_than: -> { Time.zone.today }'
169+
end
170+
171+
include_examples 'autocorrects'
172+
end
173+
162174
context 'with splat' do
163175
let(:autocorrected_source) do
164176
'validates :a, *b, numericality: true'

0 commit comments

Comments
 (0)