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

Wrong autocorrect for Rails/Validation #118

Closed
geniou opened this issue Aug 27, 2019 · 2 comments · Fixed by #119
Closed

Wrong autocorrect for Rails/Validation #118

geniou opened this issue Aug 27, 2019 · 2 comments · Fixed by #119
Labels
bug Something isn't working

Comments

@geniou
Copy link
Contributor

geniou commented Aug 27, 2019

When running the auto correct of Rails/Validation is producing invalid code.


Expected behavior

validates_presence_of %i[foo bar] should be corrected to validates :foo, :bar, presence: true or skipped.

Actual behavior

Got corrected to validates %i[foo bar], presence: true which is invalid and fails with undefined method to_sym' for #Array:0x0000000009efab88`

Steps to reproduce the problem

see code snippets

RuboCop version

0.74.0 (using Parser 2.6.3.0, running on ruby 2.6.3 x86_64-darwin18)

@geniou geniou changed the title wrong autocorrect of Rails/Validation Wrong autocorrect for Rails/Validation Aug 27, 2019
@koic koic added the bug Something isn't working label Aug 27, 2019
koic added a commit to koic/rubocop-rails that referenced this issue Aug 27, 2019
Fixes rubocop#118.

This PR fixes an incorrect autocorrect for `Rails/Validation`
when attributes are specified with symbol array literal.

The following auto-corrected causes `NoMethodError`.

```ruby
validates %i[full_name birth_date], presence: true

# => validates_with': undefined method `to_sym' for
#    [:full_name, :birth_date]:Array (NoMethodError)
```

This PR will auto-corrected to the following code.

```ruby
validates :full_name, :birth_date, presence: true
```
koic added a commit to koic/rubocop-rails that referenced this issue Aug 27, 2019
Fixes rubocop#118.

This PR fixes an incorrect autocorrect for `Rails/Validation`
when attributes are specified with symbol array literal.

The following auto-corrected causes `NoMethodError`.

```ruby
validates %i[full_name birth_date], presence: true

# => validates_with': undefined method `to_sym' for
#    [:full_name, :birth_date]:Array (NoMethodError)
```

This PR will auto-correct it to the following code.

```ruby
validates :full_name, :birth_date, presence: true
```
koic added a commit to koic/rubocop-rails that referenced this issue Aug 28, 2019
Fixes rubocop#118.

This PR fixes an incorrect autocorrect for `Rails/Validation`
when attributes are specified with symbol array literal.

The following auto-corrected causes `NoMethodError`.

```ruby
validates %i[full_name birth_date], presence: true

# => validates_with': undefined method `to_sym' for
#    [:full_name, :birth_date]:Array (NoMethodError)
```

This PR will auto-correct it to the following code.

```ruby
validates :full_name, :birth_date, presence: true
```
koic added a commit to koic/rubocop-rails that referenced this issue Aug 28, 2019
Fixes rubocop#118.

This PR fixes an incorrect autocorrect for `Rails/Validation`
when attributes are specified with symbol array literal.

The following auto-corrected causes `NoMethodError`.

```ruby
validates %i[full_name birth_date], presence: true

# => validates_with': undefined method `to_sym' for
#    [:full_name, :birth_date]:Array (NoMethodError)
```

This PR will auto-correct it to the following code.

```ruby
validates :full_name, :birth_date, presence: true
```
@koic koic closed this as completed in #119 Aug 31, 2019
koic added a commit that referenced this issue Aug 31, 2019
…ils_validation

[Fix #118] Fix an incorrect autocorrect for `Rails/Validation`
@koic
Copy link
Member

koic commented Sep 1, 2019

RuboCop Rails 2.3.2 has been released to resolve this issue. Thank you.

@geniou
Copy link
Contributor Author

geniou commented Sep 2, 2019

@koic thank you! That was quick.

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