mongoid-devise 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.rdoc +333 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +260 -0
- data/Rakefile +53 -0
- data/TODO +2 -0
- data/app/controllers/confirmations_controller.rb +33 -0
- data/app/controllers/passwords_controller.rb +42 -0
- data/app/controllers/registrations_controller.rb +55 -0
- data/app/controllers/sessions_controller.rb +45 -0
- data/app/controllers/unlocks_controller.rb +33 -0
- data/app/models/devise_mailer.rb +68 -0
- data/app/views/confirmations/new.html.erb +12 -0
- data/app/views/devise_mailer/confirmation_instructions.html.erb +5 -0
- data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
- data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
- data/app/views/passwords/edit.html.erb +16 -0
- data/app/views/passwords/new.html.erb +12 -0
- data/app/views/registrations/edit.html.erb +25 -0
- data/app/views/registrations/new.html.erb +17 -0
- data/app/views/sessions/new.html.erb +17 -0
- data/app/views/shared/_devise_links.erb +19 -0
- data/app/views/unlocks/new.html.erb +12 -0
- data/generators/devise/USAGE +5 -0
- data/generators/devise/devise_generator.rb +15 -0
- data/generators/devise/lib/route_devise.rb +32 -0
- data/generators/devise/templates/migration.rb +23 -0
- data/generators/devise/templates/model.rb +9 -0
- data/generators/devise_install/USAGE +3 -0
- data/generators/devise_install/devise_install_generator.rb +15 -0
- data/generators/devise_install/templates/README +18 -0
- data/generators/devise_install/templates/devise.rb +102 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +21 -0
- data/init.rb +2 -0
- data/lib/devise.rb +253 -0
- data/lib/devise/controllers/helpers.rb +200 -0
- data/lib/devise/controllers/internal_helpers.rb +129 -0
- data/lib/devise/controllers/url_helpers.rb +41 -0
- data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
- data/lib/devise/encryptors/base.rb +20 -0
- data/lib/devise/encryptors/bcrypt.rb +21 -0
- data/lib/devise/encryptors/clearance_sha1.rb +19 -0
- data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
- data/lib/devise/encryptors/sha1.rb +27 -0
- data/lib/devise/encryptors/sha512.rb +27 -0
- data/lib/devise/failure_app.rb +65 -0
- data/lib/devise/hooks/activatable.rb +15 -0
- data/lib/devise/hooks/rememberable.rb +30 -0
- data/lib/devise/hooks/timeoutable.rb +18 -0
- data/lib/devise/hooks/trackable.rb +18 -0
- data/lib/devise/locales/en.yml +35 -0
- data/lib/devise/mapping.rb +131 -0
- data/lib/devise/models.rb +112 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/authenticatable.rb +146 -0
- data/lib/devise/models/confirmable.rb +172 -0
- data/lib/devise/models/http_authenticatable.rb +21 -0
- data/lib/devise/models/lockable.rb +160 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +94 -0
- data/lib/devise/models/timeoutable.rb +28 -0
- data/lib/devise/models/token_authenticatable.rb +89 -0
- data/lib/devise/models/trackable.rb +16 -0
- data/lib/devise/models/validatable.rb +48 -0
- data/lib/devise/orm/active_record.rb +41 -0
- data/lib/devise/orm/data_mapper.rb +83 -0
- data/lib/devise/orm/mongo_mapper.rb +51 -0
- data/lib/devise/orm/mongoid.rb +60 -0
- data/lib/devise/rails.rb +14 -0
- data/lib/devise/rails/routes.rb +125 -0
- data/lib/devise/rails/warden_compat.rb +25 -0
- data/lib/devise/schema.rb +65 -0
- data/lib/devise/strategies/authenticatable.rb +36 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/http_authenticatable.rb +49 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +86 -0
- data/lib/devise/version.rb +3 -0
- data/test/controllers/helpers_test.rb +177 -0
- data/test/controllers/internal_helpers_test.rb +55 -0
- data/test/controllers/url_helpers_test.rb +47 -0
- data/test/devise_test.rb +69 -0
- data/test/encryptors_test.rb +31 -0
- data/test/failure_app_test.rb +44 -0
- data/test/integration/authenticatable_test.rb +271 -0
- data/test/integration/confirmable_test.rb +97 -0
- data/test/integration/http_authenticatable_test.rb +44 -0
- data/test/integration/lockable_test.rb +83 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +130 -0
- data/test/integration/rememberable_test.rb +63 -0
- data/test/integration/timeoutable_test.rb +68 -0
- data/test/integration/token_authenticatable_test.rb +55 -0
- data/test/integration/trackable_test.rb +64 -0
- data/test/mailers/confirmation_instructions_test.rb +80 -0
- data/test/mailers/reset_password_instructions_test.rb +68 -0
- data/test/mailers/unlock_instructions_test.rb +62 -0
- data/test/mapping_test.rb +153 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +228 -0
- data/test/models/lockable_test.rb +202 -0
- data/test/models/recoverable_test.rb +138 -0
- data/test/models/rememberable_test.rb +135 -0
- data/test/models/timeoutable_test.rb +28 -0
- data/test/models/token_authenticatable_test.rb +51 -0
- data/test/models/trackable_test.rb +5 -0
- data/test/models/validatable_test.rb +106 -0
- data/test/models_test.rb +56 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -0
- data/test/orm/mongoid.rb +22 -0
- data/test/rails_app/app/active_record/admin.rb +7 -0
- data/test/rails_app/app/active_record/user.rb +7 -0
- data/test/rails_app/app/controllers/admins_controller.rb +6 -0
- data/test/rails_app/app/controllers/application_controller.rb +10 -0
- data/test/rails_app/app/controllers/home_controller.rb +4 -0
- data/test/rails_app/app/controllers/users_controller.rb +16 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/mongo_mapper/admin.rb +9 -0
- data/test/rails_app/app/mongo_mapper/user.rb +8 -0
- data/test/rails_app/app/mongoid/admin.rb +9 -0
- data/test/rails_app/app/mongoid/user.rb +8 -0
- data/test/rails_app/config/boot.rb +110 -0
- data/test/rails_app/config/environment.rb +42 -0
- data/test/rails_app/config/environments/development.rb +17 -0
- data/test/rails_app/config/environments/production.rb +28 -0
- data/test/rails_app/config/environments/test.rb +28 -0
- data/test/rails_app/config/initializers/devise.rb +79 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
- data/test/rails_app/config/initializers/session_store.rb +15 -0
- data/test/rails_app/config/routes.rb +21 -0
- data/test/routes_test.rb +110 -0
- data/test/support/assertions_helper.rb +37 -0
- data/test/support/integration_tests_helper.rb +71 -0
- data/test/support/test_silencer.rb +5 -0
- data/test/support/tests_helper.rb +39 -0
- data/test/test_helper.rb +21 -0
- data/test/test_helpers_test.rb +57 -0
- metadata +216 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'devise/strategies/base'
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
module Strategies
|
|
5
|
+
# Remember the user through the remember token. This strategy is responsible
|
|
6
|
+
# to verify whether there is a cookie with the remember token, and to
|
|
7
|
+
# recreate the user from this cookie if it exists. Must be called *before*
|
|
8
|
+
# authenticatable.
|
|
9
|
+
class Rememberable < Devise::Strategies::Base
|
|
10
|
+
|
|
11
|
+
# A valid strategy for rememberable needs a remember token in the cookies.
|
|
12
|
+
def valid?
|
|
13
|
+
remember_me_cookie.present? && mapping.to.respond_to?(:serialize_from_cookie)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# To authenticate a user we deserialize the cookie and attempt finding
|
|
17
|
+
# the record in the database. If the attempt fails, we pass to another
|
|
18
|
+
# strategy handle the authentication.
|
|
19
|
+
def authenticate!
|
|
20
|
+
if resource = mapping.to.serialize_from_cookie(remember_me_cookie)
|
|
21
|
+
success!(resource)
|
|
22
|
+
else
|
|
23
|
+
pass
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# Accessor for remember cookie
|
|
30
|
+
def remember_me_cookie
|
|
31
|
+
@remember_me_cookie ||= request.cookies["remember_#{mapping.name}_token"]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
Warden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require 'devise/strategies/base'
|
|
2
|
+
|
|
3
|
+
module Devise
|
|
4
|
+
module Strategies
|
|
5
|
+
# Strategy for signing in a user, based on a authenticatable token.
|
|
6
|
+
# Redirects to sign_in page if it's not authenticated.
|
|
7
|
+
class TokenAuthenticatable < Base
|
|
8
|
+
def valid?
|
|
9
|
+
mapping.to.respond_to?(:authenticate_with_token) && authentication_token(scope).present?
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Authenticate a user based on authenticatable token params, returning to warden
|
|
13
|
+
# success and the authenticated user if everything is okay. Otherwise redirect
|
|
14
|
+
# to sign in page.
|
|
15
|
+
def authenticate!
|
|
16
|
+
if resource = mapping.to.authenticate_with_token(params[scope] || params)
|
|
17
|
+
success!(resource)
|
|
18
|
+
else
|
|
19
|
+
fail!(:invalid_token)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
# Detect authentication token in params: scoped or not.
|
|
26
|
+
def authentication_token(scope)
|
|
27
|
+
if params[scope]
|
|
28
|
+
params[scope][mapping.to.token_authentication_key]
|
|
29
|
+
else
|
|
30
|
+
params[mapping.to.token_authentication_key]
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
Warden::Strategies.add(:token_authenticatable, Devise::Strategies::TokenAuthenticatable)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module Devise
|
|
2
|
+
module TestHelpers
|
|
3
|
+
def self.included(base)
|
|
4
|
+
base.class_eval do
|
|
5
|
+
setup :setup_controller_for_warden, :warden if respond_to?(:setup)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# This is a Warden::Proxy customized for functional tests. It's meant to
|
|
10
|
+
# some of Warden::Manager responsibilities, as retrieving configuration
|
|
11
|
+
# options and calling the FailureApp.
|
|
12
|
+
class TestWarden < Warden::Proxy #:nodoc:
|
|
13
|
+
attr_reader :controller
|
|
14
|
+
|
|
15
|
+
def initialize(controller)
|
|
16
|
+
@controller = controller
|
|
17
|
+
manager = Warden::Manager.new(nil) do |config|
|
|
18
|
+
Devise.configure_warden(config)
|
|
19
|
+
end
|
|
20
|
+
super(controller.request.env, manager)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def authenticate!(*args)
|
|
24
|
+
catch_with_redirect { super }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def catch_with_redirect(&block)
|
|
28
|
+
result = catch(:warden, &block)
|
|
29
|
+
|
|
30
|
+
if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
|
|
31
|
+
result[:action] ||= :unauthenticated
|
|
32
|
+
|
|
33
|
+
env = @controller.request.env
|
|
34
|
+
env["PATH_INFO"] = "/#{result[:action]}"
|
|
35
|
+
env["warden.options"] = result
|
|
36
|
+
Warden::Manager._before_failure.each{ |hook| hook.call(env, result) }
|
|
37
|
+
|
|
38
|
+
status, headers, body = Devise::FailureApp.call(env).to_a
|
|
39
|
+
@controller.send :redirect_to, headers["Location"]
|
|
40
|
+
else
|
|
41
|
+
result
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# We need to setup the environment variables and the response in the controller.
|
|
47
|
+
def setup_controller_for_warden #:nodoc:
|
|
48
|
+
@request.env['action_controller.rescue.request'] = @request
|
|
49
|
+
@request.env['action_controller.rescue.response'] = @response
|
|
50
|
+
@request.env['rack.session'] = session
|
|
51
|
+
@controller.response = @response
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Quick access to Warden::Proxy.
|
|
55
|
+
def warden #:nodoc:
|
|
56
|
+
@warden ||= (@request.env['warden'] = TestWarden.new(@controller))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# sign_in a given resource by storing its keys in the session.
|
|
60
|
+
#
|
|
61
|
+
# Examples:
|
|
62
|
+
#
|
|
63
|
+
# sign_in :user, @user # sign_in(scope, resource)
|
|
64
|
+
# sign_in @user # sign_in(resource)
|
|
65
|
+
#
|
|
66
|
+
def sign_in(resource_or_scope, resource=nil)
|
|
67
|
+
scope ||= Devise::Mapping.find_scope!(resource_or_scope)
|
|
68
|
+
resource ||= resource_or_scope
|
|
69
|
+
warden.session_serializer.store(resource, scope)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Sign out a given resource or scope by calling logout on Warden.
|
|
73
|
+
#
|
|
74
|
+
# Examples:
|
|
75
|
+
#
|
|
76
|
+
# sign_out :user # sign_out(scope)
|
|
77
|
+
# sign_out @user # sign_out(resource)
|
|
78
|
+
#
|
|
79
|
+
def sign_out(resource_or_scope)
|
|
80
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
|
81
|
+
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
|
82
|
+
warden.logout(scope)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
require 'test/test_helper'
|
|
2
|
+
require 'ostruct'
|
|
3
|
+
|
|
4
|
+
class MockController < ApplicationController
|
|
5
|
+
attr_accessor :env
|
|
6
|
+
|
|
7
|
+
def request
|
|
8
|
+
self
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def path
|
|
12
|
+
''
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class ControllerAuthenticableTest < ActionController::TestCase
|
|
17
|
+
tests MockController
|
|
18
|
+
|
|
19
|
+
def setup
|
|
20
|
+
@controller = MockController.new
|
|
21
|
+
@mock_warden = OpenStruct.new
|
|
22
|
+
@controller.env = { 'warden' => @mock_warden }
|
|
23
|
+
@controller.session = {}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
test 'setup warden' do
|
|
27
|
+
assert_not_nil @controller.warden
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test 'provide access to warden instance' do
|
|
31
|
+
assert_equal @controller.warden, @controller.env['warden']
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
test 'proxy signed_in? to authenticated' do
|
|
35
|
+
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
|
|
36
|
+
@controller.signed_in?(:my_scope)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
test 'proxy current_admin to authenticate with admin scope' do
|
|
40
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
|
41
|
+
@controller.current_admin
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
test 'proxy current_user to authenticate with user scope' do
|
|
45
|
+
@mock_warden.expects(:authenticate).with(:scope => :user)
|
|
46
|
+
@controller.current_user
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
test 'proxy user_authenticate! to authenticate with user scope' do
|
|
50
|
+
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
|
51
|
+
@controller.authenticate_user!
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
test 'proxy admin_authenticate! to authenticate with admin scope' do
|
|
55
|
+
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
|
56
|
+
@controller.authenticate_admin!
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
test 'proxy user_signed_in? to authenticate? with user scope' do
|
|
60
|
+
@mock_warden.expects(:authenticate?).with(:scope => :user)
|
|
61
|
+
@controller.user_signed_in?
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
test 'proxy admin_signed_in? to authenticate? with admin scope' do
|
|
65
|
+
@mock_warden.expects(:authenticate?).with(:scope => :admin)
|
|
66
|
+
@controller.admin_signed_in?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
test 'proxy user_session to session scope in warden' do
|
|
70
|
+
@mock_warden.expects(:authenticate).with(:scope => :user).returns(true)
|
|
71
|
+
@mock_warden.expects(:session).with(:user).returns({})
|
|
72
|
+
@controller.user_session
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
test 'proxy admin_session to session scope in warden' do
|
|
76
|
+
@mock_warden.expects(:authenticate).with(:scope => :admin).returns(true)
|
|
77
|
+
@mock_warden.expects(:session).with(:admin).returns({})
|
|
78
|
+
@controller.admin_session
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
test 'sign in proxy to set_user on warden' do
|
|
82
|
+
user = User.new
|
|
83
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
84
|
+
@controller.sign_in(:user, user)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
test 'sign in accepts a resource as argument' do
|
|
88
|
+
user = User.new
|
|
89
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
90
|
+
@controller.sign_in(user)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
test 'sign out proxy to logout on warden' do
|
|
94
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
|
95
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
|
96
|
+
@controller.sign_out(:user)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
test 'sign out accepts a resource as argument' do
|
|
100
|
+
@mock_warden.expects(:user).with(:user).returns(true)
|
|
101
|
+
@mock_warden.expects(:logout).with(:user).returns(true)
|
|
102
|
+
@controller.sign_out(User.new)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
test 'stored location for returns the location for a given scope' do
|
|
106
|
+
assert_nil @controller.stored_location_for(:user)
|
|
107
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
|
108
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
test 'stored location for accepts a resource as argument' do
|
|
112
|
+
assert_nil @controller.stored_location_for(:user)
|
|
113
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
|
114
|
+
assert_equal "/foo.bar", @controller.stored_location_for(User.new)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
test 'stored location cleans information after reading' do
|
|
118
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
|
119
|
+
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
|
120
|
+
assert_nil @controller.session[:"user.return_to"]
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
test 'after sign in path defaults to root path if none by was specified for the given scope' do
|
|
124
|
+
assert_equal root_path, @controller.after_sign_in_path_for(:user)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
test 'after sign in path defaults to the scoped root path' do
|
|
128
|
+
assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
test 'after sign out path defaults to the root path' do
|
|
132
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:admin)
|
|
133
|
+
assert_equal root_path, @controller.after_sign_out_path_for(:user)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
test 'sign in and redirect uses the stored location' do
|
|
137
|
+
user = User.new
|
|
138
|
+
@controller.session[:"user.return_to"] = "/foo.bar"
|
|
139
|
+
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
|
140
|
+
@controller.expects(:redirect_to).with("/foo.bar")
|
|
141
|
+
@controller.sign_in_and_redirect(user)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
test 'sign in and redirect uses the configured after sign in path' do
|
|
145
|
+
admin = Admin.new
|
|
146
|
+
@mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true)
|
|
147
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
148
|
+
@controller.sign_in_and_redirect(admin)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
test 'only redirect if skip is given' do
|
|
152
|
+
admin = Admin.new
|
|
153
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
154
|
+
@controller.sign_in_and_redirect(:admin, admin, true)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
test 'sign out and redirect uses the configured after sign out path' do
|
|
158
|
+
@mock_warden.expects(:user).with(:admin).returns(true)
|
|
159
|
+
@mock_warden.expects(:logout).with(:admin).returns(true)
|
|
160
|
+
@controller.expects(:redirect_to).with(admin_root_path)
|
|
161
|
+
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
|
162
|
+
@controller.sign_out_and_redirect(:admin)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
test 'is not a devise controller' do
|
|
166
|
+
assert_not @controller.devise_controller?
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
test 'default url options are retrieved from devise' do
|
|
170
|
+
begin
|
|
171
|
+
Devise.default_url_options {{ :locale => I18n.locale }}
|
|
172
|
+
assert_equal({ :locale => :en }, @controller.send(:default_url_options))
|
|
173
|
+
ensure
|
|
174
|
+
Devise.default_url_options {{ }}
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require 'test/test_helper'
|
|
2
|
+
|
|
3
|
+
class MyController < ApplicationController
|
|
4
|
+
include Devise::Controllers::InternalHelpers
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class HelpersTest < ActionController::TestCase
|
|
8
|
+
tests MyController
|
|
9
|
+
|
|
10
|
+
test 'get resource name from request path' do
|
|
11
|
+
@request.path = '/users/session'
|
|
12
|
+
assert_equal :user, @controller.resource_name
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
test 'get resource name from specific request path' do
|
|
16
|
+
@request.path = '/admin_area/session'
|
|
17
|
+
assert_equal :admin, @controller.resource_name
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
test 'get resource class from request path' do
|
|
21
|
+
@request.path = '/users/session'
|
|
22
|
+
assert_equal User, @controller.resource_class
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'get resource instance variable from request path' do
|
|
26
|
+
@request.path = '/admin_area/session'
|
|
27
|
+
@controller.instance_variable_set(:@admin, admin = Admin.new)
|
|
28
|
+
assert_equal admin, @controller.resource
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test 'set resource instance variable from request path' do
|
|
32
|
+
@request.path = '/admin_area/session'
|
|
33
|
+
|
|
34
|
+
admin = @controller.send(:resource_class).new
|
|
35
|
+
@controller.send(:resource=, admin)
|
|
36
|
+
|
|
37
|
+
assert_equal admin, @controller.send(:resource)
|
|
38
|
+
assert_equal admin, @controller.instance_variable_get(:@admin)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'resources methods are not controller actions' do
|
|
42
|
+
assert @controller.class.action_methods.empty?
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
test 'require no authentication tests current mapping' do
|
|
46
|
+
@controller.expects(:resource_name).returns(:user).twice
|
|
47
|
+
@mock_warden.expects(:authenticated?).with(:user).returns(true)
|
|
48
|
+
@controller.expects(:redirect_to).with(root_path)
|
|
49
|
+
@controller.send :require_no_authentication
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
test 'is a devise controller' do
|
|
53
|
+
assert @controller.devise_controller?
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
require 'test/test_helper'
|
|
2
|
+
|
|
3
|
+
class RoutesTest < ActionController::TestCase
|
|
4
|
+
tests ApplicationController
|
|
5
|
+
|
|
6
|
+
def test_path_and_url(name, prepend_path=nil)
|
|
7
|
+
@request.path = '/users/session'
|
|
8
|
+
prepend_path = "#{prepend_path}_" if prepend_path
|
|
9
|
+
|
|
10
|
+
# Resource param
|
|
11
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user),
|
|
12
|
+
send(:"#{prepend_path}user_#{name}_path")
|
|
13
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user),
|
|
14
|
+
send(:"#{prepend_path}user_#{name}_url")
|
|
15
|
+
|
|
16
|
+
# Default url params
|
|
17
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, :param => 123),
|
|
18
|
+
send(:"#{prepend_path}user_#{name}_path", :param => 123)
|
|
19
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, :param => 123),
|
|
20
|
+
send(:"#{prepend_path}user_#{name}_url", :param => 123)
|
|
21
|
+
|
|
22
|
+
@request.path = nil
|
|
23
|
+
# With an AR object
|
|
24
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_path", User.new),
|
|
25
|
+
send(:"#{prepend_path}user_#{name}_path")
|
|
26
|
+
assert_equal @controller.send(:"#{prepend_path}#{name}_url", User.new),
|
|
27
|
+
send(:"#{prepend_path}user_#{name}_url")
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
test 'should alias session to mapped user session' do
|
|
32
|
+
test_path_and_url :session
|
|
33
|
+
test_path_and_url :session, :new
|
|
34
|
+
test_path_and_url :session, :destroy
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test 'should alias password to mapped user password' do
|
|
38
|
+
test_path_and_url :password
|
|
39
|
+
test_path_and_url :password, :new
|
|
40
|
+
test_path_and_url :password, :edit
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
test 'should alias confirmation to mapped user confirmation' do
|
|
44
|
+
test_path_and_url :confirmation
|
|
45
|
+
test_path_and_url :confirmation, :new
|
|
46
|
+
end
|
|
47
|
+
end
|