From 6861f3abf26f4098d3225e7c94ff52174b283446 Mon Sep 17 00:00:00 2001 From: Kamal Fariz Mahyuddin Date: Wed, 19 Mar 2008 16:25:29 +0800 Subject: [PATCH] Fix incorrect serializing of collection inputs, i.e. name contains [] --- lib/webrat/session.rb | 8 ++++---- test/clicks_button_test.rb | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/webrat/session.rb b/lib/webrat/session.rb index 0a8168f..ae93209 100644 --- a/lib/webrat/session.rb +++ b/lib/webrat/session.rb @@ -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 diff --git a/test/clicks_button_test.rb b/test/clicks_button_test.rb index ec529ff..c8d5274 100644 --- a/test/clicks_button_test.rb +++ b/test/clicks_button_test.rb @@ -196,6 +196,20 @@ class ClicksButtonTest < Test::Unit::TestCase @session.expects(:get_via_redirect).with("/login", "user" => {"tos" => "1"}) @session.clicks_button end + + def test_should_send_default_collection_fields + @response.stubs(:body).returns(<<-EOS) +
+ + + + + +
+ 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)