dcu-devise 1.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +378 -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 +41 -0
- data/app/controllers/registrations_controller.rb +53 -0
- data/app/controllers/sessions_controller.rb +44 -0
- data/app/controllers/unlocks_controller.rb +41 -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 +23 -0
- data/generators/devise_install/templates/devise.rb +105 -0
- data/generators/devise_views/USAGE +3 -0
- data/generators/devise_views/devise_views_generator.rb +21 -0
- data/lib/devise.rb +264 -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 +32 -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 +128 -0
- data/lib/devise/models.rb +117 -0
- data/lib/devise/models/activatable.rb +16 -0
- data/lib/devise/models/confirmable.rb +162 -0
- data/lib/devise/models/database_authenticatable.rb +144 -0
- data/lib/devise/models/http_authenticatable.rb +21 -0
- data/lib/devise/models/lockable.rb +150 -0
- data/lib/devise/models/recoverable.rb +80 -0
- data/lib/devise/models/registerable.rb +8 -0
- data/lib/devise/models/rememberable.rb +92 -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 +39 -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 +47 -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 +73 -0
- data/lib/devise/strategies/base.rb +16 -0
- data/lib/devise/strategies/database_authenticatable.rb +36 -0
- data/lib/devise/strategies/http_authenticatable.rb +59 -0
- data/lib/devise/strategies/rememberable.rb +37 -0
- data/lib/devise/strategies/token_authenticatable.rb +37 -0
- data/lib/devise/test_helpers.rb +90 -0
- data/lib/devise/version.rb +3 -0
- data/rails/init.rb +2 -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 +74 -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 +52 -0
- data/test/integration/lockable_test.rb +102 -0
- data/test/integration/rack_middleware_test.rb +47 -0
- data/test/integration/recoverable_test.rb +141 -0
- data/test/integration/registerable_test.rb +144 -0
- data/test/integration/rememberable_test.rb +71 -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 +86 -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 +148 -0
- data/test/models/authenticatable_test.rb +180 -0
- data/test/models/confirmable_test.rb +212 -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 +70 -0
- data/test/orm/active_record.rb +31 -0
- data/test/orm/mongo_mapper.rb +20 -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 +12 -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 +13 -0
- data/test/rails_app/app/mongo_mapper/user.rb +14 -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 +82 -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 +213 -0
@@ -0,0 +1,90 @@
|
|
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 user(*args)
|
28
|
+
catch_with_redirect { super }
|
29
|
+
end
|
30
|
+
|
31
|
+
def catch_with_redirect(&block)
|
32
|
+
result = catch(:warden, &block)
|
33
|
+
|
34
|
+
if result.is_a?(Hash) && !custom_failure? && !@controller.send(:performed?)
|
35
|
+
result[:action] ||= :unauthenticated
|
36
|
+
|
37
|
+
env = @controller.request.env
|
38
|
+
env["PATH_INFO"] = "/#{result[:action]}"
|
39
|
+
env["warden.options"] = result
|
40
|
+
Warden::Manager._before_failure.each{ |hook| hook.call(env, result) }
|
41
|
+
|
42
|
+
status, headers, body = Devise::FailureApp.call(env).to_a
|
43
|
+
@controller.send :redirect_to, headers["Location"]
|
44
|
+
else
|
45
|
+
result
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# We need to setup the environment variables and the response in the controller.
|
51
|
+
def setup_controller_for_warden #:nodoc:
|
52
|
+
@request.env['action_controller.rescue.request'] = @request
|
53
|
+
@request.env['action_controller.rescue.response'] = @response
|
54
|
+
@request.env['rack.session'] = session
|
55
|
+
@controller.response = @response
|
56
|
+
end
|
57
|
+
|
58
|
+
# Quick access to Warden::Proxy.
|
59
|
+
def warden #:nodoc:
|
60
|
+
@warden ||= (@request.env['warden'] = TestWarden.new(@controller))
|
61
|
+
end
|
62
|
+
|
63
|
+
# sign_in a given resource by storing its keys in the session.
|
64
|
+
#
|
65
|
+
# Examples:
|
66
|
+
#
|
67
|
+
# sign_in :user, @user # sign_in(scope, resource)
|
68
|
+
# sign_in @user # sign_in(resource)
|
69
|
+
#
|
70
|
+
def sign_in(resource_or_scope, resource=nil)
|
71
|
+
scope ||= Devise::Mapping.find_scope!(resource_or_scope)
|
72
|
+
resource ||= resource_or_scope
|
73
|
+
warden.session_serializer.store(resource, scope)
|
74
|
+
end
|
75
|
+
|
76
|
+
# Sign out a given resource or scope by calling logout on Warden.
|
77
|
+
#
|
78
|
+
# Examples:
|
79
|
+
#
|
80
|
+
# sign_out :user # sign_out(scope)
|
81
|
+
# sign_out @user # sign_out(resource)
|
82
|
+
#
|
83
|
+
def sign_out(resource_or_scope)
|
84
|
+
scope = Devise::Mapping.find_scope!(resource_or_scope)
|
85
|
+
@controller.instance_variable_set(:"@current_#{scope}", nil)
|
86
|
+
warden.logout(scope)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
end
|
data/rails/init.rb
ADDED
@@ -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
|
data/test/devise_test.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
module Devise
|
4
|
+
def self.clean_warden_config!
|
5
|
+
@warden_config = nil
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class DeviseTest < ActiveSupport::TestCase
|
10
|
+
test 'model options can be configured through Devise' do
|
11
|
+
swap Devise, :confirm_within => 113, :pepper => "foo" do
|
12
|
+
assert_equal 113, Devise.confirm_within
|
13
|
+
assert_equal "foo", Devise.pepper
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
test 'setup block yields self' do
|
18
|
+
Devise.setup do |config|
|
19
|
+
assert_equal Devise, config
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
test 'warden manager configuration' do
|
24
|
+
config = Warden::Config.new
|
25
|
+
Devise.configure_warden(config)
|
26
|
+
|
27
|
+
assert_equal Devise::FailureApp, config.failure_app
|
28
|
+
assert_equal [:rememberable, :http_authenticatable, :token_authenticatable, :database_authenticatable], config.default_strategies
|
29
|
+
assert_equal :user, config.default_scope
|
30
|
+
assert config.silence_missing_strategies?
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'warden manager user configuration through a block' do
|
34
|
+
begin
|
35
|
+
@executed = false
|
36
|
+
Devise.warden do |config|
|
37
|
+
@executed = true
|
38
|
+
assert_kind_of Warden::Config, config
|
39
|
+
end
|
40
|
+
|
41
|
+
Devise.configure_warden(Warden::Config.new)
|
42
|
+
assert @executed
|
43
|
+
ensure
|
44
|
+
Devise.clean_warden_config!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
test 'add new module using the helper method' do
|
49
|
+
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
50
|
+
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
51
|
+
assert_not Devise::STRATEGIES.include?(:coconut)
|
52
|
+
assert_not defined?(Devise::Models::Coconut)
|
53
|
+
Devise::ALL.delete(:coconut)
|
54
|
+
|
55
|
+
assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => true) }
|
56
|
+
assert_equal 1, Devise::STRATEGIES.select { |v| v == :banana }.size
|
57
|
+
Devise::ALL.delete(:banana)
|
58
|
+
Devise::STRATEGIES.delete(:banana)
|
59
|
+
|
60
|
+
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
|
61
|
+
assert_not_nil Devise::CONTROLLERS[:fruits]
|
62
|
+
assert_equal 1, Devise::CONTROLLERS[:fruits].select { |v| v == :kivi }.size
|
63
|
+
Devise::ALL.delete(:kivi)
|
64
|
+
Devise::CONTROLLERS.delete(:fruits)
|
65
|
+
|
66
|
+
assert_nothing_raised(Exception) { Devise.add_module(:carrot, :route => :vegetable) }
|
67
|
+
assert_equal 1, Devise::ROUTES.select { |v| v == :vegetable }.size
|
68
|
+
Devise::ALL.delete(:carrot)
|
69
|
+
Devise::ROUTES.delete(:vegetable)
|
70
|
+
|
71
|
+
assert_nothing_raised(Exception) { Devise.add_module(:authenticatable_again, :model => 'devise/model/authenticatable') }
|
72
|
+
assert defined?(Devise::Models::AuthenticatableAgain)
|
73
|
+
end
|
74
|
+
end
|