aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-10-24 16:45:33 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-10-24 16:45:33 +0000
commitf57ba4cc5237b408e23715ab6c7d700bd8e125b0 (patch)
tree0ff766a1adef059bfc417c93441d1a134a1d9735 /activerecord
parent0e4c5b0288c3fab5ec8bdc4d7448be2b72e55e58 (diff)
downloadrails-f57ba4cc5237b408e23715ab6c7d700bd8e125b0.tar.gz
rails-f57ba4cc5237b408e23715ab6c7d700bd8e125b0.tar.bz2
rails-f57ba4cc5237b408e23715ab6c7d700bd8e125b0.zip
r2727@asus: jeremy | 2005-10-24 14:14:36 -0700
Fallback to @loaded_fixtures = {}. Use Logger#silence. Test fixture isolation with use_instantiated_fixtures and with no fixtures declaration. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rwxr-xr-xactiverecord/lib/active_record/fixtures.rb17
-rwxr-xr-xactiverecord/test/fixtures_test.rb41
2 files changed, 49 insertions, 9 deletions
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