Skip to content

Commit a10fa78

Browse files
committed
Skip annotation if table doesn't exist
1 parent cca21f2 commit a10fa78

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ def do_annotations(options={})
411411
def annotate_model_file(annotated, file, header, options)
412412
begin
413413
klass = get_model_class(file)
414-
if klass && klass < ActiveRecord::Base && !klass.abstract_class?
414+
if klass && klass < ActiveRecord::Base && !klass.abstract_class? && klass.table_exists?
415415
if annotate(klass, file, header, options)
416416
annotated << klass
417417
end

spec/annotate/annotate_models_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,20 @@ class User < ActiveRecord::Base
461461
end
462462
end
463463
end
464+
465+
describe '.annotate_model_file' do
466+
before do
467+
class Foo < ActiveRecord::Base; end;
468+
AnnotateModels.stub(:get_model_class).with('foo.rb') { Foo }
469+
Foo.stub(:table_exists?) { false }
470+
end
471+
472+
after { Object.send :remove_const, 'Foo' }
473+
474+
it 'skips attempt to annotate if no table exists for model' do
475+
annotate_model_file = AnnotateModels.annotate_model_file([], 'foo.rb', nil, nil)
476+
477+
annotate_model_file.should eq nil
478+
end
479+
end
464480
end

0 commit comments

Comments
 (0)