Skip to content

Commit

Permalink
handle exception in Rails/RedundantReceiverInWithOptions with empty b…
Browse files Browse the repository at this point in the history
…ody (#6855)
  • Loading branch information
ericsullivan authored and koic committed Mar 22, 2019
1 parent ebbafd2 commit 2df1e20
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,9 @@

## master (unreleased)

### Bug fixes
* [#6855](https://github.com/rubocop-hq/rubocop/pull/6855): Fix an exception in `Rails/RedundantReceiverInWithOptions` when the body is empty. ([@ericsullivan][])

### Changes

* [#5977](https://github.com/rubocop-hq/rubocop/issues/5977): Warn for Performance Cops. ([@koic][])
Expand Down Expand Up @@ -3882,3 +3885,4 @@
[@elmasantos]: https://github.com/elmasantos
[@luciamo]: https://github.com/luciamo
[@dirtyharrycallahan]: https://github.com/dirtyharrycallahan
[@ericsullivan]: https://github.com/ericsullivan
Expand Up @@ -81,6 +81,7 @@ class RedundantReceiverInWithOptions < Cop

def on_block(node)
with_options?(node) do |arg, body|
return if body.nil?
return unless all_block_nodes_in(body).count.zero?

send_nodes = all_send_nodes_in(body)
Expand Down
Expand Up @@ -87,12 +87,20 @@ class Account < ApplicationRecord
end
RUBY
end

it 'does not register an offense when empty' do
expect_no_offenses(<<-RUBY.strip_indent)
with_options options: false do |merger|
end
RUBY
end
end

context 'rails <= 4.1' do
let(:rails_version) { 4.1 }

it 'registers an offense when using explicit receiver in `with_options`' do
it 'does not register an offense when using explicit receiver in ' \
'`with_options`' do
expect_no_offenses(<<-RUBY.strip_indent)
class Account < ApplicationRecord
with_options dependent: :destroy do |assoc|
Expand Down

0 comments on commit 2df1e20

Please sign in to comment.