diff --git a/lib/annotate/annotate_models.rb b/lib/annotate/annotate_models.rb index 69da7e862..77cd77335 100644 --- a/lib/annotate/annotate_models.rb +++ b/lib/annotate/annotate_models.rb @@ -809,7 +809,7 @@ def annotate_model_file(annotated, file, header, options) begin return false if /#{SKIP_ANNOTATION_PREFIX}.*/ =~ (File.exist?(file) ? File.read(file) : '') klass = get_model_class(file) - do_annotate = klass && + do_annotate = klass.is_a?(Class) && klass < ActiveRecord::Base && (!options[:exclude_sti_subclasses] || !(klass.superclass < ActiveRecord::Base && klass.table_name == klass.superclass.table_name)) && !klass.abstract_class? && diff --git a/spec/lib/annotate/annotate_models_spec.rb b/spec/lib/annotate/annotate_models_spec.rb index c3d0069e9..c9cab37af 100644 --- a/spec/lib/annotate/annotate_models_spec.rb +++ b/spec/lib/annotate/annotate_models_spec.rb @@ -2743,5 +2743,18 @@ class Foo < ActiveRecord::Base; end it 'skips attempt to annotate if no table exists for model' do is_expected.to eq nil end + + context 'with a non-class' do + before do + NotAClass = 'foo'.freeze # rubocop:disable Naming/ConstantName + allow(AnnotateModels).to receive(:get_model_class).with('foo.rb') { NotAClass } + end + + after { Object.send :remove_const, 'NotAClass' } + + it "doesn't output an error" do + expect { subject }.not_to output.to_stderr + end + end end end