diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 66c7feee48..260c3f97b1 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -217,19 +217,16 @@ class Fixtures < YAML::Omap DEFAULT_FILTER_RE = /\.ya?ml$/ def self.instantiate_fixtures(object, table_name, fixtures, load_instances=true) - old_logger_level = ActiveRecord::Base.logger.level - ActiveRecord::Base.logger.level = Logger::ERROR - object.instance_variable_set "@#{table_name.to_s.gsub('.','_')}", fixtures if load_instances - fixtures.each do |name, fixture| - if model = fixture.find - object.instance_variable_set "@#{name}", model + ActiveRecord::Base.logger.silence do + fixtures.each do |name, fixture| + if model = fixture.find + object.instance_variable_set "@#{name}", model + end end end end - - ActiveRecord::Base.logger.level = old_logger_level end def self.instantiate_all_loaded_fixtures(object, load_instances=true) @@ -558,7 +555,7 @@ module Test #:nodoc: def reload_fixtures! # Clear dirty fixtures and loaded fixtures which were not declared # for this test case. - wipe = dirty_fixture_table_names + loaded_fixture_table_names - fixture_table_names + wipe = dirty_fixture_table_names | loaded_fixture_table_names - fixture_table_names Fixtures.delete_fixtures(wipe) unless wipe.empty? dirty_fixture_table_names.clear loaded_fixture_table_names.clear @@ -573,6 +570,8 @@ module Test #:nodoc: @loaded_fixtures[f.table_name] = f f.table_name.to_s } + else + @loaded_fixtures = {} end end diff --git a/activerecord/test/fixtures_test.rb b/activerecord/test/fixtures_test.rb index ef931ea873..b5e49999f4 100755 --- a/activerecord/test/fixtures_test.rb +++ b/activerecord/test/fixtures_test.rb @@ -329,3 +329,44 @@ class FixtureCleanup4Test < FixtureCleanup2Test assert_equal %w(developers), fixture_table_names end end + +class FixtureCleanup5Test < FixtureCleanup3Test + self.use_instantiated_fixtures = false + + def test_dirty_fixture_table_names + assert_equal %w(developers), dirty_fixture_table_names + assert_equal %w(developers), loaded_fixture_table_names + assert_equal %w(developers), fixture_table_names + end +end + +class FixtureCleanup6Test < FixtureCleanup4Test + self.use_instantiated_fixtures = true + + def test_dirty_fixture_table_names + assert_equal [], dirty_fixture_table_names + assert_equal %w(developers), loaded_fixture_table_names + assert_equal %w(developers), fixture_table_names + end +end + +class FixtureCleanup7Test < Test::Unit::TestCase + self.use_transactional_fixtures = false + self.use_instantiated_fixtures = true + + def test_dirty_fixture_table_names + assert_equal [], dirty_fixture_table_names + assert_equal [], loaded_fixture_table_names + assert_equal [], fixture_table_names + end + + def test_isolation + assert_equal 0, Topic.count + assert_equal 0, Developer.count + end +end + +class FixtureCleanup8Test < FixtureCleanup7Test + self.use_transactional_fixtures = true + self.use_instantiated_fixtures = true +end