Permalink
Browse files

Enhance documentation for setting headers in integration tests. Skip …

…auto HTTP prepending when its already there. Closes #4079. [Rick Olson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4286 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 3ba7c53 commit 8ee378f3c46c164cf8d7559bbb6a65ce1bb786fb Marcel Molina committed Apr 26, 2006
Showing with 12 additions and 4 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +10 −4 actionpack/lib/action_controller/integration.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Enhance documentation for setting headers in integration tests. Skip auto HTTP prepending when its already there. Closes #4079. [Rick Olson]
+
* Documentation for AbstractRequest. Closes #4895. [kevin.clark@gmail.com]
* Refactor various InstanceTag instance method to class methods. Closes #4800. [skaes@web.de]
@@ -140,22 +140,28 @@ def redirect?
# Performs a GET request with the given parameters. The parameters may
# be +nil+, a Hash, or a string that is appropriately encoded
- # (application/x-www-form-urlencoded or multipart/form-data).
+ # (application/x-www-form-urlencoded or multipart/form-data). The headers
+ # should be a hash. The keys will automatically be upcased, with the
+ # prefix 'HTTP_' added if needed.
def get(path, parameters=nil, headers=nil)
process :get, path, parameters, headers
end
# Performs a POST request with the given parameters. The parameters may
# be +nil+, a Hash, or a string that is appropriately encoded
- # (application/x-www-form-urlencoded or multipart/form-data).
+ # (application/x-www-form-urlencoded or multipart/form-data). The headers
+ # should be a hash. The keys will automatically be upcased, with the
+ # prefix 'HTTP_' added if needed.
def post(path, parameters=nil, headers=nil)
process :post, path, parameters, headers
end
# Performs an XMLHttpRequest request with the given parameters, mimicing
# the request environment created by the Prototype library. The parameters
# may be +nil+, a Hash, or a string that is appropriately encoded
- # (application/x-www-form-urlencoded or multipart/form-data).
+ # (application/x-www-form-urlencoded or multipart/form-data). The headers
+ # should be a hash. The keys will automatically be upcased, with the
+ # prefix 'HTTP_' added if needed.
def xml_http_request(path, parameters=nil, headers=nil)
headers = (headers || {}).merge("X-Requested-With" => "XMLHttpRequest")
post(path, parameters, headers)
@@ -218,7 +224,7 @@ def process(method, path, parameters=nil, headers=nil)
(headers || {}).each do |key, value|
key = key.to_s.upcase.gsub(/-/, "_")
- key = "HTTP_#{key}" unless env.has_key?(key)
+ key = "HTTP_#{key}" unless env.has_key?(key) || env =~ /^X|HTTP/
env[key] = value
end

0 comments on commit 8ee378f

Please sign in to comment.