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

Merge pull request #7314 from schneems/schneems/form_for_error

Check for Blank Record in form_for
This commit is contained in:
Rafael Mendonça França 2012-08-10 20:09:21 -07:00
commit a6e0d8cfcf
2 changed files with 15 additions and 0 deletions

View file

@ -423,6 +423,7 @@ module ActionView
object = nil
else
object = record.is_a?(Array) ? record.last : record
raise ArgumentError, "First argument in form cannot contain nil or be empty" if object.blank?
object_name = options[:as] || model_name_from_record_or_class(object).param_key
apply_form_for_options!(record, object, options)
end

View file

@ -1045,6 +1045,20 @@ class FormHelperTest < ActionView::TestCase
end
end
def test_form_for_requires_arguments
error = assert_raises(ArgumentError) do
form_for(nil, :html => { :id => 'create-post' }) do
end
end
assert_equal "First argument in form cannot contain nil or be empty", error.message
error = assert_raises(ArgumentError) do
form_for([nil, nil], :html => { :id => 'create-post' }) do
end
end
assert_equal "First argument in form cannot contain nil or be empty", error.message
end
def test_form_for
form_for(@post, :html => { :id => 'create-post' }) do |f|
concat f.label(:title) { "The Title" }