Skip to content

Commit

Permalink
Merge pull request #1297 from ChaelCodes/1295-rails-validations-cover…
Browse files Browse the repository at this point in the history
…s-comparison

[Fix #1295] Covers validates_comparison_of in Rails/Validations
  • Loading branch information
koic committed Jun 21, 2024
2 parents 906e18c + 7e77248 commit dec8343
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 dec8343

Please sign in to comment.