Changeset 6796
- Timestamp:
- 05/21/07 09:15:16 (1 year ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/integration.rb (modified) (7 diffs)
- trunk/actionpack/test/controller/integration_test.rb (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r6787 r6796 1 1 *SVN* 2 3 * Integration tests: alias xhr to xml_http_request and add a request_method argument instead of always using POST. #7124 [Nik Wakelin, Francois Beausoleil, Wizard] 2 4 3 5 * Document caches_action. #5419 [Jarkko Laine] trunk/actionpack/lib/action_controller/integration.rb
r6764 r6796 68 68 @cookies = {} 69 69 @controller = @request = @response = nil 70 70 71 71 self.host = "www.example.com" 72 72 self.remote_addr = "127.0.0.1" … … 90 90 # session.https!(false) 91 91 def https!(flag=true) 92 @https = flag 92 @https = flag 93 93 end 94 94 … … 144 144 # be +nil+, a Hash, or a string that is appropriately encoded 145 145 # (application/x-www-form-urlencoded or multipart/form-data). The headers 146 # should be a hash. The keys will automatically be upcased, with the 146 # should be a hash. The keys will automatically be upcased, with the 147 147 # prefix 'HTTP_' added if needed. 148 148 # 149 # You can also perform POST, PUT, DELETE, and HEAD requests with #post, 149 # You can also perform POST, PUT, DELETE, and HEAD requests with #post, 150 150 # #put, #delete, and #head. 151 151 def get(path, parameters=nil, headers=nil) … … 162 162 process :put, path, parameters, headers 163 163 end 164 164 165 165 # Performs a DELETE request with the given parameters. See get() for more details. 166 166 def delete(path, parameters=nil, headers=nil) 167 167 process :delete, path, parameters, headers 168 168 end 169 169 170 170 # Performs a HEAD request with the given parameters. See get() for more details. 171 171 def head(path, parameters=nil, headers=nil) … … 173 173 end 174 174 175 # Performs an XMLHttpRequest request with the given parameters, mimicing 176 # the request environment created by the Prototype library. The parameters 177 # may be +nil+, a Hash, or a string that is appropriately encoded 178 # (application/x-www-form-urlencoded or multipart/form-data). The headers 179 # should be a hash. The keys will automatically be upcased, with the 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 ) 186 187 post(path, parameters, headers) 188 end 175 # Performs an XMLHttpRequest request with the given parameters, mirroring 176 # a request from the Prototype library. 177 # 178 # The request_method is :get, :post, :put, :delete or :head; the 179 # parameters are +nil+, a hash, or a url-encoded or multipart string; 180 # the headers are a hash. Keys are automatically upcased and prefixed 181 # with 'HTTP_' if not already. 182 # 183 # This method used to omit the request_method parameter, assuming it 184 # was :post. This was deprecated in Rails 1.2.4. Always pass the request 185 # method as the first argument. 186 def xml_http_request(request_method, path, parameters = nil, headers = nil) 187 unless request_method.is_a?(Symbol) 188 ActiveSupport::Deprecation.warn 'xml_http_request now takes the request_method (:get, :post, etc.) as the first argument. It used to assume :post, so add the :post argument to your existing method calls to silence this warning.' 189 request_method, path, parameters, headers = :post, request_method, path, parameters 190 end 191 192 headers ||= {} 193 headers['X-Requested-With'] = 'XMLHttpRequest' 194 headers['Accept'] = 'text/javascript, text/html, application/xml, text/xml, */*' 195 196 process(request_method, path, parameters, headers) 197 end 198 alias xhr :xml_http_request 189 199 190 200 # Returns the URL for the given options, according to the rules specified … … 292 302 end 293 303 294 # Encode the cookies hash in a format suitable for passing to a 304 # Encode the cookies hash in a format suitable for passing to a 295 305 # request. 296 306 def encode_cookies … … 450 460 def run(*args) #:nodoc: 451 461 return if @method_name == "default_test" 452 super 462 super 453 463 end 454 464 trunk/actionpack/test/controller/integration_test.rb
r6203 r6796 133 133 end 134 134 135 def test_xml_http_request 136 path = "/index"; params = "blah"; headers = {:location => 'blah'} 137 headers_after_xhr = headers.merge( 138 "X-Requested-With" => "XMLHttpRequest", 139 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 140 ) 141 @session.expects(:post).with(path,params,headers_after_xhr) 142 @session.xml_http_request(path,params,headers) 135 def test_xml_http_request_deprecated_call 136 path = "/index"; params = "blah"; headers = {:location => 'blah'} 137 headers_after_xhr = headers.merge( 138 "X-Requested-With" => "XMLHttpRequest", 139 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 140 ) 141 @session.expects(:process).with(:post,path,params,headers_after_xhr) 142 assert_deprecated { @session.xml_http_request(path,params,headers) } 143 end 144 145 def test_xml_http_request_get 146 path = "/index"; params = "blah"; headers = {:location => 'blah'} 147 headers_after_xhr = headers.merge( 148 "X-Requested-With" => "XMLHttpRequest", 149 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 150 ) 151 @session.expects(:process).with(:get,path,params,headers_after_xhr) 152 @session.xml_http_request(:get,path,params,headers) 153 end 154 155 def test_xml_http_request_post 156 path = "/index"; params = "blah"; headers = {:location => 'blah'} 157 headers_after_xhr = headers.merge( 158 "X-Requested-With" => "XMLHttpRequest", 159 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 160 ) 161 @session.expects(:process).with(:post,path,params,headers_after_xhr) 162 @session.xml_http_request(:post,path,params,headers) 163 end 164 165 def test_xml_http_request_put 166 path = "/index"; params = "blah"; headers = {:location => 'blah'} 167 headers_after_xhr = headers.merge( 168 "X-Requested-With" => "XMLHttpRequest", 169 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 170 ) 171 @session.expects(:process).with(:put,path,params,headers_after_xhr) 172 @session.xml_http_request(:put,path,params,headers) 173 end 174 175 def test_xml_http_request_delete 176 path = "/index"; params = "blah"; headers = {:location => 'blah'} 177 headers_after_xhr = headers.merge( 178 "X-Requested-With" => "XMLHttpRequest", 179 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 180 ) 181 @session.expects(:process).with(:delete,path,params,headers_after_xhr) 182 @session.xml_http_request(:delete,path,params,headers) 183 end 184 185 def test_xml_http_request_head 186 path = "/index"; params = "blah"; headers = {:location => 'blah'} 187 headers_after_xhr = headers.merge( 188 "X-Requested-With" => "XMLHttpRequest", 189 "Accept" => "text/javascript, text/html, application/xml, text/xml, */*" 190 ) 191 @session.expects(:process).with(:head,path,params,headers_after_xhr) 192 @session.xml_http_request(:head,path,params,headers) 143 193 end 144 194 end … … 151 201 @session = @test.open_session 152 202 end 153 203 154 204 def test_opens_new_session 155 205 @test.class.expects(:fixture_table_names).times(2).returns(['foo'])