2010-03-26 06:27:19 -04:00
|
|
|
require 'test_helper'
|
2009-10-12 07:37:42 -04:00
|
|
|
|
2010-07-02 02:12:00 -04:00
|
|
|
class FakeRequest < Struct.new(:path_info, :params)
|
|
|
|
end
|
|
|
|
|
2009-11-03 06:35:11 -05:00
|
|
|
class MappingTest < ActiveSupport::TestCase
|
2010-07-02 02:12:00 -04:00
|
|
|
def fake_request(path, params={})
|
|
|
|
FakeRequest.new(path, params)
|
|
|
|
end
|
2009-10-12 07:37:42 -04:00
|
|
|
|
|
|
|
test 'store options' do
|
2009-10-12 20:49:51 -04:00
|
|
|
mapping = Devise.mappings[:user]
|
|
|
|
assert_equal User, mapping.to
|
2010-03-03 05:57:23 -05:00
|
|
|
assert_equal User.devise_modules, mapping.modules
|
2010-11-20 15:41:26 -05:00
|
|
|
assert_equal "users", mapping.scoped_path
|
2010-04-15 02:21:13 -04:00
|
|
|
assert_equal :user, mapping.singular
|
2010-07-05 19:27:20 -04:00
|
|
|
assert_equal "users", mapping.path
|
2010-11-20 15:41:26 -05:00
|
|
|
assert_equal "/users", mapping.fullpath
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'store options with namespace' do
|
|
|
|
mapping = Devise.mappings[:publisher_account]
|
|
|
|
assert_equal Admin, mapping.to
|
|
|
|
assert_equal "publisher/accounts", mapping.scoped_path
|
|
|
|
assert_equal :publisher_account, mapping.singular
|
|
|
|
assert_equal "accounts", mapping.path
|
|
|
|
assert_equal "/publisher/accounts", mapping.fullpath
|
2009-10-12 07:37:42 -04:00
|
|
|
end
|
|
|
|
|
2010-04-15 02:21:13 -04:00
|
|
|
test 'allows path to be given' do
|
2010-07-05 19:27:20 -04:00
|
|
|
assert_equal "admin_area", Devise.mappings[:admin].path
|
2009-10-12 07:37:42 -04:00
|
|
|
end
|
2009-10-12 07:49:28 -04:00
|
|
|
|
2010-08-12 17:46:00 -04:00
|
|
|
test 'sign_out_via defaults to :get' do
|
|
|
|
assert_equal :get, Devise.mappings[:user].sign_out_via
|
|
|
|
end
|
|
|
|
|
|
|
|
test 'allows custom sign_out_via to be given' do
|
|
|
|
assert_equal :delete, Devise.mappings[:sign_out_via_delete].sign_out_via
|
|
|
|
assert_equal :post, Devise.mappings[:sign_out_via_post].sign_out_via
|
|
|
|
assert_equal [:delete, :post], Devise.mappings[:sign_out_via_delete_or_post].sign_out_via
|
|
|
|
end
|
|
|
|
|
2010-04-15 02:21:13 -04:00
|
|
|
test 'allows custom singular to be given' do
|
2010-07-05 19:27:20 -04:00
|
|
|
assert_equal "accounts", Devise.mappings[:manager].path
|
2009-10-12 07:49:28 -04:00
|
|
|
end
|
2009-10-12 08:56:12 -04:00
|
|
|
|
2010-03-28 08:51:03 -04:00
|
|
|
test 'has strategies depending on the model declaration' do
|
2010-03-29 14:52:34 -04:00
|
|
|
assert_equal [:rememberable, :token_authenticatable, :database_authenticatable], Devise.mappings[:user].strategies
|
2010-09-25 06:04:38 -04:00
|
|
|
assert_equal [:rememberable, :database_authenticatable], Devise.mappings[:admin].strategies
|
2010-03-28 08:51:03 -04:00
|
|
|
end
|
|
|
|
|
2009-11-16 12:07:01 -05:00
|
|
|
test 'find scope for a given object' do
|
|
|
|
assert_equal :user, Devise::Mapping.find_scope!(User)
|
|
|
|
assert_equal :user, Devise::Mapping.find_scope!(:user)
|
|
|
|
assert_equal :user, Devise::Mapping.find_scope!(User.new)
|
|
|
|
end
|
|
|
|
|
2010-03-26 05:19:31 -04:00
|
|
|
test 'find scope works with single table inheritance' do
|
|
|
|
assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))
|
|
|
|
assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
|
|
|
|
end
|
|
|
|
|
2009-11-16 12:07:01 -05:00
|
|
|
test 'find scope raises an error if cannot be found' do
|
2009-11-15 12:14:08 -05:00
|
|
|
assert_raise RuntimeError do
|
2009-11-16 12:07:01 -05:00
|
|
|
Devise::Mapping.find_scope!(String)
|
2009-11-15 12:14:08 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-10-16 19:46:06 -04:00
|
|
|
test 'return default path names' do
|
|
|
|
mapping = Devise.mappings[:user]
|
2010-02-08 08:03:15 -05:00
|
|
|
assert_equal 'sign_in', mapping.path_names[:sign_in]
|
|
|
|
assert_equal 'sign_out', mapping.path_names[:sign_out]
|
|
|
|
assert_equal 'password', mapping.path_names[:password]
|
2009-10-16 19:46:06 -04:00
|
|
|
assert_equal 'confirmation', mapping.path_names[:confirmation]
|
2010-02-16 11:00:36 -05:00
|
|
|
assert_equal 'sign_up', mapping.path_names[:sign_up]
|
2010-02-08 08:03:15 -05:00
|
|
|
assert_equal 'unlock', mapping.path_names[:unlock]
|
2009-10-16 19:46:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'allow custom path names to be given' do
|
2009-12-21 09:29:58 -05:00
|
|
|
mapping = Devise.mappings[:manager]
|
2010-02-08 08:03:15 -05:00
|
|
|
assert_equal 'login', mapping.path_names[:sign_in]
|
|
|
|
assert_equal 'logout', mapping.path_names[:sign_out]
|
|
|
|
assert_equal 'secret', mapping.path_names[:password]
|
2009-10-16 19:46:06 -04:00
|
|
|
assert_equal 'verification', mapping.path_names[:confirmation]
|
2010-02-08 08:03:15 -05:00
|
|
|
assert_equal 'register', mapping.path_names[:sign_up]
|
|
|
|
assert_equal 'unblock', mapping.path_names[:unlock]
|
2009-10-16 19:46:06 -04:00
|
|
|
end
|
|
|
|
|
2009-10-12 20:06:39 -04:00
|
|
|
test 'magic predicates' do
|
2009-10-12 20:49:51 -04:00
|
|
|
mapping = Devise.mappings[:user]
|
2009-10-30 06:29:10 -04:00
|
|
|
assert mapping.authenticatable?
|
2009-10-12 20:06:39 -04:00
|
|
|
assert mapping.confirmable?
|
2009-10-12 20:49:51 -04:00
|
|
|
assert mapping.recoverable?
|
2009-10-19 22:31:33 -04:00
|
|
|
assert mapping.rememberable?
|
2010-02-16 11:00:36 -05:00
|
|
|
assert mapping.registerable?
|
2009-10-12 20:49:51 -04:00
|
|
|
|
|
|
|
mapping = Devise.mappings[:admin]
|
2009-10-30 06:29:10 -04:00
|
|
|
assert mapping.authenticatable?
|
2010-03-12 03:54:57 -05:00
|
|
|
assert mapping.recoverable?
|
2010-07-12 01:24:21 -04:00
|
|
|
assert mapping.lockable?
|
2009-10-12 20:49:51 -04:00
|
|
|
assert_not mapping.confirmable?
|
2010-10-14 18:44:21 -04:00
|
|
|
assert_not mapping.omniauthable?
|
2009-10-12 20:06:39 -04:00
|
|
|
end
|
2010-10-29 16:43:38 -04:00
|
|
|
|
|
|
|
test 'find mapping by path' do
|
|
|
|
assert_raise RuntimeError do
|
|
|
|
Devise::Mapping.find_by_path!('/accounts/facebook/callback')
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
Devise::Mapping.find_by_path!('/:locale/accounts/login')
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
Devise::Mapping.find_by_path!('/accounts/facebook/callback', :path)
|
|
|
|
end
|
|
|
|
end
|
2009-10-12 07:37:42 -04:00
|
|
|
end
|