2010-03-26 06:27:19 -04:00
|
|
|
require 'test_helper'
|
2009-11-03 06:35:11 -05:00
|
|
|
|
|
|
|
module Devise
|
2010-03-28 08:51:03 -04:00
|
|
|
def self.yield_and_restore
|
2010-05-15 18:38:40 -04:00
|
|
|
@@warden_configured = nil
|
2010-03-28 08:51:03 -04:00
|
|
|
c, b = @@warden_config, @@warden_config_block
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
@@warden_config, @@warden_config_block = c, b
|
2009-11-03 06:35:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class DeviseTest < ActiveSupport::TestCase
|
|
|
|
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
|
|
|
|
|
2010-03-31 16:04:48 -04:00
|
|
|
test 'stores warden configuration' do
|
|
|
|
assert_equal Devise::FailureApp, Devise.warden_config.failure_app
|
|
|
|
assert_equal :user, Devise.warden_config.default_scope
|
2009-11-19 10:09:05 -05:00
|
|
|
end
|
|
|
|
|
2009-11-03 06:35:11 -05:00
|
|
|
test 'warden manager user configuration through a block' do
|
2010-03-28 08:51:03 -04:00
|
|
|
Devise.yield_and_restore do
|
2009-11-03 06:35:11 -05:00
|
|
|
@executed = false
|
2010-01-05 07:44:13 -05:00
|
|
|
Devise.warden do |config|
|
2009-11-03 06:35:11 -05:00
|
|
|
@executed = true
|
2010-01-05 07:44:13 -05:00
|
|
|
assert_kind_of Warden::Config, config
|
2009-11-03 06:35:11 -05:00
|
|
|
end
|
|
|
|
|
2010-03-31 16:04:48 -04:00
|
|
|
Devise.configure_warden!
|
2009-11-03 06:35:11 -05:00
|
|
|
assert @executed
|
|
|
|
end
|
|
|
|
end
|
2010-01-20 19:19:36 -05:00
|
|
|
|
|
|
|
test 'add new module using the helper method' do
|
|
|
|
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
|
|
|
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
|
|
|
assert_not Devise::STRATEGIES.include?(:coconut)
|
|
|
|
assert_not defined?(Devise::Models::Coconut)
|
|
|
|
Devise::ALL.delete(:coconut)
|
|
|
|
|
2010-03-28 08:51:03 -04:00
|
|
|
assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) }
|
|
|
|
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
2010-01-20 19:19:36 -05:00
|
|
|
Devise::ALL.delete(:banana)
|
|
|
|
Devise::STRATEGIES.delete(:banana)
|
|
|
|
|
|
|
|
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
|
2010-03-03 05:57:23 -05:00
|
|
|
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
2010-01-20 19:19:36 -05:00
|
|
|
Devise::ALL.delete(:kivi)
|
2010-03-03 05:57:23 -05:00
|
|
|
Devise::CONTROLLERS.delete(:kivi)
|
2010-01-20 19:19:36 -05:00
|
|
|
|
|
|
|
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
|
|
|
|
assert defined?(Devise::Models::AuthenticatableAgain)
|
|
|
|
end
|
2009-11-03 06:35:11 -05:00
|
|
|
end
|