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

Crash on class including ActiveModel::Model on valid? method #6977

Closed
net1957 opened this issue Apr 26, 2019 · 1 comment
Closed

Crash on class including ActiveModel::Model on valid? method #6977

net1957 opened this issue Apr 26, 2019 · 1 comment

Comments

@net1957
Copy link

net1957 commented Apr 26, 2019

Expected behavior

Rubocop should not fail

Actual behavior

An error occurred while Rails/ActiveRecordOverride cop was inspecting D:/Dvlt/ruby/projects/_active/Db_presenter/app/models/marycmd/test.rb:9:4.
undefined method `const_name' for nil:NilClass

I have duplicated my class to a simplified one that give the same error: fail on valid?

the test.rb file:

# frozen_string_literal: true

# Marycmd module
module Marycmd
  # rfq model
  class Rfq
    include ActiveModel::Model

    def save
      valid? ? save_to_db : false
    end

    private

    def save_to_db
      true # example
    end
  end
end

the trace:

Scanning D:/Dvlt/ruby/projects/_active/Db_presenter/app/models/marycmd/test.rb
An error occurred while Rails/ActiveRecordOverride cop was inspecting D:/Dvlt/ruby/projects/_active/Db_presenter/app/models/marycmd/test.rb:9:4.
undefined method `const_name' for nil:NilClass
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/rails/active_record_override.rb:42:in `on_def'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `each'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `each'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `on_begin'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:92:in `on_class'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:150:in `on_while'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:13:in `walk'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:46:in `investigate'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:116:in `investigate'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:104:in `offenses'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:44:in `inspect_file'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:273:in `inspect_file'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:220:in `block in do_inspection_loop'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:252:in `block in iterate_until_no_changes'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `loop'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `iterate_until_no_changes'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:216:in `do_inspection_loop'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:119:in `block in file_offenses'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:137:in `file_offense_cache'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:117:in `file_offenses'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:105:in `process_file'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:82:in `block in each_inspected_file'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `reduce'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each_inspected_file'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:73:in `inspect_files'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:39:in `run'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:174:in `execute_runner'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:75:in `execute_runners'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:47:in `run'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/exe/rubocop:25:in `block in <top (required)>'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
D:/program/dvlt/ruby/Ruby25-x64/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/exe/rubocop:24:in `<top (required)>'
D:/program/dvlt/ruby/Ruby25-x64/bin/rubocop:23:in `load'
D:/program/dvlt/ruby/Ruby25-x64/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

Use the latest rubocop version. previous versions did not fail at this code

RuboCop version

0.67.2 (using Parser 2.6.2.1, running on ruby 2.5.3 x64-mingw32)

Rails is 5.2.3

@koic koic added the duplicate label Apr 26, 2019
@koic
Copy link
Member

koic commented Apr 26, 2019

This issue is the same as #6888 and #6943 and resolved at #6889. It will be included in the next release RuboCop 0.68.

@koic koic closed this as completed Apr 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants