Skip to content

Commit

Permalink
Merge pull request #405 from koic/fix_an_error_for_rails_where_equals
Browse files Browse the repository at this point in the history
[Fix #401] Fix an error for `Rails/WhereEquals`
  • Loading branch information
koic authored Dec 12, 2020
2 parents abbb4fa + 3eecd98 commit 97c8578
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Bug fixes

* [#408](https://github.com/rubocop-hq/rubocop-rails/pull/408): Fix bug in `Rails/FindEach` where config was ignored. ([@ghiculescu][])
* [#401](https://github.com/rubocop-hq/rubocop-rails/issues/401): Fix an error for `Rails/WhereEquals` using only named placeholder template without replacement argument. ([@koic][])

## 2.9.0 (2020-12-09)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rails/where_equals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def extract_column_and_value(template_node, value_node)
when EQ_ANONYMOUS_RE, IN_ANONYMOUS_RE
value_node.source
when EQ_NAMED_RE, IN_NAMED_RE
return unless value_node.hash_type?
return unless value_node&.hash_type?

pair = value_node.pairs.find { |p| p.key.value.to_sym == Regexp.last_match(2).to_sym }
pair.value.source
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/where_equals_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,12 @@
User.where('name = ? AND age = ?', 'john', 19)
RUBY
end

it 'does not register an offense when using only named placeholder template without replacement argument' do
expect_no_offenses(<<~'RUBY')
sql = User.where('name = :name').select(:id).to_sql
User.where("id IN (#{sql})", name: 'Lastname').first
RUBY
end
end

0 comments on commit 97c8578

Please sign in to comment.