1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fixtures: fix YAML ordered map support. Closes #2665.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6360 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2007-03-09 02:06:50 +00:00
parent 866cba7bb7
commit 49d1f6a813
3 changed files with 21 additions and 7 deletions

View file

@ -1,5 +1,7 @@
*SVN* *SVN*
* Fixtures: fix YAML ordered map support. #2665 [Manuel Holtgrewe, nfbuckley]
* DateTimes assume the default timezone. #7764 [Geoff Buesing] * DateTimes assume the default timezone. #7764 [Geoff Buesing]
* Sybase: hide timestamp columns since they're inherently read-only. #7716 [Mike Joyce] * Sybase: hide timestamp columns since they're inherently read-only. #7716 [Mike Joyce]

View file

@ -304,18 +304,30 @@ class Fixtures < YAML::Omap
yaml_string << IO.read(subfixture_path) yaml_string << IO.read(subfixture_path)
end end
yaml_string << IO.read(yaml_file_path) yaml_string << IO.read(yaml_file_path)
begin begin
yaml = YAML::load(erb_render(yaml_string)) yaml = YAML::load(erb_render(yaml_string))
rescue Exception=>boom 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}" 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 if yaml
yaml = yaml.value if yaml.respond_to?(:type_id) and yaml.respond_to?(:value) # If the file is an ordered map, extract its children.
yaml.each do |name, data| yaml_value =
unless data if yaml.respond_to?(:type_id) && yaml.respond_to?(:value)
raise Fixture::FormatError, "Bad data for #{@class_name} fixture named #{name} (nil)" 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 end
self[name] = Fixture.new(data, @class_name)
end end
end end
elsif File.file?(csv_file_path) elsif File.file?(csv_file_path)

View file

@ -1,4 +1,4 @@
--- !omap --- !!omap
<% 100.times do |i| %> <% 100.times do |i| %>
- fixture_no_<%= i %>: - fixture_no_<%= i %>:
id: <%= i %> id: <%= i %>