aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/testing/integration.rb
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2010-04-05 17:01:33 -0500
committerJeremy Kemper <jeremy@bitsweat.net>2010-04-05 15:22:09 -0700
commit570c54c39acc702eefcee9589ebe02d85173a1c1 (patch)
treecc0a9c87190767fe31520115830490ce073aa6f0 /actionpack/lib/action_dispatch/testing/integration.rb
parentd270da569efeabd7cd563028816452236713aa9f (diff)
downloadrails-570c54c39acc702eefcee9589ebe02d85173a1c1.tar.gz
rails-570c54c39acc702eefcee9589ebe02d85173a1c1.tar.bz2
rails-570c54c39acc702eefcee9589ebe02d85173a1c1.zip
Fix cookie access in integration tests with other host names
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/integration.rb')
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index 286797ba20..64eb6d8de7 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -137,7 +137,10 @@ module ActionDispatch
end
# The hostname used in the last request.
- attr_accessor :host
+ def host
+ @host || DEFAULT_HOST
+ end
+ attr_writer :host
# The remote_addr used in the last request.
attr_accessor :remote_addr
@@ -148,7 +151,7 @@ module ActionDispatch
# A map of the cookies returned by the last response, and which will be
# sent with the next request.
def cookies
- @mock_session.cookie_jar
+ _mock_session.cookie_jar
end
# A reference to the controller instance used by the last request.
@@ -189,8 +192,8 @@ module ActionDispatch
# session.reset!
def reset!
@https = false
- @mock_session = Rack::MockSession.new(@app, DEFAULT_HOST)
@controller = @request = @response = nil
+ @_mock_session = nil
@request_count = 0
self.host = DEFAULT_HOST
@@ -234,6 +237,9 @@ module ActionDispatch
end
private
+ def _mock_session
+ @_mock_session ||= Rack::MockSession.new(@app, host)
+ end
# Performs the actual request.
def process(method, path, parameters = nil, rack_environment = nil)
@@ -254,7 +260,7 @@ module ActionDispatch
:method => method,
:params => parameters,
- "SERVER_NAME" => host,
+ "SERVER_NAME" => host.split(':')[0],
"SERVER_PORT" => (https? ? "443" : "80"),
"HTTPS" => https? ? "on" : "off",
"rack.url_scheme" => https? ? "https" : "http",
@@ -266,17 +272,25 @@ module ActionDispatch
"HTTP_ACCEPT" => accept
}
- session = Rack::Test::Session.new(@mock_session)
+ session = Rack::Test::Session.new(_mock_session)
(rack_environment || {}).each do |key, value|
env[key] = value
end
- session.request(path, env)
+ # NOTE: rack-test v0.5 doesn't build a default uri correctly
+ # Make sure requested path is always a full uri
+ uri = URI.parse('/')
+ uri.scheme ||= env['rack.url_scheme']
+ uri.host ||= env['SERVER_NAME']
+ uri.port ||= env['SERVER_PORT'].try(:to_i)
+ uri += path
+
+ session.request(uri.to_s, env)
@request_count += 1
@request = ActionDispatch::Request.new(session.last_request.env)
- response = @mock_session.last_response
+ response = _mock_session.last_response
@response = ActionDispatch::TestResponse.new(response.status, response.headers, response.body)
@html_document = nil