Fix incorrect serializing of collection inputs, i.e. name contains []
This commit is contained in:
parent
7ee7bae757
commit
6861f3abf2
|
@ -301,10 +301,10 @@ module ActionController
|
||||||
form_data[form_number] ||= {}
|
form_data[form_number] ||= {}
|
||||||
|
|
||||||
data.each do |key, value|
|
data.each do |key, value|
|
||||||
if form_data[form_number][key].is_a?(Hash)
|
case form_data[form_number][key]
|
||||||
merge(form_data[form_number][key], value)
|
when Hash; then merge(form_data[form_number][key], value)
|
||||||
else
|
when Array; then form_data[form_number][key] = (form_data[form_number][key] | value).sort
|
||||||
form_data[form_number][key] = value
|
else form_data[form_number][key] = value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -197,6 +197,20 @@ class ClicksButtonTest < Test::Unit::TestCase
|
||||||
@session.clicks_button
|
@session.clicks_button
|
||||||
end
|
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
|
def test_should_not_send_default_unchecked_fields
|
||||||
@response.stubs(:body).returns(<<-EOS)
|
@response.stubs(:body).returns(<<-EOS)
|
||||||
<form method="get" action="/login">
|
<form method="get" action="/login">
|
||||||
|
|
Loading…
Reference in New Issue