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/WhereEquals throughs error with specific ActiveRecord usecase #401

Closed
mobilutz opened this issue Dec 9, 2020 · 0 comments · Fixed by #405
Closed

Rails/WhereEquals throughs error with specific ActiveRecord usecase #401

mobilutz opened this issue Dec 9, 2020 · 0 comments · Fixed by #405
Labels
bug Something isn't working

Comments

@mobilutz
Copy link
Contributor

mobilutz commented Dec 9, 2020

Some code I support, has an implementation, which throughs in error inside Rails/WhereEquals.
The code is strange, but it works and does what it needs to do.


Expected behavior

Rubocop should not through an error on the code

Actual behavior

This error is thrown.

undefined method `hash_type?' for nil:NilClass
[...]/rubocop-rails-2.9.0/lib/rubocop/cop/rails/where_equals.rb:71:in `extract_column_and_value'
[...]/rubocop-rails-2.9.0/lib/rubocop/cop/rails/where_equals.rb:41:in `block in on_send'
[...]/rubocop-rails-2.9.0/lib/rubocop/cop/rails/where_equals.rb:64:in `where_method_call?'
[...]/rubocop-rails-2.9.0/lib/rubocop/cop/rails/where_equals.rb:36:in `on_send'

Steps to reproduce the problem

Run rubocop with rubocop-rails >= 2.9.0 on this code:

def sql
  ::User.where('name = :name').select(:id).to_sql
end

::User.where("id IN (#{sql})", name: 'Lastname').first

Yes, this code works and returns the User with name: 'Lastname when it is run!!!!

RuboCop version

❯ bundle exec rubocop -V
1.5.2 (using Parser 2.7.2.0, rubocop-ast 1.3.0, running on ruby 2.7.2 x86_64-darwin19)
  - rubocop-performance 1.9.1
  - rubocop-rails 2.9.0
  - rubocop-rspec 2.0.1```
@koic koic added the bug Something isn't working label Dec 9, 2020
koic added a commit to koic/rubocop-rails that referenced this issue Dec 10, 2020
Fixes rubocop#401.

This PR fixes an error for `Rails/WhereEquals` when
using only named placeholder template without replacement argument.
koic added a commit to koic/rubocop-rails that referenced this issue Dec 10, 2020
Fixes rubocop#401.

This PR fixes an error for `Rails/WhereEquals` when
using only named placeholder template without replacement argument.
koic added a commit to koic/rubocop-rails that referenced this issue Dec 10, 2020
Fixes rubocop#401.

This PR fixes an error for `Rails/WhereEquals` when
using only named placeholder template without replacement argument.
koic added a commit to koic/rubocop-rails that referenced this issue Dec 12, 2020
Fixes rubocop#401.

This PR fixes an error for `Rails/WhereEquals` when
using only named placeholder template without replacement argument.
@koic koic closed this as completed in #405 Dec 12, 2020
koic added a commit that referenced this issue Dec 12, 2020
Earlopain added a commit to Earlopain/rubocop-rails that referenced this issue Aug 14, 2024
koic pushed a commit to koic/rubocop-rails that referenced this issue Aug 23, 2024
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
2 participants