Skip to content

Commit

Permalink
[Fix #1295] Cover validates_comparison_of in Rails/Validation
Browse files Browse the repository at this point in the history
Rails/Validation should include all old-style validation helpers,
including validates_comparison_of.
  • Loading branch information
ChaelCodes committed Jun 19, 2024
1 parent 906e18c commit 7e77248
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/change_1295_covers_validates_comparison_of_in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#1295](https://github.com/rubocop/rubocop-rails/issues/1295): Cover validates_comparison_of in `Rails/Validation`. ([@ChaelCodes][])
3 changes: 3 additions & 0 deletions lib/rubocop/cop/rails/validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Rails
# @example
# # bad
# validates_acceptance_of :foo
# validates_comparison_of :foo
# validates_confirmation_of :foo
# validates_exclusion_of :foo
# validates_format_of :foo
Expand All @@ -22,6 +23,7 @@ module Rails
# # good
# validates :foo, acceptance: true
# validates :foo, confirmation: true
# validates :foo, comparison: true
# validates :foo, exclusion: true
# validates :foo, format: true
# validates :foo, inclusion: true
Expand All @@ -39,6 +41,7 @@ class Validation < Base

TYPES = %w[
acceptance
comparison
confirmation
exclusion
format
Expand Down
12 changes: 12 additions & 0 deletions spec/rubocop/cop/rails/validation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@
include_examples 'autocorrects'
end

context 'with a proc' do
let(:autocorrected_source) do
'validates :a, :b, comparison: { greater_than: -> { Time.zone.today } }'
end

let(:source) do
'validates_comparison_of :a, :b, greater_than: -> { Time.zone.today }'
end

include_examples 'autocorrects'
end

context 'with splat' do
let(:autocorrected_source) do
'validates :a, *b, numericality: true'
Expand Down

0 comments on commit 7e77248

Please sign in to comment.