Ticket #7124: ticket-7124-integration-session-xhr-normalization.diff
| File ticket-7124-integration-session-xhr-normalization.diff, 3.3 kB (added by francois.beausoleil, 2 years ago) |
|---|
-
test/controller/integration_test.rb
old new 134 134 @session.head(path,params,headers) 135 135 end 136 136 137 def test_xml_http_request 137 def test_xml_http_request_deprecated_call 138 138 path = "/index"; params = "blah"; headers = {:location => 'blah'} 139 139 headers_after_xhr = headers.merge( 140 140 "X-Requested-With" => "XMLHttpRequest", … … 143 143 @session.expects(:post).with(path,params,headers_after_xhr) 144 144 @session.xml_http_request(path,params,headers) 145 145 end 146 147 def test_put_using_xml_http_request 148 path = "/people/3"; params = "blah"; headers = {:location => 'blah'} 149 headers_after_xhr = headers.merge( 150 "X-Requested-With" => "XMLHttpRequest", 151 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 152 ) 153 @session.expects(:put).with(path, params, headers_after_xhr) 154 @session.xml_http_request(:put, path, params, headers) 155 end 156 157 def test_delete_using_xml_http_request_alias 158 path = "/people/3"; params = "blah"; headers = {:location => 'blah'} 159 headers_after_xhr = headers.merge( 160 "X-Requested-With" => "XMLHttpRequest", 161 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 162 ) 163 @session.expects(:delete).with(path, params, headers_after_xhr) 164 @session.xhr(:delete, path, params, headers) 165 end 146 166 end 147 167 148 168 # TODO -
lib/action_controller/integration.rb
old new 178 178 # (application/x-www-form-urlencoded or multipart/form-data). The headers 179 179 # should be a hash. The keys will automatically be upcased, with the 180 180 # prefix 'HTTP_' added if needed. 181 def xml_http_request(path, parameters=nil, headers=nil) 182 headers = (headers || {}).merge( 183 "X-Requested-With" => "XMLHttpRequest", 184 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 185 ) 181 # 182 # This method was previously implemented as: 183 # xml_http_request(path, parameters=nil, headers=nil, *extras) 184 def xml_http_request(request_method, path=nil, parameters=nil, headers=nil) 185 case request_method.to_s.downcase 186 when "get", "head", "put", "post", "delete" 187 headers = (headers || {}).merge( 188 "X-Requested-With" => "XMLHttpRequest", 189 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 190 ) 191 send(request_method, path, parameters, headers) 192 else 193 # Deprecated call 194 path, parameters, headers = request_method, path, parameters 186 195 187 post(path, parameters, headers) 196 headers = (headers || {}).merge( 197 "X-Requested-With" => "XMLHttpRequest", 198 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 199 ) 200 post(path, parameters, headers) 201 end 188 202 end 203 alias xhr :xml_http_request 189 204 190 205 # Returns the URL for the given options, according to the rules specified 191 206 # in the application's routes.