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

AfterCommitOverride fails with lambda param #345

Closed
gaffneyc opened this issue Sep 6, 2020 · 0 comments · Fixed by #347
Closed

AfterCommitOverride fails with lambda param #345

gaffneyc opened this issue Sep 6, 2020 · 0 comments · Fixed by #347
Labels
bug Something isn't working

Comments

@gaffneyc
Copy link

gaffneyc commented Sep 6, 2020

Expected behavior

AfterCommitOverride should ignore lambda or block arguments and not error. The cop is supposed to only check that a given method isn't defined in multiple after_commit hooks as only the last definition will be used. One way to get around this is to instead pass a lambda which will call the method. Unfortunately that causes the cop to error.

Actual behavior

RuboCop errors with the below (truncated) stack:

undefined method `value' for #<RuboCop::AST::BlockNode:0x00007f7dee922ef8>
rubocop-rails-2.8.0/lib/rubocop/cop/rails/after_commit_override.rb:49:in `block in on_class'
rubocop-rails-2.8.0/lib/rubocop/cop/rails/after_commit_override.rb:62:in `block in each_after_commit_callback'
rubocop-rails-2.8.0/lib/rubocop/cop/rails/after_commit_override.rb:61:in `each'
rubocop-rails-2.8.0/lib/rubocop/cop/rails/after_commit_override.rb:61:in `each_after_commit_callback'
rubocop-rails-2.8.0/lib/rubocop/cop/rails/after_commit_override.rb:48:in `on_class'

Steps to reproduce the problem

class Fake < ActiveRecord::Base
  after_commit -> { foo }

  def foo
  end
end
rubocop -d -o Rails/AfterCommitOverride app/models/fake.rb

RuboCop version

0.90.0 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.7.1 x86_64-linux)
@koic koic added the bug Something isn't working label Sep 7, 2020
pocke added a commit to pocke/rubocop-rails that referenced this issue Sep 7, 2020
@koic koic closed this as completed in #347 Sep 7, 2020
koic added a commit that referenced this issue Sep 7, 2020
[Fix #345] Fix error of `Rails/AfterCommitOverride` on `after_commit`with a lambda
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
Development

Successfully merging a pull request may close this issue.

2 participants