Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails/Validation for validates_size_of causes Unknown validator: 'SizeValidator' error #1270

Closed
theblang opened this issue Apr 16, 2024 · 0 comments · Fixed by #1271
Closed
Labels
bug Something isn't working

Comments

@theblang
Copy link

The Rails/Validation rule for validates_size_of tries to autocorrect the following to an unknown validator:

validates_size_of :attribute, minimum: 1, if: :condition?, message: 'must have at least one'


Expected behavior

Produce validates :attribute, length: { minimum: 1, if: :condition?, message: 'must have at least one' }

See also this doc

Actual behavior

Produces validates :attribute, size: { minimum: 1, if: :condition?, message: 'must have at least one' }, which causes an error:

ArgumentError:
  Unknown validator: 'SizeValidator'

Steps to reproduce the problem

Autocorrect a validates_size_of with Rails/Validation

RuboCop version

1.63.1 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.2.3) [x86_64-linux-musl]
  - rubocop-rails 2.24.1
@koic koic added the bug Something isn't working label Apr 17, 2024
koic added a commit to koic/rubocop-rails that referenced this issue Apr 17, 2024
koic added a commit to koic/rubocop-rails that referenced this issue Apr 17, 2024
Fixes rubocop#1270.

This PR fixes an incorrect autocorrect for `Rails/Validation`
when using `validates_size_of`.
koic added a commit that referenced this issue Apr 19, 2024
…ails_validation

[Fix #1270] Fix an incorrect autocorrect for `Rails/Validation`
fwolfst pushed a commit to fwolfst/rubocop-rails that referenced this issue Jun 3, 2024
Fixes rubocop#1270.

This PR fixes an incorrect autocorrect for `Rails/Validation`
when using `validates_size_of`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants