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

False positive on Rails/ActiveRecordAliases: Use update instead of update_attributes #898

Closed
bvicenzo opened this issue Dec 26, 2022 · 0 comments · Fixed by #899
Closed
Labels
bug Something isn't working

Comments

@bvicenzo
Copy link

I had a possible false positive for this rule when I used a local method named update_attributes.


Expected behavior

def update_attributes(raw_attributes)
  {
    name: raw_attributes['nome'],
    date_of_birth: Date.parse(raw_attributes['dataDeNascimento']),
    document_number: raw_attributes['NumeroDoDocumento']
  }
end

user = User.find(1)
user.update(update_attributes)

No issue was pointed out.

Actual behavior

def update_attributes(raw_attributes)
  {
    name: raw_attributes['nome'],
    date_of_birth: Date.parse(raw_attributes['dataDeNascimento']),
    document_number: raw_attributes['NumeroDoDocumento']
  }
end

user = User.find(1)
user.update(update_attributes)

W: [Correctable] Rails/ActiveRecordAliases: Use update instead of update_attributes.

Steps to reproduce the problem

  • put the above code in a file, for example, app/models/user_test.rb;
  • Run cops: bundle exec rubocop app/models/user_test.rb

RuboCop version

1.35.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.0.3 x86_64-linux-musl)
  - rubocop-performance 1.15.0
  - rubocop-rails 2.16.1
  - rubocop-rspec 2.13.2
@koic koic added the bug Something isn't working label Dec 27, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Dec 27, 2022
Fixes rubocop#898.

This PR fixes a false positive for `Rails/ActiveRecordAliases`
when arguments of `update_attributes` is empty.
@koic koic closed this as completed in #899 Dec 30, 2022
koic added a commit that referenced this issue Dec 30, 2022
…ve_record_aliases

[Fix #898] Fix a false positive for `Rails/ActiveRecordAliases`
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