提交 97a19c6b 编写于 作者: A Aaron Patterson

don't depend on object state when reading fixture files

上级 7a05455a
......@@ -528,7 +528,6 @@ def self.identify(label)
attr_reader :table_name, :name, :fixtures, :model_class, :config
def initialize(connection, name, class_name, path, config = ActiveRecord::Base)
@fixtures = {} # Ordered hash
@name = name
@path = path
@config = config
......@@ -550,7 +549,7 @@ def initialize(connection, name, class_name, path, config = ActiveRecord::Base)
model_class.table_name :
self.class.default_fixture_table_name(name, config) )
read_fixture_files
@fixtures = read_fixture_files path, @model_class
end
def [](x)
......@@ -670,12 +669,12 @@ def column_names
@column_names ||= @connection.columns(@table_name).collect { |c| c.name }
end
def read_fixture_files
yaml_files = Dir["#{@path}/{**,*}/*.yml"].select { |f|
def read_fixture_files(path, model_class)
yaml_files = Dir["#{path}/{**,*}/*.yml"].select { |f|
::File.file?(f)
} + [yaml_file_path]
} + [yaml_file_path(path)]
yaml_files.each do |file|
yaml_files.each_with_object({}) do |file, fixtures|
FixtureSet::File.open(file) do |fh|
fh.each do |fixture_name, row|
fixtures[fixture_name] = ActiveRecord::Fixture.new(row, model_class)
......@@ -684,8 +683,8 @@ def read_fixture_files
end
end
def yaml_file_path
"#{@path}.yml"
def yaml_file_path(path)
"#{path}.yml"
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册