Skip to content
This repository
Browse code

removing CSV fixture support

  • Loading branch information...
commit 1716da07204193c8acf967e2d75a53a82e4c7c28 1 parent 081b36c
Aaron Patterson authored May 10, 2011
62  activerecord/lib/active_record/fixtures.rb
@@ -6,7 +6,6 @@
6 6
 end
7 7
 
8 8
 require 'yaml'
9  
-require 'csv'
10 9
 require 'zlib'
11 10
 require 'active_support/dependencies'
12 11
 require 'active_support/core_ext/array/wrap'
@@ -658,73 +657,32 @@ def column_names
658 657
       def read_fixture_files
659 658
         if ::File.file?(yaml_file_path)
660 659
           read_yaml_fixture_files
661  
-        elsif ::File.file?(csv_file_path)
662  
-          read_csv_fixture_files
663 660
         else
664  
-          raise FixturesFileNotFound, "Could not find #{yaml_file_path} or #{csv_file_path}"
  661
+          raise FixturesFileNotFound, "Could not find #{yaml_file_path}"
665 662
         end
666 663
       end
667 664
 
668 665
       def read_yaml_fixture_files
669  
-        yaml_string = (Dir["#{@fixture_path}/**/*.yml"].select { |f|
670  
-          File.file?(f)
671  
-        } + [yaml_file_path]).map { |file_path| IO.read(file_path) }.join
672  
-
673  
-        if yaml = parse_yaml_string(yaml_string)
674  
-          # If the file is an ordered map, extract its children.
675  
-          yaml_value =
676  
-            if yaml.respond_to?(:type_id) && yaml.respond_to?(:value)
677  
-              yaml.value
678  
-            else
679  
-              [yaml]
680  
-            end
681  
-
682  
-          yaml_value.each do |fixture|
683  
-            raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{fixture}" unless fixture.respond_to?(:each)
684  
-            fixture.each do |name, data|
685  
-              unless data
686  
-                raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
687  
-              end
688  
-
689  
-              fixtures[name] = ActiveRecord::Fixture.new(data, model_class)
  666
+        yaml_files = Dir["#{@fixture_path}/**/*.yml"].select { |f|
  667
+          ::File.file?(f)
  668
+        } + [yaml_file_path]
  669
+
  670
+        yaml_files.each do |file|
  671
+          Fixtures::File.open(file) do |fh|
  672
+            fh.each do |name, row|
  673
+              fixtures[name] = ActiveRecord::Fixture.new(row, model_class)
690 674
             end
691 675
           end
692 676
         end
693 677
       end
694 678
 
695  
-      def read_csv_fixture_files
696  
-        reader = CSV.parse(erb_render(IO.read(csv_file_path)))
697  
-        header = reader.shift
698  
-        i = 0
699  
-        reader.each do |row|
700  
-          data = {}
701  
-          row.each_with_index { |cell, j| data[header[j].to_s.strip] = cell.to_s.strip }
702  
-          fixtures["#{@class_name.to_s.underscore}_#{i+=1}"] = ActiveRecord::Fixture.new(data, model_class)
703  
-        end
704  
-      end
705  
-      deprecate :read_csv_fixture_files
706  
-
707 679
       def yaml_file_path
708 680
         "#{@fixture_path}.yml"
709 681
       end
710 682
 
711  
-      def csv_file_path
712  
-        @fixture_path + ".csv"
713  
-      end
714  
-
715 683
       def yaml_fixtures_key(path)
716 684
         ::File.basename(@fixture_path).split(".").first
717 685
       end
718  
-
719  
-      def parse_yaml_string(fixture_content)
720  
-        YAML::load(erb_render(fixture_content))
721  
-      rescue => error
722  
-        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}"
723  
-      end
724  
-
725  
-      def erb_render(fixture_content)
726  
-        ERB.new(fixture_content).result
727  
-      end
728 686
   end
729 687
 
730 688
   class Fixture #:nodoc:
@@ -799,7 +757,7 @@ def set_fixture_class(class_names = {})
799 757
 
800 758
       def fixtures(*fixture_names)
801 759
         if fixture_names.first == :all
802  
-          fixture_names = Dir["#{fixture_path}/**/*.{yml,csv}"]
  760
+          fixture_names = Dir["#{fixture_path}/**/*.{yml}"]
803 761
           fixture_names.map! { |f| f[(fixture_path.size + 1)..-5] }
804 762
         else
805 763
           fixture_names = fixture_names.flatten.map { |n| n.to_s }
6  activerecord/test/cases/fixtures_test.rb
@@ -174,12 +174,6 @@ def test_dirty_dirty_yaml_file
174 174
     end
175 175
   end
176 176
 
177  
-  def test_empty_csv_fixtures
178  
-    assert_deprecated do
179  
-      assert_not_nil ActiveRecord::Fixtures.new( Account.connection, "accounts", 'Account', FIXTURES_ROOT + "/naked/csv/accounts")
180  
-    end
181  
-  end
182  
-
183 177
   def test_omap_fixtures
184 178
     assert_nothing_raised do
185 179
       fixtures = ActiveRecord::Fixtures.new(Account.connection, 'categories', 'Category', FIXTURES_ROOT + "/categories_ordered")

3 notes on commit 1716da0

John Dell

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.

Brad Folkens

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

Dewayne Richardson

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.