Skip to content

Commit

Permalink
[rubocop#1295] Covers validates_comparison_of in Rails/Validations
Browse files Browse the repository at this point in the history
Rails/Validations should include all old-style validation helpers,
including validates_comparison_of.
  • Loading branch information
ChaelCodes committed Jun 13, 2024
1 parent 202d8c1 commit 6aa2123
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/change_merge_pull_request_1293_from.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#x](https://github.com/rubocop/rubocop-rails/pull/x): Merge pull request #1293 from fatkodima/where-range-unsafe. ([@][])
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 6aa2123

Please sign in to comment.