From 65ef2592f6aa7ad54b5bd86f132fb7673880c199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 9 May 2012 18:27:44 +0200 Subject: [PATCH] Add a test case to previous commit --- CHANGELOG.rdoc | 1 + test/failure_app_test.rb | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index fc67b5ea..7cd845f9 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -9,6 +9,7 @@ * valid_for_authentication? must now return a boolean * bug fix + * Ensure the failure app still respects config.relative_url_root * `/users/sign_in` doesn't choke on protected attributes used to select sign in scope (by @Paymium) * `failed_attempts` is set to zero after any sign in (including via reset password) (by @rodrigoflores) * Added token expiration on timeout (by @antiarchitect) diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index 0a72f739..a1cff058 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -29,20 +29,20 @@ class FailureTest < ActiveSupport::TestCase end context 'When redirecting' do - test 'return to the default redirect location' do + test 'returns to the default redirect location' do call_failure assert_equal 302, @response.first assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert] assert_equal 'http://test.host/users/sign_in', @response.second['Location'] end - test 'return to the default redirect location for wildcard requests' do + test 'returns to the default redirect location for wildcard requests' do call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*' assert_equal 302, @response.first assert_equal 'http://test.host/users/sign_in', @response.second['Location'] end - test 'return to the root path if no session path is available' do + test 'returns to the root path if no session path is available' do swap Devise, :router_name => :fake_app do call_failure :app => RootFailureApp assert_equal 302, @response.first @@ -51,6 +51,14 @@ class FailureTest < ActiveSupport::TestCase end end + test 'returns to the default redirect location considering the relative url root' do + swap Rails.application.config, :relative_url_root => "/sample" do + call_failure + assert_equal 302, @response.first + assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location'] + end + end + test 'uses the proxy failure message as symbol' do call_failure('warden' => OpenStruct.new(:message => :invalid)) assert_equal 'Invalid email or password.', @request.flash[:alert]