Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Unset the X-Requested-With header when using the xhr wrapper in funct…

…ional tests. Closes #2352.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2551 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 4b72a4b12fbb33d32ae3f9b9d004ca5888d42d58 1 parent f60f76e
@sstephenson sstephenson authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Unset the X-Requested-With header when using the xhr wrapper in functional tests so that future requests aren't accidentally xhr'ed #2352 [me@julik.nl, Sam Stephenson]
+
* Unescape paths before writing cache to file system. #1877. [Damien Pollet]
* Wrap javascript_tag contents in a CDATA section and add a cdata_section method to TagHelper #1691 [Michael Schuerig, Sam Stephenson]
View
4 actionpack/lib/action_controller/test_process.rb
@@ -303,7 +303,9 @@ def #{method}(action, parameters = nil, session = nil, flash = nil)
def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil)
@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
- self.send(request_method, action, parameters, session, flash)
+ returning self.send(request_method, action, parameters, session, flash) do
+ @request.env.delete 'HTTP_X_REQUESTED_WITH'
+ end
end
alias xhr :xml_http_request
View
5 actionpack/test/controller/test_test.rb
@@ -305,6 +305,11 @@ def test_remote_addr
assert_equal "192.0.0.1", @response.body
end
+ def test_header_properly_reset_after_remote_http_request
+ xhr :get, :test_params
+ assert_nil @request.env['HTTP_X_REQUESTED_WITH']
+ end
+
%w(controller response request).each do |variable|
%w(get post put delete head process).each do |method|
define_method("test_#{variable}_missing_for_#{method}_raises_error") do
Please sign in to comment.
Something went wrong with that request. Please try again.