lib/devise/test_helpers.rb in devise-3.5.10 vs lib/devise/test_helpers.rb in devise-4.0.0.rc1
- old
+ new
@@ -14,11 +14,14 @@
end
# Override process to consider warden.
def process(*)
# Make sure we always return @response, a la ActionController::TestCase::Behaviour#process, even if warden interrupts
- _catch_warden { super } || @response
+ _catch_warden { super } # || @response # _catch_warden will setup the @response object
+
+ # process needs to return the ActionDispath::TestResponse object
+ @response
end
# We need to setup the environment variables and the response in the controller.
def setup_controller_for_warden #:nodoc:
@request.env['action_controller.instance'] = @controller
@@ -107,12 +110,13 @@
env["warden.options"] = options
Warden::Manager._run_callbacks(:before_failure, env, options)
status, headers, response = Devise.warden_config[:failure_app].call(env).to_a
@controller.response.headers.merge!(headers)
- @controller.send :render, status: status, text: response.body,
- content_type: headers["Content-Type"], location: headers["Location"]
+ r_opts = { status: status, content_type: headers["Content-Type"], location: headers["Location"] }
+ r_opts[Rails.version.start_with?('5') ? :body : :text] = response.body
+ @controller.send :render, r_opts
nil # causes process return @response
end
# ensure that the controller response is set up. In production, this is
# not necessary since warden returns the results to rack. However, at
@@ -120,10 +124,11 @@
# framework to verify what would be returned to rack.
if ret.is_a?(Array)
# ensure the controller response is set to our response.
@controller.response ||= @response
@response.status = ret.first
- @response.headers = ret.second
+ @response.headers.clear
+ ret.second.each { |k,v| @response[k] = v }
@response.body = ret.third
end
ret
end