Fix incorrect serializing of collection inputs, i.e. name contains []

This commit is contained in:
Kamal Fariz Mahyuddin 2008-03-19 16:25:29 +08:00 committed by Bryan Helmkamp
parent 7ee7bae757
commit 6861f3abf2
2 changed files with 18 additions and 4 deletions

View File

@ -301,10 +301,10 @@ module ActionController
form_data[form_number] ||= {}
data.each do |key, value|
if form_data[form_number][key].is_a?(Hash)
merge(form_data[form_number][key], value)
else
form_data[form_number][key] = value
case form_data[form_number][key]
when Hash; then merge(form_data[form_number][key], value)
when Array; then form_data[form_number][key] = (form_data[form_number][key] | value).sort
else form_data[form_number][key] = value
end
end
end

View File

@ -197,6 +197,20 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.clicks_button
end
def test_should_send_default_collection_fields
@response.stubs(:body).returns(<<-EOS)
<form method="post" action="/login">
<input type="checkbox" name="options[]" value="burger" checked="checked" />
<input type="radio" name="options[]" value="fries" checked="checked" />
<input type="text" name="options[]" value="soda" />
<input type="hidden" name="options[]" value="dessert" />
<input type="submit" />
</form>
EOS
@session.expects(:post_via_redirect).with("/login", "options" => ["burger", "dessert", "fries", "soda"])
@session.clicks_button
end
def test_should_not_send_default_unchecked_fields
@response.stubs(:body).returns(<<-EOS)
<form method="get" action="/login">