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] ||= {} 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

View File

@ -196,6 +196,20 @@ class ClicksButtonTest < Test::Unit::TestCase
@session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "1"}) @session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "1"})
@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)