From b9df42c35017f6ff0e650832290ab56306d93dd2 Mon Sep 17 00:00:00 2001 From: James Pellow Date: Thu, 8 Jul 2010 03:05:30 +0800 Subject: [PATCH] Add tests for http_authenticatable_on_xhr option --- test/failure_app_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/failure_app_test.rb b/test/failure_app_test.rb index 3a1c47a9..b2b965f9 100644 --- a/test/failure_app_test.rb +++ b/test/failure_app_test.rb @@ -77,6 +77,20 @@ class FailureTest < ActiveSupport::TestCase assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"] end + test 'dont return WWW-authenticate on ajax call if http_authenticatable_on_xhr false' do + swap Devise, :http_authenticatable_on_xhr => false do + call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') + assert_nil @response.second['WWW-Authenticate'] + end + end + + test 'return WWW-authenticate on ajax call if http_authenticatable_on_xhr true' do + swap Devise, :http_authenticatable_on_xhr => true do + call_failure('formats' => :html, 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest') + assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"] + end + end + test 'uses the proxy failure message as response body' do call_failure('formats' => :xml, 'warden' => OpenStruct.new(:message => :invalid)) assert_match 'Invalid email or password.', @response.third.body