Skip to content
Browse files

return an empty array for empty yaml files

  • Loading branch information...
1 parent 74c5f65 commit 5278af3d8efbe348864baca0c40a532e8b137ce1 @tenderlove tenderlove committed May 10, 2011
Showing with 20 additions and 1 deletion.
  1. +3 −1 activerecord/lib/active_record/fixtures/file.rb
  2. +17 −0 activerecord/test/cases/fixtures/file_test.rb
View
4 activerecord/lib/active_record/fixtures/file.rb
@@ -32,7 +32,9 @@ def each(&block)
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)
View
17 activerecord/test/cases/fixtures/file_test.rb
@@ -41,6 +41,23 @@ def test_erb_processing
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

0 comments on commit 5278af3

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