2009-10-09 20:11:58 -04:00
|
|
|
require 'test/test_helper'
|
2009-10-09 08:03:01 -04:00
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
class Authenticable < User
|
2009-10-09 09:46:24 -04:00
|
|
|
devise
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
class Confirmable < User
|
2009-10-09 09:46:24 -04:00
|
|
|
devise :confirmable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
class Recoverable < User
|
2009-10-09 09:46:24 -04:00
|
|
|
devise :recoverable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
class Rememberable < User
|
|
|
|
devise :rememberable
|
|
|
|
end
|
|
|
|
|
|
|
|
class Validatable < User
|
2009-10-09 09:46:24 -04:00
|
|
|
devise :validatable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
class Devisable < User
|
2009-10-09 09:46:24 -04:00
|
|
|
devise :all
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
class Exceptable < User
|
|
|
|
devise :all, :except => [:recoverable, :rememberable, :validatable]
|
|
|
|
end
|
|
|
|
|
|
|
|
class Configurable < User
|
2009-10-22 07:49:19 -04:00
|
|
|
devise :all, :stretches => 15,
|
|
|
|
:pepper => 'abcdef',
|
2009-10-30 05:23:47 -04:00
|
|
|
:confirm_within => 5.days,
|
2009-10-22 07:49:19 -04:00
|
|
|
:remember_for => 7.days
|
2009-10-20 09:08:40 -04:00
|
|
|
end
|
|
|
|
|
2009-10-09 20:11:58 -04:00
|
|
|
class ActiveRecordTest < ActiveSupport::TestCase
|
2009-10-09 08:03:01 -04:00
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
def assert_not_include_modules(klass, *modules)
|
|
|
|
modules.each do |mod|
|
|
|
|
assert_not include_module?(klass, mod)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-30 06:29:10 -04:00
|
|
|
test 'include by default authenticatable only' do
|
|
|
|
assert_include_modules Authenticable, :authenticatable
|
2009-10-20 09:08:40 -04:00
|
|
|
assert_not_include_modules Authenticable, :confirmable, :recoverable, :rememberable, :validatable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'add confirmable module only' do
|
2009-10-30 06:29:10 -04:00
|
|
|
assert_include_modules Confirmable, :authenticatable, :confirmable
|
2009-10-20 09:08:40 -04:00
|
|
|
assert_not_include_modules Confirmable, :recoverable, :rememberable, :validatable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'add recoverable module only' do
|
2009-10-30 06:29:10 -04:00
|
|
|
assert_include_modules Recoverable, :authenticatable, :recoverable
|
2009-10-20 09:08:40 -04:00
|
|
|
assert_not_include_modules Recoverable, :confirmable, :rememberable, :validatable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'add rememberable module only' do
|
2009-10-30 06:29:10 -04:00
|
|
|
assert_include_modules Rememberable, :authenticatable, :rememberable
|
2009-10-20 09:08:40 -04:00
|
|
|
assert_not_include_modules Rememberable, :confirmable, :recoverable, :validatable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'add validatable module only' do
|
2009-10-30 06:29:10 -04:00
|
|
|
assert_include_modules Validatable, :authenticatable, :validatable
|
2009-10-20 09:08:40 -04:00
|
|
|
assert_not_include_modules Validatable, :confirmable, :recoverable, :rememberable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'add all modules' do
|
|
|
|
assert_include_modules Devisable,
|
2009-10-30 06:29:10 -04:00
|
|
|
:authenticatable, :confirmable, :recoverable, :rememberable, :validatable
|
2009-10-09 08:03:01 -04:00
|
|
|
end
|
|
|
|
|
2009-10-20 09:08:40 -04:00
|
|
|
test 'configure modules with except option' do
|
2009-10-30 06:29:10 -04:00
|
|
|
assert_include_modules Exceptable, :authenticatable, :confirmable
|
2009-10-20 09:08:40 -04:00
|
|
|
assert_not_include_modules Exceptable, :recoverable, :rememberable, :validatable
|
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-10-22 07:49:19 -04:00
|
|
|
assert_equal 15, Configurable.new.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-10-22 07:49:19 -04:00
|
|
|
assert_equal 'abcdef', Configurable.new.pepper
|
|
|
|
end
|
|
|
|
|
2009-10-30 05:23:47 -04:00
|
|
|
test 'set a default value for confirm_within' do
|
|
|
|
assert_equal 5.days, Configurable.new.confirm_within
|
2009-10-22 07:49:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'set a default value for remember_for' do
|
|
|
|
assert_equal 7.days, Configurable.new.remember_for
|
2009-10-09 08:03:01 -04:00
|
|
|
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
|