Skip to content

Commit dd73491

Browse files
authored
Merge pull request #1522 from Earlopain/find-by-where-block
Fix an error for `Rails/FindBy` when `where` takes a block
2 parents 7f0eea9 + 7421807 commit dd73491

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* [#1522](https://github.com/rubocop/rubocop-rails/pull/1522): Fix an error for `Rails/FindBy` when `where` takes a block. ([@earlopain][])

lib/rubocop/cop/rails/find_by.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def on_send(node)
4646
private
4747

4848
def where_method?(receiver)
49-
return false unless receiver
49+
return false if !receiver || receiver.any_block_type?
5050

5151
receiver.respond_to?(:method?) && receiver.method?(:where)
5252
end

spec/rubocop/cop/rails/find_by_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
RUBY
104104
end
105105

106+
it 'does not register an offense when where takes a block' do
107+
expect_no_offenses(<<~RUBY)
108+
where { foo }.take
109+
RUBY
110+
end
111+
106112
context 'when `IgnoreWhereFirst: true' do
107113
let(:cop_config) do
108114
{ 'IgnoreWhereFirst' => true }

0 commit comments

Comments
 (0)