1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Unify functional and integration tests cookie helpers

This commit is contained in:
Joshua Peek 2009-04-26 11:37:11 -05:00
parent 3cb97aeea8
commit 6940c0de12
2 changed files with 13 additions and 22 deletions

View file

@ -285,37 +285,28 @@ module ActionController
app = Rack::Lint.new(@app)
status, headers, body = app.call(env)
response = ::Rack::MockResponse.new(status, headers, body)
@request_count += 1
@request = Request.new(env)
@html_document = nil
@response = Response.new
@response.status = @status = response.status
@response.headers = @headers = response.headers
@response.body = @body = response.body
@status = response.status
@status_message = ActionDispatch::StatusCodes::STATUS_CODES[@status]
@headers = response.headers
@body = response.body
(@headers['Set-Cookie'] || "").split("\n").each do |cookie|
name, value = cookie.match(/^([^=]*)=([^;]*);/)[1,2]
@cookies[name] = value
end
if @controller = ActionController::Base.last_instantiation
@request = @controller.request
@response = @controller.response
@controller.send(:set_test_assigns)
else
@request = Request.new(env)
@response = Response.new
@response.status = @status
@response.headers = @headers
@response.body = @body
end
@cookies.merge!(@response.cookies)
@html_document = nil
# Decorate the response with the standard behavior of the
# TestResponse so that things like assert_response can be
# used in integration tests.
@response.extend(TestResponseBehavior)
if @controller = ActionController::Base.last_instantiation
@controller.send(:set_test_assigns)
end
return @status
end

View file

@ -297,7 +297,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
assert_response 410
assert_response :gone
assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
assert_equal({"cookie_1"=>"", "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
assert_equal({"cookie_1"=>nil, "cookie_2"=>"oatmeal", "cookie_3"=>"chocolate"}, cookies)
assert_equal "Gone", response.body
end
end