2010-03-26 06:27:19 -04:00
|
|
|
require 'test_helper'
|
2009-10-09 08:03:01 -04:00
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
class Configurable < User
|
2010-04-15 02:43:39 -04:00
|
|
|
devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,
|
2010-01-13 13:51:20 -05:00
|
|
|
:stretches => 15, :pepper => 'abcdef', :confirm_within => 5.days,
|
|
|
|
:remember_for => 7.days, :timeout_in => 15.minutes, :unlock_in => 10.days
|
2009-10-20 09:08:40 -04:00
|
|
|
end
|
|
|
|
|
2010-04-15 02:34:49 -04:00
|
|
|
class Inheritable < Admin
|
|
|
|
end
|
|
|
|
|
2009-10-09 20:11:58 -04:00
|
|
|
class ActiveRecordTest < ActiveSupport::TestCase
|
2009-10-20 09:08:40 -04:00
|
|
|
def include_module?(klass, mod)
|
|
|
|
klass.devise_modules.include?(mod) &&
|
|
|
|
klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_include_modules(klass, *modules)
|
|
|
|
modules.each do |mod|
|
|
|
|
assert include_module?(klass, mod)
|
|
|
|
end
|
|
|
|
|
2009-11-24 12:18:42 -05:00
|
|
|
(Devise::ALL - modules).each do |mod|
|
2009-10-20 09:08:40 -04:00
|
|
|
assert_not include_module?(klass, mod)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-04-15 02:34:49 -04:00
|
|
|
test 'can cherry pick modules' do
|
2010-09-25 06:04:38 -04:00
|
|
|
assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable
|
2010-03-25 08:29:09 -04:00
|
|
|
end
|
|
|
|
|
2010-04-15 02:34:49 -04:00
|
|
|
test 'chosen modules are inheritable' do
|
2010-09-25 06:04:38 -04:00
|
|
|
assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :rememberable
|
2010-04-15 02:34:49 -04:00
|
|
|
end
|
|
|
|
|
2010-03-25 08:29:09 -04:00
|
|
|
test 'order of module inclusion' do
|
2010-09-25 06:04:38 -04:00
|
|
|
correct_module_order = [:database_authenticatable, :rememberable, :recoverable, :registerable, :lockable, :timeoutable]
|
|
|
|
incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :rememberable]
|
2010-03-25 08:29:09 -04:00
|
|
|
|
|
|
|
assert_include_modules Admin, *incorrect_module_order
|
|
|
|
|
|
|
|
# get module constants from symbol list
|
|
|
|
module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }
|
|
|
|
|
|
|
|
# confirm that they adhere to the order in ALL
|
|
|
|
# get included modules, filter out the noise, and reverse the order
|
|
|
|
assert_equal module_constants, (Admin.included_modules & module_constants).reverse
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'set a default value for stretches' do
|
2009-11-22 19:32:54 -05:00
|
|
|
assert_equal 15, Configurable.stretches
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'set a default value for pepper' do
|
2009-11-22 19:32:54 -05:00
|
|
|
assert_equal 'abcdef', Configurable.pepper
|
2009-10-22 07:49:19 -04:00
|
|
|
end
|
|
|
|
|
2009-10-30 05:23:47 -04:00
|
|
|
test 'set a default value for confirm_within' do
|
2009-11-22 19:32:54 -05:00
|
|
|
assert_equal 5.days, Configurable.confirm_within
|
2009-10-22 07:49:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'set a default value for remember_for' do
|
2009-11-22 19:32:54 -05:00
|
|
|
assert_equal 7.days, Configurable.remember_for
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
2009-10-22 17:26:10 -04:00
|
|
|
|
2009-11-24 21:11:49 -05:00
|
|
|
test 'set a default value for timeout_in' do
|
|
|
|
assert_equal 15.minutes, Configurable.timeout_in
|
2009-11-22 19:19:29 -05:00
|
|
|
end
|
|
|
|
|
2010-01-13 13:51:20 -05:00
|
|
|
test 'set a default value for unlock_in' do
|
|
|
|
assert_equal 10.days, Configurable.unlock_in
|
|
|
|
end
|
|
|
|
|
2009-10-22 17:26:10 -04:00
|
|
|
test 'set null fields on migrations' do
|
|
|
|
Admin.create!
|
|
|
|
end
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|