diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-10 10:31:52 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-23 15:06:12 -0700 |
commit | 5278af3d8efbe348864baca0c40a532e8b137ce1 (patch) | |
tree | 8c81aecb755492b011b461e2dd7fa721c5cd7e34 | |
parent | 74c5f65bfb7813cecb3a1e78b522de4586e76ac9 (diff) | |
download | rails-5278af3d8efbe348864baca0c40a532e8b137ce1.tar.gz rails-5278af3d8efbe348864baca0c40a532e8b137ce1.tar.bz2 rails-5278af3d8efbe348864baca0c40a532e8b137ce1.zip |
return an empty array for empty yaml files
-rw-r--r-- | activerecord/lib/active_record/fixtures/file.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/fixtures/file_test.rb | 17 |
2 files changed, 20 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/fixtures/file.rb b/activerecord/lib/active_record/fixtures/file.rb index 9e95007f40..beda5a65df 100644 --- a/activerecord/lib/active_record/fixtures/file.rb +++ b/activerecord/lib/active_record/fixtures/file.rb @@ -32,7 +32,9 @@ module ActiveRecord private def rows return @rows if @rows - @rows = YAML.load(render(IO.read(@file))).to_a + + data = YAML.load(render(IO.read(@file))) + @rows = data ? data.to_a : [] end def render(content) diff --git a/activerecord/test/cases/fixtures/file_test.rb b/activerecord/test/cases/fixtures/file_test.rb index af7a2e5a4e..38494a7857 100644 --- a/activerecord/test/cases/fixtures/file_test.rb +++ b/activerecord/test/cases/fixtures/file_test.rb @@ -41,6 +41,23 @@ module ActiveRecord assert_equal [], devs - fh.to_a.map(&:first) end end + + def test_empty_file + tmp_yaml ['empty', 'yml'], '' do |t| + assert_equal [], File.open(t.path) { |fh| fh.to_a } + end + end + + private + def tmp_yaml(name, contents) + t = Tempfile.new name + t.binmode + t.write contents + t.close + yield t + ensure + t.close true + end end end end |