1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
Jeremy Kemper 2005-10-24 16:45:33 +00:00
parent 0e4c5b0288
commit f57ba4cc52
2 changed files with 49 additions and 9 deletions

View file

@ -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
ActiveRecord::Base.logger.silence do
fixtures.each do |name, fixture|
if model = fixture.find
object.instance_variable_set "@#{name}", model
end
end
end
ActiveRecord::Base.logger.level = old_logger_level
end
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

View file

@ -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