Added that fixtures to placed in subdirectories of the main fixture files are...

Added that fixtures to placed in subdirectories of the main fixture files are also loaded (closes #3937) [dblack@wobblini.net]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3683 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 adccb319
*SVN*
* Added that fixtures to placed in subdirectories of the main fixture files are also loaded #3937 [dblack@wobblini.net]
* Define attribute query methods to avoid method_missing calls. #3677 [jonathan@bluewire.net.nz]
* ActiveRecord::Base.remove_connection explicitly closes database connections and doesn't corrupt the connection cache. Introducing the disconnect! instance method for the PostgreSQL, MySQL, and SQL Server adapters; implementations for the others are welcome. #3591 [Simon Stapleton, Tom Ward]
......
......@@ -286,11 +286,18 @@ def insert_fixtures
end
private
def read_fixture_files
if File.file?(yaml_file_path)
# YAML fixtures
begin
if yaml = YAML::load(erb_render(IO.read(yaml_file_path)))
yaml_string = ""
Dir["#{@fixture_path}/**/*"].select {|f| test(?f,f) }.each do |subfixture_path|
yaml_string << IO.read(subfixture_path)
end
yaml_string << IO.read(yaml_file_path)
if yaml = YAML::load(erb_render(yaml_string))
yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value)
yaml.each do |name, data|
self[name] = Fixture.new(data, @class_name)
......
......@@ -9,7 +9,7 @@ class FixturesTest < Test::Unit::TestCase
self.use_instantiated_fixtures = true
self.use_transactional_fixtures = false
fixtures :topics, :developers, :accounts, :tasks
fixtures :topics, :developers, :accounts, :tasks, :categories
FIXTURES = %w( accounts companies customers
developers developers_projects entrants
......@@ -170,6 +170,23 @@ def test_omap_fixtures
end
end
end
def test_non_yml_file_in_subdirectory
assert_equal(categories(:sub_special_1).name, "A special category")
assert_equal(categories(:sub_special_1).class, SpecialCategory)
end
def test_yml_file_in_subdirectory
assert_equal(categories(:sub_special_3).name, "A special category in a .yml file")
assert_equal(categories(:sub_special_3).class, SpecialCategory)
end
def test_subsubdir_file_with_arbitrary_name
assert_equal(categories(:sub_special_5).name, "A special category in an arbitrarily named subsubdir file")
assert_equal(categories(:sub_special_5).class, SpecialCategory)
end
end
if Account.connection.respond_to?(:reset_pk_sequence!)
......
......@@ -295,7 +295,7 @@ def test_forwarding_of_static_methods
end
def test_forwarding_to_dynamic_finders
assert_equal 1, Category.find_all_by_type('SpecialCategory').size
assert_equal 6, Category.find_all_by_type('SpecialCategory').size
assert_equal 0, @welcome.categories.find_all_by_type('SpecialCategory').size
assert_equal 2, @welcome.categories.find_all_by_type('Category').size
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册