From b27491061e8033aeffbfeb4b5dc11d0ac1a4e241 Mon Sep 17 00:00:00 2001 From: Jason Rush Date: Thu, 27 Sep 2012 18:44:31 -0600 Subject: [PATCH] Test helper was incorrectly returning failure body The _process_unauthenticated method in test_helper was returning the response as the body. When setting rendering the text, it was calling to_s on the response which would render something like this: #. This change renders the body of the response instead of the response itself --- lib/devise/test_helpers.rb | 4 ++-- test/test_helpers_test.rb | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/devise/test_helpers.rb b/lib/devise/test_helpers.rb index 9aa7c239..646a9ce6 100644 --- a/lib/devise/test_helpers.rb +++ b/lib/devise/test_helpers.rb @@ -107,8 +107,8 @@ module Devise env["warden.options"] = options Warden::Manager._run_callbacks(:before_failure, env, options) - status, headers, body = Devise.warden_config[:failure_app].call(env).to_a - @controller.send :render, :status => status, :text => body, + status, headers, response = Devise.warden_config[:failure_app].call(env).to_a + @controller.send :render, :status => status, :text => response.body, :content_type => headers["Content-Type"], :location => headers["Location"] nil # causes process return @response end diff --git a/test/test_helpers_test.rb b/test/test_helpers_test.rb index ff4a1677..68e55d95 100644 --- a/test/test_helpers_test.rb +++ b/test/test_helpers_test.rb @@ -9,7 +9,7 @@ class TestHelpersTest < ActionController::TestCase self.status = 306 end end - + test "redirects if attempting to access a page unauthenticated" do get :index assert_redirected_to new_user_session_path @@ -70,7 +70,7 @@ class TestHelpersTest < ActionController::TestCase get :index assert_redirected_to new_user_session_path end - + test "respects custom failure app" do begin Devise.warden_config.failure_app = CustomFailureApp @@ -81,6 +81,11 @@ class TestHelpersTest < ActionController::TestCase end end + test "returns the body of a failure app" do + get :index + assert_equal response.body, "You are being redirected." + 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|