Commit f5099413 by Cuong Tran

Merge pull request #126 from davejachimiak/dj-attempt_only_if_table_exists

Attempt model annotation only if table exists
parents e91eb1e0 a10fa782
...@@ -411,7 +411,7 @@ module AnnotateModels ...@@ -411,7 +411,7 @@ module AnnotateModels
def annotate_model_file(annotated, file, header, options) def annotate_model_file(annotated, file, header, options)
begin begin
klass = get_model_class(file) klass = get_model_class(file)
if klass && klass < ActiveRecord::Base && !klass.abstract_class? if klass && klass < ActiveRecord::Base && !klass.abstract_class? && klass.table_exists?
if annotate(klass, file, header, options) if annotate(klass, file, header, options)
annotated << klass annotated << klass
end end
......
...@@ -461,4 +461,20 @@ end ...@@ -461,4 +461,20 @@ end
end end
end end
end end
describe '.annotate_model_file' do
before do
class Foo < ActiveRecord::Base; end;
AnnotateModels.stub(:get_model_class).with('foo.rb') { Foo }
Foo.stub(:table_exists?) { false }
end
after { Object.send :remove_const, 'Foo' }
it 'skips attempt to annotate if no table exists for model' do
annotate_model_file = AnnotateModels.annotate_model_file([], 'foo.rb', nil, nil)
annotate_model_file.should eq nil
end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment