Skip to content
This repository
Browse code

Merge [6360] from trunk. Fixes YAML Omap fixtures. References #2665.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@6361 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 243cdde6a849b3051739fd8824e4c62df6bd761a 1 parent a9ed24c
Jeremy Kemper authored
2  activerecord/CHANGELOG
... ...
@@ -1,5 +1,7 @@
1 1
 *SVN*
2 2
 
  3
+* Fixtures: fix YAML ordered map support.  #2665 [Manuel Holtgrewe, nfbuckley]
  4
+
3 5
 * Fix has_many :through << with custom foreign keys.  #6466, #7153 [naffis, Rich Collins]
4 6
 
5 7
 
24  activerecord/lib/active_record/fixtures.rb
@@ -301,18 +301,30 @@ def read_fixture_files
301 301
           yaml_string << IO.read(subfixture_path)
302 302
         end
303 303
         yaml_string << IO.read(yaml_file_path)
  304
+
304 305
         begin
305 306
           yaml = YAML::load(erb_render(yaml_string))
306 307
         rescue Exception=>boom
307 308
           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  #{boom.class}: #{boom}"
308  
-        end         
  309
+        end
  310
+
309 311
         if yaml
310  
-          yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value)
311  
-          yaml.each do |name, data|
312  
-            unless data
313  
-              raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
  312
+          # If the file is an ordered map, extract its children.
  313
+          yaml_value =
  314
+            if yaml.respond_to?(:type_id) && yaml.respond_to?(:value)
  315
+              yaml.value
  316
+            else
  317
+              [yaml]
  318
+            end
  319
+
  320
+          yaml_value.each do |fixture|
  321
+            fixture.each do |name, data|
  322
+              unless data
  323
+                raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
  324
+              end
  325
+
  326
+              self[name] = Fixture.new(data, @class_name)
314 327
             end
315  
-            self[name] = Fixture.new(data, @class_name)
316 328
           end
317 329
         end
318 330
       elsif File.file?(csv_file_path)
2  activerecord/test/fixtures/categories_ordered.yml
... ...
@@ -1,4 +1,4 @@
1  
---- !omap
  1
+--- !!omap
2 2
 <% 100.times do |i| %>
3 3
 - fixture_no_<%= i %>:
4 4
     id: <%= i %>

0 notes on commit 243cdde

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