Skip to content

Commit

Permalink
Preserve content_type for unauthenticated tests
Browse files Browse the repository at this point in the history
In Rails 4, for unauthenticated controller tests which trigger the
failure app, ensure that the simulated failure response includes a
content_type (broken in bb44d42).

This works in Rails5, which parses the content-type header on-demand,
but not in Rails4 which requires setting the response's content_type
explicitly.

Fixes #4783.
  • Loading branch information
Gordon McNaughton committed Feb 26, 2018
1 parent 6bda962 commit 3e23371
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/devise/test/controller_helpers.rb
Expand Up @@ -139,6 +139,7 @@ def _process_unauthenticated(env, options = {})

status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
@controller.response.headers.merge!(headers)
@controller.response.content_type = headers["Content-Type"] unless Devise::Test.rails5?
@controller.status = status
@controller.response.body = response.body
nil # causes process return @response
Expand Down
5 changes: 5 additions & 0 deletions test/test/controller_helpers_test.rb
Expand Up @@ -100,6 +100,11 @@ def respond
assert_equal response.body, "<html><body>You are being <a href=\"http://test.host/users/sign_in\">redirected</a>.</body></html>"
end

test "returns the content type of a failure app" do
get :index, params: { format: :xml }
assert response.content_type.include?('application/xml')
end

test "defined Warden after_authentication callback should not be called when sign_in is called" do
begin
Warden::Manager.after_authentication do |user, auth, opts|
Expand Down

0 comments on commit 3e23371

Please sign in to comment.