Permalink
Browse files

don't depend on object state when reading fixture files

  • Loading branch information...
1 parent 7a05455 commit 97a19c6b4b71d1e12d62d880ec8c8eed357b3d3c @tenderlove tenderlove committed Sep 6, 2013
Showing with 7 additions and 8 deletions.
  1. +7 −8 activerecord/lib/active_record/fixtures.rb
@@ -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

0 comments on commit 97a19c6

Please sign in to comment.