2009-10-10 00:11:58 +00:00
|
|
|
require 'test/test_helper'
|
2009-10-09 12:03:01 +00:00
|
|
|
|
2009-11-23 01:22:41 +00:00
|
|
|
class Authenticatable < User
|
2009-11-23 01:14:45 +00:00
|
|
|
devise :authenticatable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
class Confirmable < User
|
2009-11-23 01:14:45 +00:00
|
|
|
devise :authenticatable, :confirmable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
class Recoverable < User
|
2009-11-23 01:14:45 +00:00
|
|
|
devise :authenticatable, :recoverable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
class Rememberable < User
|
2009-11-23 01:14:45 +00:00
|
|
|
devise :authenticatable, :rememberable
|
2009-10-20 13:08:40 +00:00
|
|
|
end
|
|
|
|
|
2009-11-24 17:18:42 +00:00
|
|
|
class Trackable < User
|
|
|
|
devise :authenticatable, :trackable
|
|
|
|
end
|
|
|
|
|
2009-11-23 00:19:29 +00:00
|
|
|
class Timeoutable < User
|
2009-11-23 01:22:41 +00:00
|
|
|
devise :authenticatable, :timeoutable
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
|
|
|
|
2009-12-30 17:19:33 +00:00
|
|
|
class Lockable < User
|
|
|
|
devise :authenticatable, :lockable
|
|
|
|
end
|
|
|
|
|
2009-12-21 14:29:58 +00:00
|
|
|
class IsValidatable < User
|
2009-11-23 01:14:45 +00:00
|
|
|
devise :authenticatable, :validatable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
class Devisable < User
|
2009-10-09 13:46:24 +00:00
|
|
|
devise :all
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
class Exceptable < User
|
2009-12-30 17:19:33 +00:00
|
|
|
devise :all, :except => [:recoverable, :rememberable, :validatable, :lockable]
|
2009-10-20 13:08:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class Configurable < User
|
2009-12-20 12:53:53 +00:00
|
|
|
devise :all, :timeoutable, :stretches => 15,
|
|
|
|
:pepper => 'abcdef',
|
|
|
|
:confirm_within => 5.days,
|
|
|
|
:remember_for => 7.days,
|
|
|
|
:timeout_in => 15.minutes
|
2009-10-20 13:08:40 +00:00
|
|
|
end
|
|
|
|
|
2009-10-10 00:11:58 +00:00
|
|
|
class ActiveRecordTest < ActiveSupport::TestCase
|
2009-10-20 13:08:40 +00: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 17:18:42 +00:00
|
|
|
(Devise::ALL - modules).each do |mod|
|
2009-10-20 13:08:40 +00:00
|
|
|
assert_not include_module?(klass, mod)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-12-20 12:53:53 +00:00
|
|
|
test 'add authenticatable module only' do
|
2009-11-23 00:19:29 +00:00
|
|
|
assert_include_modules Authenticatable, :authenticatable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'add confirmable module only' do
|
2009-10-30 10:29:10 +00:00
|
|
|
assert_include_modules Confirmable, :authenticatable, :confirmable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'add recoverable module only' do
|
2009-10-30 10:29:10 +00:00
|
|
|
assert_include_modules Recoverable, :authenticatable, :recoverable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'add rememberable module only' do
|
2009-10-30 10:29:10 +00:00
|
|
|
assert_include_modules Rememberable, :authenticatable, :rememberable
|
2009-11-24 17:18:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'add trackable module only' do
|
|
|
|
assert_include_modules Trackable, :authenticatable, :trackable
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'add timeoutable module only' do
|
|
|
|
assert_include_modules Timeoutable, :authenticatable, :timeoutable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-12-30 17:19:33 +00:00
|
|
|
test 'add lockable module only' do
|
|
|
|
assert_include_modules Lockable, :authenticatable, :lockable
|
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'add validatable module only' do
|
2009-12-21 14:29:58 +00:00
|
|
|
assert_include_modules IsValidatable, :authenticatable, :validatable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'add all modules' do
|
|
|
|
assert_include_modules Devisable,
|
2010-01-09 13:41:28 +00:00
|
|
|
:authenticatable, :confirmable, :recoverable, :rememberable, :trackable, :validatable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'configure modules with except option' do
|
2009-12-20 12:53:53 +00:00
|
|
|
assert_include_modules Exceptable, :authenticatable, :confirmable, :trackable
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'set a default value for stretches' do
|
2009-11-23 00:32:54 +00:00
|
|
|
assert_equal 15, Configurable.stretches
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
|
|
|
|
2009-10-20 13:08:40 +00:00
|
|
|
test 'set a default value for pepper' do
|
2009-11-23 00:32:54 +00:00
|
|
|
assert_equal 'abcdef', Configurable.pepper
|
2009-10-22 11:49:19 +00:00
|
|
|
end
|
|
|
|
|
2009-10-30 09:23:47 +00:00
|
|
|
test 'set a default value for confirm_within' do
|
2009-11-23 00:32:54 +00:00
|
|
|
assert_equal 5.days, Configurable.confirm_within
|
2009-10-22 11:49:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'set a default value for remember_for' do
|
2009-11-23 00:32:54 +00:00
|
|
|
assert_equal 7.days, Configurable.remember_for
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|
2009-10-22 21:26:10 +00:00
|
|
|
|
2009-11-25 02:11:49 +00:00
|
|
|
test 'set a default value for timeout_in' do
|
|
|
|
assert_equal 15.minutes, Configurable.timeout_in
|
2009-11-23 00:19:29 +00:00
|
|
|
end
|
|
|
|
|
2009-10-22 21:26:10 +00:00
|
|
|
test 'set null fields on migrations' do
|
|
|
|
Admin.create!
|
|
|
|
end
|
2009-10-09 12:03:01 +00:00
|
|
|
end
|