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:
parent
3cb97aeea8
commit
6940c0de12
2 changed files with 13 additions and 22 deletions
|
@ -285,37 +285,28 @@ module ActionController
|
||||||
app = Rack::Lint.new(@app)
|
app = Rack::Lint.new(@app)
|
||||||
status, headers, body = app.call(env)
|
status, headers, body = app.call(env)
|
||||||
response = ::Rack::MockResponse.new(status, headers, body)
|
response = ::Rack::MockResponse.new(status, headers, body)
|
||||||
|
|
||||||
@request_count += 1
|
@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]
|
@status_message = ActionDispatch::StatusCodes::STATUS_CODES[@status]
|
||||||
@headers = response.headers
|
@cookies.merge!(@response.cookies)
|
||||||
@body = response.body
|
@html_document = nil
|
||||||
|
|
||||||
(@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
|
|
||||||
|
|
||||||
# Decorate the response with the standard behavior of the
|
# Decorate the response with the standard behavior of the
|
||||||
# TestResponse so that things like assert_response can be
|
# TestResponse so that things like assert_response can be
|
||||||
# used in integration tests.
|
# used in integration tests.
|
||||||
@response.extend(TestResponseBehavior)
|
@response.extend(TestResponseBehavior)
|
||||||
|
|
||||||
|
if @controller = ActionController::Base.last_instantiation
|
||||||
|
@controller.send(:set_test_assigns)
|
||||||
|
end
|
||||||
|
|
||||||
return @status
|
return @status
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -297,7 +297,7 @@ class IntegrationProcessTest < ActionController::IntegrationTest
|
||||||
assert_response 410
|
assert_response 410
|
||||||
assert_response :gone
|
assert_response :gone
|
||||||
assert_equal "cookie_1=; path=/\ncookie_3=chocolate; path=/", headers["Set-Cookie"]
|
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
|
assert_equal "Gone", response.body
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue