1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/test/mapping_test.rb

121 lines
4.2 KiB
Ruby
Raw Normal View History

require 'test_helper'
2009-10-12 07:37:42 -04:00
class MappingTest < ActiveSupport::TestCase
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
assert_equal User.devise_modules, mapping.modules
assert_equal :users, mapping.plural
assert_equal :user, mapping.singular
assert_equal :users, mapping.path
2009-10-12 07:37:42 -04:00
end
test 'allows path to be given' do
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
test 'allows custom singular to be given' do
assert_equal :accounts, Devise.mappings[:manager].path
2009-10-18 10:08:07 -04:00
end
2009-10-12 07:49:28 -04:00
test 'allows a controller depending on the mapping' do
allowed = Devise.mappings[:user].allowed_controllers
assert allowed.include?("devise/sessions")
assert allowed.include?("devise/confirmations")
assert allowed.include?("devise/passwords")
allowed = Devise.mappings[:admin].allowed_controllers
assert allowed.include?("sessions")
assert_not allowed.include?("devise/confirmations")
assert_not allowed.include?("devise/unlocks")
2009-10-12 07:49:28 -04:00
end
2009-10-12 08:56:12 -04:00
test 'has strategies depending on the model declaration' do
assert_equal [:rememberable, :token_authenticatable, :database_authenticatable], Devise.mappings[:user].strategies
assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies
end
2009-11-15 12:14:08 -05:00
test 'find mapping by path' do
assert_nil Devise::Mapping.find_by_path("/foo/bar")
assert_equal Devise.mappings[:user], Devise::Mapping.find_by_path("/users/session")
2009-10-12 08:56:12 -04:00
end
2009-11-15 12:14:08 -05:00
test 'find mapping by customized path' do
assert_equal Devise.mappings[:admin], Devise::Mapping.find_by_path("/admin_area/session")
2009-10-12 08:56:12 -04:00
end
2009-10-12 20:06:39 -04: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
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
test 'find scope raises an error if cannot be found' do
2009-11-15 12:14:08 -05:00
assert_raise RuntimeError do
Devise::Mapping.find_scope!(String)
2009-11-15 12:14:08 -05:00
end
end
test 'return default path names' do
mapping = Devise.mappings[:user]
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]
assert_equal 'confirmation', mapping.path_names[:confirmation]
assert_equal 'sign_up', mapping.path_names[:sign_up]
assert_equal 'unlock', mapping.path_names[:unlock]
end
test 'allow custom path names to be given' do
2009-12-21 09:29:58 -05:00
mapping = Devise.mappings[:manager]
assert_equal 'login', mapping.path_names[:sign_in]
assert_equal 'logout', mapping.path_names[:sign_out]
assert_equal 'secret', mapping.path_names[:password]
assert_equal 'verification', mapping.path_names[:confirmation]
assert_equal 'register', mapping.path_names[:sign_up]
assert_equal 'unblock', mapping.path_names[:unlock]
end
test 'has an empty path as default path prefix' do
2009-12-21 09:29:58 -05:00
mapping = Devise.mappings[:user]
assert_equal '/', mapping.path_prefix
end
test 'allow path prefix to be configured' do
mapping = Devise.mappings[:manager]
assert_equal '/:locale/', mapping.path_prefix
end
test 'retrieve as from the proper position' do
assert_equal 1, Devise.mappings[:user].segment_position
assert_equal 2, Devise.mappings[:manager].segment_position
end
test 'path is returned with path prefix and as' do
assert_equal '/users', Devise.mappings[:user].full_path
assert_equal '/:locale/accounts', Devise.mappings[:manager].full_path
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]
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?
assert mapping.registerable?
2009-10-12 20:49:51 -04:00
mapping = Devise.mappings[:admin]
assert mapping.authenticatable?
assert mapping.recoverable?
2009-10-12 20:49:51 -04:00
assert_not mapping.confirmable?
assert_not mapping.lockable?
2009-10-19 22:31:33 -04:00
assert_not mapping.rememberable?
2009-10-12 20:06:39 -04:00
end
2009-10-12 07:37:42 -04:00
end