File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change
1
+ * [ #573 ] ( https://github.com/rubocop/rubocop-rails/pull/573 ) : Fix an error for ` Rails/FindEach ` when using ` where ` with no receiver. ([ @koic ] [ ] )
Original file line number Diff line number Diff line change @@ -55,6 +55,8 @@ def active_model_error_where?(node)
55
55
end
56
56
57
57
def active_model_error? ( node )
58
+ return false if node . nil?
59
+
58
60
node . send_type? && node . method? ( :errors )
59
61
end
60
62
end
Original file line number Diff line number Diff line change 45
45
# Active Model Errors slice from the new query interface introduced in Rails 6.1.
46
46
it 'does not register an offense when using `model.errors.where`' do
47
47
expect_no_offenses ( <<~RUBY )
48
- model.errors.where(:title).each { |error| do_something(error) }
48
+ class Model < ApplicationRecord
49
+ model.errors.where(:title).each { |error| do_something(error) }
50
+ end
51
+ RUBY
52
+ end
53
+
54
+ it 'registers an offense when using `where` with no receiver' do
55
+ expect_offense ( <<~RUBY )
56
+ class Model < ApplicationRecord
57
+ where(record: [record1, record2]).each(&:touch)
58
+ ^^^^ Use `find_each` instead of `each`.
59
+ end
49
60
RUBY
50
61
end
51
62
You can’t perform that action at this time.
0 commit comments