Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

return an empty array for empty yaml files

  • Loading branch information...
commit 5278af3d8efbe348864baca0c40a532e8b137ce1 1 parent 74c5f65
@tenderlove tenderlove authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.