diff options
author | Jamis Buck <jamis@37signals.com> | 2006-03-15 21:46:41 +0000 |
---|---|---|
committer | Jamis Buck <jamis@37signals.com> | 2006-03-15 21:46:41 +0000 |
commit | 2429074075b08b219f4dbbe8f6d08598c1d67878 (patch) | |
tree | ef5fd183f7e5a17fe8de9d613b4bc0be325454c3 /actionpack/test/controller | |
parent | 6c95e9b14697a9527ab761d1a084f6bc61af56b9 (diff) | |
download | rails-2429074075b08b219f4dbbe8f6d08598c1d67878.tar.gz rails-2429074075b08b219f4dbbe8f6d08598c1d67878.tar.bz2 rails-2429074075b08b219f4dbbe8f6d08598c1d67878.zip |
Underscore dasherized keys in formatted requests
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3878 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/webservice_test.rb | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/actionpack/test/controller/webservice_test.rb b/actionpack/test/controller/webservice_test.rb index c99abeaa9e..90691e9e9c 100644 --- a/actionpack/test/controller/webservice_test.rb +++ b/actionpack/test/controller/webservice_test.rb @@ -19,7 +19,20 @@ class WebServiceTest < Test::Unit::TestCase session :off def assign_parameters - render :text => (@params.keys - ['controller', 'action']).sort.join(", ") + if params[:full] + render :text => dump_params_keys + else + render :text => (params.keys - ['controller', 'action']).sort.join(", ") + end + end + + def dump_params_keys(hash=params) + hash.keys.sort.inject("") do |s, k| + value = hash[k] + value = Hash === value ? "(#{dump_params_keys(value)})" : "" + s << ", " unless s.empty? + s << "#{k}#{value}" + end end def rescue_action(e) raise end @@ -88,16 +101,28 @@ class WebServiceTest < Test::Unit::TestCase assert_equal true, @controller.request.yaml_post? assert_equal false, @controller.request.xml_post? end + + def test_dasherized_keys_as_xml + ActionController::Base.param_parsers[Mime::XML] = :xml_simple + process('POST', 'application/xml', "<first-key>\n<sub-key>...</sub-key>\n</first-key>", true) + assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body + end + + def test_dasherized_keys_as_yaml + ActionController::Base.param_parsers[Mime::YAML] = :yaml + process('POST', 'application/x-yaml', "---\nfirst-key:\n sub-key: ...\n", true) + assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body + end private - def process(verb, content_type = 'application/x-www-form-urlencoded', data = '') + def process(verb, content_type = 'application/x-www-form-urlencoded', data = '', full=false) cgi = MockCGI.new({ 'REQUEST_METHOD' => verb, 'CONTENT_TYPE' => content_type, - 'QUERY_STRING' => "action=assign_parameters&controller=webservicetest/test", + 'QUERY_STRING' => "action=assign_parameters&controller=webservicetest/test#{"&full=1" if full}", "REQUEST_URI" => "/", "HTTP_HOST" => 'testdomain.com', "CONTENT_LENGTH" => data.size, |