Changeset 3878
- Timestamp:
- 03/15/06 21:46:41 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb (modified) (2 diffs)
- trunk/actionpack/lib/action_controller/mime_responds.rb (modified) (1 diff)
- trunk/actionpack/test/controller/webservice_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r3876 r3878 1 1 *SVN* 2 3 * Underscore dasherized keys in formatted requests [Jamis Buck] 2 4 3 5 * Add MimeResponds::Responder#any for managing multiple types with identical responses [Jamis Buck] trunk/actionpack/lib/action_controller/cgi_ext/cgi_methods.rb
r3874 r3878 72 72 end 73 73 74 params || {}74 dasherize_keys(params || {}) 75 75 rescue Object => e 76 76 { "exception" => "#{e.message} (#{e.class})", "backtrace" => e.backtrace, … … 79 79 80 80 private 81 82 def self.dasherize_keys(params) 83 case params.class.to_s 84 when "Hash" 85 params.inject({}) do |h,(k,v)| 86 h[k.tr("-", "_")] = dasherize_keys(v) 87 h 88 end 89 else 90 params 91 end 92 end 81 93 82 94 # Splits the given key into several pieces. Example keys are 'name', 'person[name]', trunk/actionpack/lib/action_controller/mime_responds.rb
r3876 r3878 37 37 else 38 38 if argument = args.first 39 eval("__mime_responder_arg__ = " + (argument.is_a?(String) ? "'" + argument + "'" : argument), @block_binding)39 eval("__mime_responder_arg__ = #{argument.is_a?(String) ? argument.inspect : argument}", @block_binding) 40 40 @responses[mime_type] = eval(DEFAULT_BLOCKS[(mime_type.to_sym.to_s + "_arg").to_sym], @block_binding) 41 41 else trunk/actionpack/test/controller/webservice_test.rb
r3847 r3878 20 20 21 21 def assign_parameters 22 render :text => (@params.keys - ['controller', 'action']).sort.join(", ") 22 if params[:full] 23 render :text => dump_params_keys 24 else 25 render :text => (params.keys - ['controller', 'action']).sort.join(", ") 26 end 27 end 28 29 def dump_params_keys(hash=params) 30 hash.keys.sort.inject("") do |s, k| 31 value = hash[k] 32 value = Hash === value ? "(#{dump_params_keys(value)})" : "" 33 s << ", " unless s.empty? 34 s << "#{k}#{value}" 35 end 23 36 end 24 37 … … 89 102 assert_equal false, @controller.request.xml_post? 90 103 end 104 105 def test_dasherized_keys_as_xml 106 ActionController::Base.param_parsers[Mime::XML] = :xml_simple 107 process('POST', 'application/xml', "<first-key>\n<sub-key>...</sub-key>\n</first-key>", true) 108 assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body 109 end 110 111 def test_dasherized_keys_as_yaml 112 ActionController::Base.param_parsers[Mime::YAML] = :yaml 113 process('POST', 'application/x-yaml', "---\nfirst-key:\n sub-key: ...\n", true) 114 assert_equal 'action, controller, first_key(sub_key), full', @controller.response.body 115 end 91 116 92 117 93 118 private 94 119 95 def process(verb, content_type = 'application/x-www-form-urlencoded', data = '' )120 def process(verb, content_type = 'application/x-www-form-urlencoded', data = '', full=false) 96 121 97 122 cgi = MockCGI.new({ 98 123 'REQUEST_METHOD' => verb, 99 124 'CONTENT_TYPE' => content_type, 100 'QUERY_STRING' => "action=assign_parameters&controller=webservicetest/test ",125 'QUERY_STRING' => "action=assign_parameters&controller=webservicetest/test#{"&full=1" if full}", 101 126 "REQUEST_URI" => "/", 102 127 "HTTP_HOST" => 'testdomain.com',