Skip to content

Treat table_exists? exceptions as an indication that the table does not exist #19

Merged
merged 3 commits into from Dec 7, 2011
View
2 lib/attribute_normalizer/model_inclusions.rb
@@ -62,7 +62,7 @@ def normalize_default_attributes
def inherited(subclass)
super
- if subclass.respond_to?(:table_exists?) && subclass.table_exists?
+ if subclass.respond_to?(:table_exists?) && (subclass.table_exists? rescue false)
subclass.normalize_default_attributes
end
end
View
12 spec/attribute_normalizer_spec.rb
@@ -11,4 +11,16 @@
klass.should respond_to(:normalize_attribute)
end
+ it 'should not fail due to database exceptions raised by table_exists?' do
+ class PGError < RuntimeError; end
+
+ Class.new(ActiveRecord::Base) do
+ def self.table_exists?
+ raise PGError, "FATAL: something bad happened trying to probe for table existence"
+ end
+
+ include AttributeNormalizer
+ end
+
+ end
end
Something went wrong with that request. Please try again.