Skip to content

Commit

Permalink
Merge [6360] from trunk. Fixes YAML Omap fixtures. References #2665.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-stable@6361 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Mar 9, 2007
1 parent a9ed24c commit 243cdde
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* Fixtures: fix YAML ordered map support. #2665 [Manuel Holtgrewe, nfbuckley]

* Fix has_many :through << with custom foreign keys. #6466, #7153 [naffis, Rich Collins]


Expand Down
24 changes: 18 additions & 6 deletions activerecord/lib/active_record/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,18 +301,30 @@ def read_fixture_files
yaml_string << IO.read(subfixture_path)
end
yaml_string << IO.read(yaml_file_path)

begin
yaml = YAML::load(erb_render(yaml_string))
rescue Exception=>boom
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}"
end
end

if yaml
yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value)
yaml.each do |name, data|
unless data
raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
# 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|
fixture.each do |name, data|
unless data
raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)"
end

self[name] = Fixture.new(data, @class_name)
end
self[name] = Fixture.new(data, @class_name)
end
end
elsif File.file?(csv_file_path)
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/fixtures/categories_ordered.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
--- !omap
--- !!omap
<% 100.times do |i| %>
- fixture_no_<%= i %>:
id: <%= i %>
Expand Down

0 comments on commit 243cdde

Please sign in to comment.