Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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? &&
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/annotate/annotate_models_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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