diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-09 02:06:50 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-09 02:06:50 +0000 |
commit | 49d1f6a813c2791f150611df1229593306796871 (patch) | |
tree | 62ade93667ad62407b36e59be516f2fab59d6dc2 | |
parent | 866cba7bb73dcd9d9ae60e8163655295d825dc58 (diff) | |
download | rails-49d1f6a813c2791f150611df1229593306796871.tar.gz rails-49d1f6a813c2791f150611df1229593306796871.tar.bz2 rails-49d1f6a813c2791f150611df1229593306796871.zip |
Fixtures: fix YAML ordered map support. Closes #2665.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6360 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/fixtures.rb | 24 | ||||
-rw-r--r-- | activerecord/test/fixtures/categories_ordered.yml | 2 |
3 files changed, 21 insertions, 7 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index c4020762dd..1b961e0c1f 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixtures: fix YAML ordered map support. #2665 [Manuel Holtgrewe, nfbuckley] + * DateTimes assume the default timezone. #7764 [Geoff Buesing] * Sybase: hide timestamp columns since they're inherently read-only. #7716 [Mike Joyce] diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 2fe89aac16..96fd0c57af 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -304,18 +304,30 @@ class Fixtures < YAML::Omap 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) diff --git a/activerecord/test/fixtures/categories_ordered.yml b/activerecord/test/fixtures/categories_ordered.yml index 294a6368d6..2afc6cb5a9 100644 --- a/activerecord/test/fixtures/categories_ordered.yml +++ b/activerecord/test/fixtures/categories_ordered.yml @@ -1,4 +1,4 @@ ---- !omap +--- !!omap <% 100.times do |i| %> - fixture_no_<%= i %>: id: <%= i %> |