diff --git a/spec/support/unit/helpers/class_builder.rb b/spec/support/unit/helpers/class_builder.rb index fff1290c..bcea6d1e 100644 --- a/spec/support/unit/helpers/class_builder.rb +++ b/spec/support/unit/helpers/class_builder.rb @@ -60,10 +60,6 @@ module UnitTests if block_given? constant.class_eval(&block) end - - if constant.respond_to?(:reset_column_information) - constant.reset_column_information - end end end @@ -72,9 +68,5 @@ module UnitTests def teardown_defined_constants ActiveSupport::Dependencies.clear end - - def teardown_defined_constants - ActiveSupport::Dependencies.clear - end end end diff --git a/spec/support/unit/helpers/model_builder.rb b/spec/support/unit/helpers/model_builder.rb index fb2d2a5d..643259e1 100644 --- a/spec/support/unit/helpers/model_builder.rb +++ b/spec/support/unit/helpers/model_builder.rb @@ -8,6 +8,7 @@ module UnitTests example_group.include(self) example_group.after do + clear_column_caches drop_created_tables end end @@ -76,6 +77,18 @@ module UnitTests private + def clear_column_caches + # Rails 3.1 - 4.0 + if ActiveRecord::Base.connection_pool.respond_to?(:clear_cache!) + ActiveRecord::Base.connection_pool.clear_cache! + end + + # Rails 4.x + if ActiveRecord::Base.connection.respond_to?(:schema_cache) + ActiveRecord::Base.connection.schema_cache.clear! + end + end + def drop_created_tables connection = ActiveRecord::Base.connection