Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
don't depend on object state when reading fixture files
  • Loading branch information
tenderlove committed Sep 6, 2013
1 parent 7a05455 commit 97a19c6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions activerecord/lib/active_record/fixtures.rb
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 97a19c6

Please sign in to comment.