Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an error for
Rails/HasManyOrHasOneDependent
This PR fixes an error for `Rails/HasManyOrHasOneDependent` when an Active Record model does not have any relations. The reproduction procedure is as follows. ```console % cat app/models/person.rb class Person < ApplicationRecord end % rubocop app/models/person.rb -R --only Rails/HasManyOrHasOneDependent -d For /private/tmp: configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/config/default.yml Inheriting configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/config/enabled.yml Inheriting configuration from /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/config/disabled.yml Inspecting 1 file Scanning /private/tmp/app/models/person.rb An error occurred while Rails/HasManyOrHasOneDependent cop was inspecting /private/tmp/app/models/person.rb:1:0. undefined method `each_descendant' for nil:NilClass /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:59:in `block in on_class' /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:28:in `activerecord_class' /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb:57:in `on_class' /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops' /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling' /Users/koic/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/rubocop-0.59.1/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops' (snip) 1 file inspected, no offenses detected 1 error occurred: An error occurred while Rails/HasManyOrHasOneDependent cop was inspecting /private/tmp/app/models/person.rb:1:0. Errors are usually caused by RuboCop bugs. Please, report your problems to RuboCop's issue tracker. https://github.com/rubocop-hq/rubocop/issues Mention the following information in the issue report: 0.59.1 (using Parser 2.5.1.2, running on ruby 2.5.1 x86_64-darwin17) ``` This error is a regression by #6298.
- Loading branch information