2009-11-03 06:35:11 -05:00
|
|
|
require 'test/test_helper'
|
|
|
|
|
|
|
|
module Devise
|
|
|
|
def self.clean_warden_config!
|
|
|
|
@warden_config = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class DeviseTest < ActiveSupport::TestCase
|
|
|
|
class MockManager
|
|
|
|
attr_accessor :failure_app
|
|
|
|
attr_reader :default_strategies, :silence_missing_strategies
|
|
|
|
|
|
|
|
def silence_missing_strategies!
|
|
|
|
@silence_missing_strategies = true
|
|
|
|
end
|
|
|
|
|
2009-11-14 21:13:43 -05:00
|
|
|
def silence_missing_serializers!
|
|
|
|
@silence_missing_serializers = true
|
|
|
|
end
|
|
|
|
|
2009-11-03 06:35:11 -05:00
|
|
|
def default_strategies(*args)
|
|
|
|
if args.empty?
|
|
|
|
@default_strategies
|
|
|
|
else
|
|
|
|
@default_strategies = args
|
|
|
|
end
|
|
|
|
end
|
2009-11-14 21:13:43 -05:00
|
|
|
|
|
|
|
def default_serializers(*args)
|
|
|
|
if args.empty?
|
|
|
|
@default_serializers
|
|
|
|
else
|
|
|
|
@default_serializers = args
|
|
|
|
end
|
|
|
|
end
|
2009-11-03 06:35:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'DeviseMailer.sender can be configured through Devise' do
|
|
|
|
swap DeviseMailer, :sender => "foo@bar" do
|
|
|
|
assert_equal "foo@bar", DeviseMailer.sender
|
2009-11-06 06:40:38 -05:00
|
|
|
Devise.mailer_sender = "bar@foo"
|
2009-11-03 06:35:11 -05:00
|
|
|
assert_equal "bar@foo", DeviseMailer.sender
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'model options can be configured through Devise' do
|
|
|
|
swap Devise, :confirm_within => 113, :pepper => "foo" do
|
|
|
|
assert_equal 113, Devise.confirm_within
|
|
|
|
assert_equal "foo", Devise.pepper
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'setup block yields self' do
|
|
|
|
Devise.setup do |config|
|
|
|
|
assert_equal Devise, config
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'warden manager configuration' do
|
|
|
|
manager = MockManager.new
|
|
|
|
Devise.configure_warden_manager(manager)
|
|
|
|
|
2009-11-16 11:31:09 -05:00
|
|
|
assert_equal Devise::FailureApp, manager.failure_app
|
2009-11-13 16:26:33 -05:00
|
|
|
assert_equal [:authenticatable], manager.default_strategies
|
2009-11-03 06:35:11 -05:00
|
|
|
assert manager.silence_missing_strategies
|
|
|
|
end
|
|
|
|
|
2009-11-19 10:09:05 -05:00
|
|
|
test 'warden default scope is set' do
|
|
|
|
assert_equal :user, Warden::Manager.default_scope
|
|
|
|
end
|
|
|
|
|
2009-11-03 06:35:11 -05:00
|
|
|
test 'warden manager user configuration through a block' do
|
|
|
|
begin
|
|
|
|
@executed = false
|
|
|
|
Devise.warden do |manager|
|
|
|
|
@executed = true
|
|
|
|
assert_kind_of MockManager, manager
|
|
|
|
end
|
|
|
|
|
|
|
|
manager = MockManager.new
|
|
|
|
Devise.configure_warden_manager(manager)
|
|
|
|
assert @executed
|
|
|
|
ensure
|
|
|
|
Devise.clean_warden_config!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|