Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removing CSV fixture support

  • Loading branch information...
commit 1716da07204193c8acf967e2d75a53a82e4c7c28 1 parent 081b36c
@tenderlove tenderlove authored
View
62 activerecord/lib/active_record/fixtures.rb
@@ -6,7 +6,6 @@
end
require 'yaml'
-require 'csv'
require 'zlib'
require 'active_support/dependencies'
require 'active_support/core_ext/array/wrap'
@@ -658,73 +657,32 @@ def column_names
def read_fixture_files
if ::File.file?(yaml_file_path)
read_yaml_fixture_files
- elsif ::File.file?(csv_file_path)
- read_csv_fixture_files
else
- raise FixturesFileNotFound, "Could not find #{yaml_file_path} or #{csv_file_path}"
+ raise FixturesFileNotFound, "Could not find #{yaml_file_path}"
end
end
def read_yaml_fixture_files
- yaml_string = (Dir["#{@fixture_path}/**/*.yml"].select { |f|
- File.file?(f)
- } + [yaml_file_path]).map { |file_path| IO.read(file_path) }.join
-
- if yaml = parse_yaml_string(yaml_string)
- # If the file is an ordered map, extract its children.
- yaml_value =
- if yaml.respond_to?(:type_id) && yaml.respond_to?(:value)
- yaml.value
- else
- [yaml]
- end
-
- yaml_value.each do |fixture|
- raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{fixture}" unless fixture.respond_to?(:each)
- fixture.each do |name, data|
- unless data
- raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
- end
-
- fixtures[name] = ActiveRecord::Fixture.new(data, model_class)
+ yaml_files = Dir["#{@fixture_path}/**/*.yml"].select { |f|
+ ::File.file?(f)
+ } + [yaml_file_path]
+
+ yaml_files.each do |file|
+ Fixtures::File.open(file) do |fh|
+ fh.each do |name, row|
+ fixtures[name] = ActiveRecord::Fixture.new(row, model_class)
end
end
end
end
- def read_csv_fixture_files
- reader = CSV.parse(erb_render(IO.read(csv_file_path)))
- header = reader.shift
- i = 0
- reader.each do |row|
- data = {}
- row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
- fixtures["#{@class_name.to_s.underscore}_#{i+=1}"] = ActiveRecord::Fixture.new(data, model_class)
- end
- end
- deprecate :read_csv_fixture_files
-
def yaml_file_path
"#{@fixture_path}.yml"
end
- def csv_file_path
- @fixture_path + ".csv"
- end
-
def yaml_fixtures_key(path)
::File.basename(@fixture_path).split(".").first
end
-
- def parse_yaml_string(fixture_content)
- YAML::load(erb_render(fixture_content))
- rescue => error
- raise Fixture::FormatError, "a YAML error occurred parsing #{yaml_file_path}. Please note that YAML must be consistently indented using spaces. Tabs are not allowed. Please have a look at http://www.yaml.org/faq.html\nThe exact error was:\n #{error.class}: #{error}"
- end
-
- def erb_render(fixture_content)
- ERB.new(fixture_content).result
- end
end
class Fixture #:nodoc:
@@ -799,7 +757,7 @@ def set_fixture_class(class_names = {})
def fixtures(*fixture_names)
if fixture_names.first == :all
- fixture_names = Dir["#{fixture_path}/**/*.{yml,csv}"]
+ fixture_names = Dir["#{fixture_path}/**/*.{yml}"]
fixture_names.map! { |f| f[(fixture_path.size + 1)..-5] }
else
fixture_names = fixture_names.flatten.map { |n| n.to_s }
View
6 activerecord/test/cases/fixtures_test.rb
@@ -174,12 +174,6 @@ def test_dirty_dirty_yaml_file
end
end
- def test_empty_csv_fixtures
- assert_deprecated do
- assert_not_nil ActiveRecord::Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/csv/accounts")
- end
- end
-
def test_omap_fixtures
assert_nothing_raised do
fixtures = ActiveRecord::Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")

3 comments on commit 1716da0

@spovich

For long lists like states, counties, etc, I find csv much more palatable than yaml. Is yaml going to be the only fixture format? If so, count me as a -1 on this.

@bfolkens

I extracted a simple plugin over at https://github.com/bfolkens/rails-csv-fixtures if you need the functionality still.

@dewrich

I agree .csv data importing is much more palatable when working with the "business people" as well.

Please sign in to comment.
Something went wrong with that request. Please try again.