Skip to content
Browse files

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: #<ActionDispatch::Response:0x007fb9e1efea00>. This change
renders the body of the response instead of the response itself
  • Loading branch information...
1 parent 9e096a4 commit b27491061e8033aeffbfeb4b5dc11d0ac1a4e241 @diminish7 diminish7 committed Sep 27, 2012
Showing with 9 additions and 4 deletions.
  1. +2 −2 lib/devise/test_helpers.rb
  2. +7 −2 test/test_helpers_test.rb
View
4 lib/devise/test_helpers.rb
@@ -107,8 +107,8 @@ def _process_unauthenticated(env, options = {})
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
View
9 test/test_helpers_test.rb
@@ -9,7 +9,7 @@ def redirect
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 @@ def redirect
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 @@ def redirect
end
end
+ test "returns the body of a failure app" do
+ get :index
+ assert_equal response.body, "<html><body>You are being <a href=\"http://test.host/users/sign_in\">redirected</a>.</body></html>"
+ 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|

0 comments on commit b274910

Please sign in to comment.
Something went wrong with that request. Please try again.