2009-10-22 18:12:00 -04:00
|
|
|
require 'test/test_helper'
|
2009-11-22 19:19:29 -05:00
|
|
|
require 'ostruct'
|
2009-10-22 18:12:00 -04:00
|
|
|
|
|
|
|
class FailureTest < ActiveSupport::TestCase
|
|
|
|
|
|
|
|
def call_failure(env_params={})
|
2010-02-16 11:00:36 -05:00
|
|
|
env = {
|
|
|
|
'warden.options' => { :scope => :user },
|
|
|
|
'REQUEST_URI' => 'http://test.host/',
|
2010-02-19 03:52:04 -05:00
|
|
|
'HTTP_HOST' => 'test.host',
|
2010-02-16 11:00:36 -05:00
|
|
|
'REQUEST_METHOD' => 'GET',
|
|
|
|
'rack.session' => {}
|
|
|
|
}.merge!(env_params)
|
2009-11-16 11:31:09 -05:00
|
|
|
Devise::FailureApp.call(env)
|
2009-10-22 18:12:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'return 302 status' do
|
|
|
|
assert_equal 302, call_failure.first
|
|
|
|
end
|
|
|
|
|
2009-11-21 21:49:23 -05:00
|
|
|
test 'return to the default redirect location' do
|
2010-02-19 03:52:04 -05:00
|
|
|
assert_equal 'http://test.host/users/sign_in?unauthenticated=true', call_failure.second['Location']
|
2009-10-22 18:12:00 -04:00
|
|
|
end
|
|
|
|
|
2009-11-16 11:31:09 -05:00
|
|
|
test 'uses the proxy failure message' do
|
|
|
|
warden = OpenStruct.new(:message => :test)
|
|
|
|
location = call_failure('warden' => warden).second['Location']
|
2010-02-19 03:52:04 -05:00
|
|
|
assert_equal 'http://test.host/users/sign_in?test=true', location
|
2009-10-22 18:12:00 -04:00
|
|
|
end
|
|
|
|
|
2009-11-22 19:19:29 -05:00
|
|
|
test 'uses the given message' do
|
|
|
|
warden = OpenStruct.new(:message => 'Hello world')
|
|
|
|
location = call_failure('warden' => warden).second['Location']
|
2010-02-19 03:52:04 -05:00
|
|
|
assert_equal 'http://test.host/users/sign_in?message=Hello+world', location
|
2009-11-22 19:19:29 -05:00
|
|
|
end
|
|
|
|
|
2010-02-19 03:52:04 -05:00
|
|
|
test 'set content type to default text/html' do
|
|
|
|
assert_equal 'text/html; charset=utf-8', call_failure.second['Content-Type']
|
2009-10-22 18:12:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'setup a default message' do
|
2010-02-19 03:52:04 -05:00
|
|
|
assert_match /You are being/, call_failure.last.body
|
|
|
|
assert_match /redirected/, call_failure.last.body
|
|
|
|
assert_match /\?unauthenticated=true/, call_failure.last.body
|
2009-10-22 18:12:00 -04:00
|
|
|
end
|
|
|
|
end
|