loyal_devise 2.1.7 → 2.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -46
- data/app/controllers/devise/passwords_controller.rb +1 -1
- data/app/controllers/devise/registrations_controller.rb +1 -1
- data/lib/devise/controllers/helpers.rb +3 -6
- data/lib/devise/failure_app.rb +1 -8
- data/lib/devise/hooks/lockable.rb +1 -1
- data/lib/devise/mapping.rb +6 -6
- data/lib/devise/models/authenticatable.rb +4 -4
- data/lib/devise/models/confirmable.rb +4 -12
- data/lib/devise/models/database_authenticatable.rb +1 -1
- data/lib/devise/models/lockable.rb +1 -1
- data/lib/devise/models/recoverable.rb +2 -7
- data/lib/devise/models/rememberable.rb +1 -1
- data/lib/devise/{parameter_filter.rb → param_filter.rb} +1 -1
- data/lib/devise/parameter_sanitizer.rb +3 -3
- data/lib/devise/version.rb +1 -1
- data/lib/devise.rb +1 -1
- data/lib/generators/templates/README +1 -1
- data/lib/loyal_devise.rb +1 -0
- metadata +65 -301
- data/.gitignore +0 -12
- data/.travis.yml +0 -20
- data/.yardopts +0 -9
- data/CHANGELOG.rdoc +0 -936
- data/CONTRIBUTING.md +0 -14
- data/Gemfile +0 -31
- data/Gemfile.lock +0 -160
- data/devise.gemspec +0 -26
- data/devise.png +0 -0
- data/gemfiles/Gemfile.rails-3.2.x +0 -31
- data/gemfiles/Gemfile.rails-3.2.x.lock +0 -156
- data/loyal_devise.gemspec +0 -29
- data/test/controllers/custom_strategy_test.rb +0 -62
- data/test/controllers/helpers_test.rb +0 -253
- data/test/controllers/internal_helpers_test.rb +0 -120
- data/test/controllers/passwords_controller_test.rb +0 -32
- data/test/controllers/sessions_controller_test.rb +0 -85
- data/test/controllers/url_helpers_test.rb +0 -59
- data/test/delegator_test.rb +0 -19
- data/test/devise_test.rb +0 -83
- data/test/failure_app_test.rb +0 -221
- data/test/generators/active_record_generator_test.rb +0 -73
- data/test/generators/devise_generator_test.rb +0 -39
- data/test/generators/install_generator_test.rb +0 -13
- data/test/generators/mongoid_generator_test.rb +0 -23
- data/test/generators/views_generator_test.rb +0 -67
- data/test/helpers/devise_helper_test.rb +0 -51
- data/test/integration/authenticatable_test.rb +0 -699
- data/test/integration/confirmable_test.rb +0 -299
- data/test/integration/database_authenticatable_test.rb +0 -84
- data/test/integration/http_authenticatable_test.rb +0 -115
- data/test/integration/lockable_test.rb +0 -242
- data/test/integration/omniauthable_test.rb +0 -133
- data/test/integration/recoverable_test.rb +0 -335
- data/test/integration/registerable_test.rb +0 -349
- data/test/integration/rememberable_test.rb +0 -165
- data/test/integration/timeoutable_test.rb +0 -150
- data/test/integration/token_authenticatable_test.rb +0 -205
- data/test/integration/trackable_test.rb +0 -92
- data/test/mailers/confirmation_instructions_test.rb +0 -111
- data/test/mailers/reset_password_instructions_test.rb +0 -92
- data/test/mailers/unlock_instructions_test.rb +0 -87
- data/test/mapping_test.rb +0 -127
- data/test/models/authenticatable_test.rb +0 -13
- data/test/models/confirmable_test.rb +0 -443
- data/test/models/database_authenticatable_test.rb +0 -226
- data/test/models/lockable_test.rb +0 -273
- data/test/models/omniauthable_test.rb +0 -7
- data/test/models/recoverable_test.rb +0 -222
- data/test/models/registerable_test.rb +0 -7
- data/test/models/rememberable_test.rb +0 -175
- data/test/models/serializable_test.rb +0 -49
- data/test/models/timeoutable_test.rb +0 -46
- data/test/models/token_authenticatable_test.rb +0 -55
- data/test/models/trackable_test.rb +0 -13
- data/test/models/validatable_test.rb +0 -127
- data/test/models_test.rb +0 -163
- data/test/omniauth/config_test.rb +0 -57
- data/test/omniauth/url_helpers_test.rb +0 -54
- data/test/orm/active_record.rb +0 -10
- data/test/orm/mongoid.rb +0 -13
- data/test/parameter_sanitizer_test.rb +0 -51
- data/test/rails_app/Rakefile +0 -6
- data/test/rails_app/app/active_record/admin.rb +0 -6
- data/test/rails_app/app/active_record/shim.rb +0 -2
- data/test/rails_app/app/active_record/user.rb +0 -6
- data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
- data/test/rails_app/app/controllers/admins_controller.rb +0 -11
- data/test/rails_app/app/controllers/application_controller.rb +0 -9
- data/test/rails_app/app/controllers/home_controller.rb +0 -25
- data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
- data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
- data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
- data/test/rails_app/app/controllers/users_controller.rb +0 -31
- data/test/rails_app/app/helpers/application_helper.rb +0 -3
- data/test/rails_app/app/mailers/users/mailer.rb +0 -12
- data/test/rails_app/app/mongoid/admin.rb +0 -29
- data/test/rails_app/app/mongoid/shim.rb +0 -23
- data/test/rails_app/app/mongoid/user.rb +0 -42
- data/test/rails_app/app/views/admins/index.html.erb +0 -1
- data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
- data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/home/index.html.erb +0 -1
- data/test/rails_app/app/views/home/join.html.erb +0 -1
- data/test/rails_app/app/views/home/private.html.erb +0 -1
- data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
- data/test/rails_app/app/views/layouts/application.html.erb +0 -24
- data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
- data/test/rails_app/app/views/users/index.html.erb +0 -1
- data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
- data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
- data/test/rails_app/bin/bundle +0 -3
- data/test/rails_app/bin/rails +0 -4
- data/test/rails_app/bin/rake +0 -4
- data/test/rails_app/config/application.rb +0 -40
- data/test/rails_app/config/boot.rb +0 -8
- data/test/rails_app/config/database.yml +0 -18
- data/test/rails_app/config/environment.rb +0 -5
- data/test/rails_app/config/environments/development.rb +0 -34
- data/test/rails_app/config/environments/production.rb +0 -84
- data/test/rails_app/config/environments/test.rb +0 -36
- data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
- data/test/rails_app/config/initializers/devise.rb +0 -178
- data/test/rails_app/config/initializers/inflections.rb +0 -2
- data/test/rails_app/config/initializers/secret_token.rb +0 -8
- data/test/rails_app/config/initializers/session_store.rb +0 -1
- data/test/rails_app/config/routes.rb +0 -104
- data/test/rails_app/config.ru +0 -4
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -74
- data/test/rails_app/db/schema.rb +0 -52
- data/test/rails_app/lib/shared_admin.rb +0 -14
- data/test/rails_app/lib/shared_user.rb +0 -25
- data/test/rails_app/public/404.html +0 -26
- data/test/rails_app/public/422.html +0 -26
- data/test/rails_app/public/500.html +0 -26
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/routes_test.rb +0 -250
- data/test/support/assertions.rb +0 -40
- data/test/support/helpers.rb +0 -91
- data/test/support/integration.rb +0 -92
- data/test/support/locale/en.yml +0 -4
- data/test/support/webrat/integrations/rails.rb +0 -24
- data/test/test_helper.rb +0 -34
- data/test/test_helpers_test.rb +0 -151
- data/test/test_models.rb +0 -26
@@ -1,253 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
class ControllerAuthenticatableTest < ActionController::TestCase
|
5
|
-
tests ApplicationController
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@mock_warden = OpenStruct.new
|
9
|
-
@controller.request.env['warden'] = @mock_warden
|
10
|
-
end
|
11
|
-
|
12
|
-
test 'provide access to warden instance' do
|
13
|
-
assert_equal @mock_warden, @controller.warden
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'proxy signed_in?(scope) to authenticate?' do
|
17
|
-
@mock_warden.expects(:authenticate?).with(:scope => :my_scope)
|
18
|
-
@controller.signed_in?(:my_scope)
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'proxy signed_in?(nil) to authenticate?' do
|
22
|
-
Devise.mappings.keys.each do |scope| # :user, :admin, :manager
|
23
|
-
@mock_warden.expects(:authenticate?).with(:scope => scope)
|
24
|
-
end
|
25
|
-
@controller.signed_in?
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'proxy current_user to authenticate with user scope' do
|
29
|
-
@mock_warden.expects(:authenticate).with(:scope => :user)
|
30
|
-
@controller.current_user
|
31
|
-
end
|
32
|
-
|
33
|
-
test 'proxy current_admin to authenticate with admin scope' do
|
34
|
-
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
35
|
-
@controller.current_admin
|
36
|
-
end
|
37
|
-
|
38
|
-
test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
|
39
|
-
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
40
|
-
@controller.current_publisher_account
|
41
|
-
end
|
42
|
-
|
43
|
-
test 'proxy authenticate_user! to authenticate with user scope' do
|
44
|
-
@mock_warden.expects(:authenticate!).with(:scope => :user)
|
45
|
-
@controller.authenticate_user!
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'proxy authenticate_user! options to authenticate with user scope' do
|
49
|
-
@mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
|
50
|
-
@controller.authenticate_user!(:recall => "foo")
|
51
|
-
end
|
52
|
-
|
53
|
-
test 'proxy authenticate_admin! to authenticate with admin scope' do
|
54
|
-
@mock_warden.expects(:authenticate!).with(:scope => :admin)
|
55
|
-
@controller.authenticate_admin!
|
56
|
-
end
|
57
|
-
|
58
|
-
test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
|
59
|
-
@mock_warden.expects(:authenticate!).with(:scope => :publisher_account)
|
60
|
-
@controller.authenticate_publisher_account!
|
61
|
-
end
|
62
|
-
|
63
|
-
test 'proxy user_signed_in? to authenticate with user scope' do
|
64
|
-
@mock_warden.expects(:authenticate).with(:scope => :user).returns("user")
|
65
|
-
assert @controller.user_signed_in?
|
66
|
-
end
|
67
|
-
|
68
|
-
test 'proxy admin_signed_in? to authenticatewith admin scope' do
|
69
|
-
@mock_warden.expects(:authenticate).with(:scope => :admin)
|
70
|
-
assert_not @controller.admin_signed_in?
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
|
74
|
-
@mock_warden.expects(:authenticate).with(:scope => :publisher_account)
|
75
|
-
@controller.publisher_account_signed_in?
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'proxy user_session to session scope in warden' do
|
79
|
-
@mock_warden.expects(:authenticate).with(:scope => :user).returns(true)
|
80
|
-
@mock_warden.expects(:session).with(:user).returns({})
|
81
|
-
@controller.user_session
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'proxy admin_session to session scope in warden' do
|
85
|
-
@mock_warden.expects(:authenticate).with(:scope => :admin).returns(true)
|
86
|
-
@mock_warden.expects(:session).with(:admin).returns({})
|
87
|
-
@controller.admin_session
|
88
|
-
end
|
89
|
-
|
90
|
-
test 'proxy publisher_account_session from namespaced scope to session scope in warden' do
|
91
|
-
@mock_warden.expects(:authenticate).with(:scope => :publisher_account).returns(true)
|
92
|
-
@mock_warden.expects(:session).with(:publisher_account).returns({})
|
93
|
-
@controller.publisher_account_session
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'sign in proxy to set_user on warden' do
|
97
|
-
user = User.new
|
98
|
-
@mock_warden.expects(:user).returns(nil)
|
99
|
-
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
100
|
-
@controller.sign_in(:user, user)
|
101
|
-
end
|
102
|
-
|
103
|
-
test 'sign in accepts a resource as argument' do
|
104
|
-
user = User.new
|
105
|
-
@mock_warden.expects(:user).returns(nil)
|
106
|
-
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
107
|
-
@controller.sign_in(user)
|
108
|
-
end
|
109
|
-
|
110
|
-
test 'does not sign in again if the user is already in' do
|
111
|
-
user = User.new
|
112
|
-
@mock_warden.expects(:user).returns(user)
|
113
|
-
@mock_warden.expects(:set_user).never
|
114
|
-
assert @controller.sign_in(user)
|
115
|
-
end
|
116
|
-
|
117
|
-
test 'sign in again when the user is already in only if force is given' do
|
118
|
-
user = User.new
|
119
|
-
@mock_warden.expects(:user).returns(user)
|
120
|
-
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
121
|
-
@controller.sign_in(user, :force => true)
|
122
|
-
end
|
123
|
-
|
124
|
-
test 'sign in accepts bypass as option' do
|
125
|
-
user = User.new
|
126
|
-
@mock_warden.expects(:session_serializer).returns(serializer = mock())
|
127
|
-
serializer.expects(:store).with(user, :user)
|
128
|
-
@controller.sign_in(user, :bypass => true)
|
129
|
-
end
|
130
|
-
|
131
|
-
test 'sign out clears up any signed in user from all scopes' do
|
132
|
-
user = User.new
|
133
|
-
@mock_warden.expects(:user).times(Devise.mappings.size)
|
134
|
-
@mock_warden.expects(:logout).with().returns(true)
|
135
|
-
@controller.instance_variable_set(:@current_user, user)
|
136
|
-
@controller.instance_variable_set(:@current_admin, user)
|
137
|
-
@controller.sign_out
|
138
|
-
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
139
|
-
assert_equal nil, @controller.instance_variable_get(:@current_admin)
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'sign out logs out and clears up any signed in user by scope' do
|
143
|
-
user = User.new
|
144
|
-
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(user)
|
145
|
-
@mock_warden.expects(:logout).with(:user).returns(true)
|
146
|
-
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
|
147
|
-
@controller.instance_variable_set(:@current_user, user)
|
148
|
-
@controller.sign_out(:user)
|
149
|
-
assert_equal nil, @controller.instance_variable_get(:@current_user)
|
150
|
-
end
|
151
|
-
|
152
|
-
test 'sign out accepts a resource as argument' do
|
153
|
-
@mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
|
154
|
-
@mock_warden.expects(:logout).with(:user).returns(true)
|
155
|
-
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
|
156
|
-
@controller.sign_out(User.new)
|
157
|
-
end
|
158
|
-
|
159
|
-
test 'sign out without args proxy to sign out all scopes' do
|
160
|
-
@mock_warden.expects(:user).times(Devise.mappings.size)
|
161
|
-
@mock_warden.expects(:logout).with().returns(true)
|
162
|
-
@mock_warden.expects(:clear_strategies_cache!).with().returns(true)
|
163
|
-
@controller.sign_out
|
164
|
-
end
|
165
|
-
|
166
|
-
test 'sign out everybody proxy to logout on warden' do
|
167
|
-
@mock_warden.expects(:user).times(Devise.mappings.size)
|
168
|
-
@mock_warden.expects(:logout).with().returns(true)
|
169
|
-
@controller.sign_out_all_scopes
|
170
|
-
end
|
171
|
-
|
172
|
-
test 'stored location for returns the location for a given scope' do
|
173
|
-
assert_nil @controller.stored_location_for(:user)
|
174
|
-
@controller.session[:"user_return_to"] = "/foo.bar"
|
175
|
-
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'stored location for accepts a resource as argument' do
|
179
|
-
assert_nil @controller.stored_location_for(:user)
|
180
|
-
@controller.session[:"user_return_to"] = "/foo.bar"
|
181
|
-
assert_equal "/foo.bar", @controller.stored_location_for(User.new)
|
182
|
-
end
|
183
|
-
|
184
|
-
test 'stored location cleans information after reading' do
|
185
|
-
@controller.session[:"user_return_to"] = "/foo.bar"
|
186
|
-
assert_equal "/foo.bar", @controller.stored_location_for(:user)
|
187
|
-
assert_nil @controller.session[:"user_return_to"]
|
188
|
-
end
|
189
|
-
|
190
|
-
test 'after sign in path defaults to root path if none by was specified for the given scope' do
|
191
|
-
assert_equal root_path, @controller.after_sign_in_path_for(:user)
|
192
|
-
end
|
193
|
-
|
194
|
-
test 'after sign in path defaults to the scoped root path' do
|
195
|
-
assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)
|
196
|
-
end
|
197
|
-
|
198
|
-
test 'after sign out path defaults to the root path' do
|
199
|
-
assert_equal root_path, @controller.after_sign_out_path_for(:admin)
|
200
|
-
assert_equal root_path, @controller.after_sign_out_path_for(:user)
|
201
|
-
end
|
202
|
-
|
203
|
-
test 'sign in and redirect uses the stored location' do
|
204
|
-
user = User.new
|
205
|
-
@controller.session[:"user_return_to"] = "/foo.bar"
|
206
|
-
@mock_warden.expects(:user).with(:user).returns(nil)
|
207
|
-
@mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
|
208
|
-
@controller.expects(:redirect_to).with("/foo.bar")
|
209
|
-
@controller.sign_in_and_redirect(user)
|
210
|
-
end
|
211
|
-
|
212
|
-
test 'sign in and redirect uses the configured after sign in path' do
|
213
|
-
admin = Admin.new
|
214
|
-
@mock_warden.expects(:user).with(:admin).returns(nil)
|
215
|
-
@mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true)
|
216
|
-
@controller.expects(:redirect_to).with(admin_root_path)
|
217
|
-
@controller.sign_in_and_redirect(admin)
|
218
|
-
end
|
219
|
-
|
220
|
-
test 'sign in and redirect does not sign in again if user is already signed' do
|
221
|
-
admin = Admin.new
|
222
|
-
@mock_warden.expects(:user).with(:admin).returns(admin)
|
223
|
-
@mock_warden.expects(:set_user).never
|
224
|
-
@controller.expects(:redirect_to).with(admin_root_path)
|
225
|
-
@controller.sign_in_and_redirect(admin)
|
226
|
-
end
|
227
|
-
|
228
|
-
test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
|
229
|
-
swap Devise, :sign_out_all_scopes => false do
|
230
|
-
@mock_warden.expects(:user).with(:scope => :admin, :run_callbacks => false).returns(true)
|
231
|
-
@mock_warden.expects(:logout).with(:admin).returns(true)
|
232
|
-
@mock_warden.expects(:clear_strategies_cache!).with(:scope => :admin).returns(true)
|
233
|
-
@controller.expects(:redirect_to).with(admin_root_path)
|
234
|
-
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
235
|
-
@controller.sign_out_and_redirect(:admin)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
|
240
|
-
swap Devise, :sign_out_all_scopes => true do
|
241
|
-
@mock_warden.expects(:user).times(Devise.mappings.size)
|
242
|
-
@mock_warden.expects(:logout).with().returns(true)
|
243
|
-
@mock_warden.expects(:clear_strategies_cache!).with().returns(true)
|
244
|
-
@controller.expects(:redirect_to).with(admin_root_path)
|
245
|
-
@controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
|
246
|
-
@controller.sign_out_and_redirect(:admin)
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
test 'is not a devise controller' do
|
251
|
-
assert_not @controller.devise_controller?
|
252
|
-
end
|
253
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class MyController < DeviseController
|
4
|
-
end
|
5
|
-
|
6
|
-
class HelpersTest < ActionController::TestCase
|
7
|
-
tests MyController
|
8
|
-
|
9
|
-
def setup
|
10
|
-
@mock_warden = OpenStruct.new
|
11
|
-
@controller.request.env['warden'] = @mock_warden
|
12
|
-
@controller.request.env['devise.mapping'] = Devise.mappings[:user]
|
13
|
-
end
|
14
|
-
|
15
|
-
test 'get resource name from env' do
|
16
|
-
assert_equal :user, @controller.resource_name
|
17
|
-
end
|
18
|
-
|
19
|
-
test 'get resource class from env' do
|
20
|
-
assert_equal User, @controller.resource_class
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'get resource instance variable from env' do
|
24
|
-
@controller.instance_variable_set(:@user, user = User.new)
|
25
|
-
assert_equal user, @controller.resource
|
26
|
-
end
|
27
|
-
|
28
|
-
test 'set resource instance variable from env' do
|
29
|
-
user = @controller.send(:resource_class).new
|
30
|
-
@controller.send(:resource=, user)
|
31
|
-
|
32
|
-
assert_equal user, @controller.send(:resource)
|
33
|
-
assert_equal user, @controller.instance_variable_get(:@user)
|
34
|
-
end
|
35
|
-
|
36
|
-
test 'get resource params from request params using resource name as key' do
|
37
|
-
user_params = {'email' => 'shirley@templar.com'}
|
38
|
-
|
39
|
-
params = if Devise.rails4?
|
40
|
-
# Stub controller name so strong parameters can filter properly.
|
41
|
-
# DeviseController does not allow any parameters by default.
|
42
|
-
@controller.stubs(:controller_name).returns(:sessions_controller)
|
43
|
-
|
44
|
-
ActionController::Parameters.new({'user' => user_params})
|
45
|
-
else
|
46
|
-
HashWithIndifferentAccess.new({'user' => user_params})
|
47
|
-
end
|
48
|
-
@controller.stubs(:params).returns(params)
|
49
|
-
|
50
|
-
assert_equal user_params, @controller.send(:resource_params)
|
51
|
-
end
|
52
|
-
|
53
|
-
test 'resources methods are not controller actions' do
|
54
|
-
assert @controller.class.action_methods.empty?
|
55
|
-
end
|
56
|
-
|
57
|
-
test 'require no authentication tests current mapping' do
|
58
|
-
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
|
59
|
-
@mock_warden.expects(:user).with(:user).returns(User.new)
|
60
|
-
@controller.expects(:redirect_to).with(root_path)
|
61
|
-
@controller.send :require_no_authentication
|
62
|
-
end
|
63
|
-
|
64
|
-
test 'require no authentication only checks if already authenticated if no inputs strategies are available' do
|
65
|
-
Devise.mappings[:user].expects(:no_input_strategies).returns([])
|
66
|
-
@mock_warden.expects(:authenticate?).never
|
67
|
-
@mock_warden.expects(:authenticated?).with(:user).once.returns(true)
|
68
|
-
@mock_warden.expects(:user).with(:user).returns(User.new)
|
69
|
-
@controller.expects(:redirect_to).with(root_path)
|
70
|
-
@controller.send :require_no_authentication
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'require no authentication sets a flash message' do
|
74
|
-
@mock_warden.expects(:authenticate?).with(:rememberable, :token_authenticatable, :scope => :user).returns(true)
|
75
|
-
@mock_warden.expects(:user).with(:user).returns(User.new)
|
76
|
-
@controller.expects(:redirect_to).with(root_path)
|
77
|
-
@controller.send :require_no_authentication
|
78
|
-
assert flash[:alert] == I18n.t("devise.failure.already_authenticated")
|
79
|
-
end
|
80
|
-
|
81
|
-
test 'signed in resource returns signed in resource for current scope' do
|
82
|
-
@mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
|
83
|
-
assert_kind_of User, @controller.signed_in_resource
|
84
|
-
end
|
85
|
-
|
86
|
-
test 'is a devise controller' do
|
87
|
-
assert @controller.devise_controller?
|
88
|
-
end
|
89
|
-
|
90
|
-
test 'does not issue blank flash messages' do
|
91
|
-
I18n.stubs(:t).returns(' ')
|
92
|
-
@controller.send :set_flash_message, :notice, :send_instructions
|
93
|
-
assert flash[:notice].nil?
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'issues non-blank flash messages normally' do
|
97
|
-
I18n.stubs(:t).returns('non-blank')
|
98
|
-
@controller.send :set_flash_message, :notice, :send_instructions
|
99
|
-
assert_equal 'non-blank', flash[:notice]
|
100
|
-
end
|
101
|
-
|
102
|
-
test 'uses custom i18n options' do
|
103
|
-
@controller.stubs(:devise_i18n_options).returns(:default => "devise custom options")
|
104
|
-
@controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
|
105
|
-
assert_equal 'devise custom options', flash[:notice]
|
106
|
-
end
|
107
|
-
|
108
|
-
test 'allows custom i18n options to override resource_name' do
|
109
|
-
I18n.expects(:t).with("custom_resource_name.confirmed", anything)
|
110
|
-
@controller.stubs(:devise_i18n_options).returns(:resource_name => "custom_resource_name")
|
111
|
-
@controller.send :set_flash_message, :notice, :confirmed
|
112
|
-
end
|
113
|
-
|
114
|
-
test 'navigational_formats not returning a wild card' do
|
115
|
-
MyController.send(:public, :navigational_formats)
|
116
|
-
Devise.navigational_formats = [:"*/*", :html]
|
117
|
-
assert_not @controller.navigational_formats.include?(:"*/*")
|
118
|
-
MyController.send(:protected, :navigational_formats)
|
119
|
-
end
|
120
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PasswordsControllerTest < ActionController::TestCase
|
4
|
-
tests Devise::PasswordsController
|
5
|
-
include Devise::TestHelpers
|
6
|
-
|
7
|
-
def setup
|
8
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
9
|
-
|
10
|
-
@user = create_user
|
11
|
-
@user.send_reset_password_instructions
|
12
|
-
end
|
13
|
-
|
14
|
-
def put_update_with_params
|
15
|
-
put :update, "user" => {
|
16
|
-
"reset_password_token" => @user.reset_password_token, "password" => "123456", "password_confirmation" => "123456"
|
17
|
-
}
|
18
|
-
end
|
19
|
-
|
20
|
-
test 'redirect to after_sign_in_path_for if after_resetting_password_path_for is not overridden' do
|
21
|
-
put_update_with_params
|
22
|
-
assert_redirected_to "http://test.host/"
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'redirect accordingly if after_resetting_password_path_for is overridden' do
|
26
|
-
custom_path = "http://custom.path/"
|
27
|
-
Devise::PasswordsController.any_instance.stubs(:after_resetting_password_path_for).with(@user).returns(custom_path)
|
28
|
-
|
29
|
-
put_update_with_params
|
30
|
-
assert_redirected_to custom_path
|
31
|
-
end
|
32
|
-
end
|
@@ -1,85 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class SessionsControllerTest < ActionController::TestCase
|
4
|
-
tests Devise::SessionsController
|
5
|
-
include Devise::TestHelpers
|
6
|
-
|
7
|
-
test "#create works even with scoped views" do
|
8
|
-
swap Devise, :scoped_views => true do
|
9
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
10
|
-
post :create
|
11
|
-
assert_equal 200, @response.status
|
12
|
-
assert_template "users/sessions/new"
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
test "#create delete the url stored in the session if the requested format is navigational" do
|
17
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
18
|
-
request.session["user_return_to"] = 'foo.bar'
|
19
|
-
|
20
|
-
user = create_user
|
21
|
-
user.confirm!
|
22
|
-
post :create, :user => {
|
23
|
-
:email => user.email,
|
24
|
-
:password => user.password
|
25
|
-
}
|
26
|
-
|
27
|
-
assert_nil request.session["user_return_to"]
|
28
|
-
end
|
29
|
-
|
30
|
-
test "#create doesn't delete the url stored in the session if the requested format is not navigational" do
|
31
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
32
|
-
request.session["user_return_to"] = 'foo.bar'
|
33
|
-
|
34
|
-
user = create_user
|
35
|
-
user.confirm!
|
36
|
-
post :create, :format => 'json', :user => {
|
37
|
-
:email => user.email,
|
38
|
-
:password => user.password
|
39
|
-
}
|
40
|
-
|
41
|
-
assert_equal 'foo.bar', request.session["user_return_to"]
|
42
|
-
end
|
43
|
-
|
44
|
-
test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
|
45
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
46
|
-
post :create, :user => {
|
47
|
-
:email => "nosuchuser@example.com",
|
48
|
-
:password => "wevdude"
|
49
|
-
}
|
50
|
-
assert_equal 200, @response.status
|
51
|
-
assert_template "devise/sessions/new"
|
52
|
-
end
|
53
|
-
|
54
|
-
test "#destroy doesn't set the flash if the requested format is not navigational" do
|
55
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
56
|
-
user = create_user
|
57
|
-
user.confirm!
|
58
|
-
post :create, :format => 'json', :user => {
|
59
|
-
:email => user.email,
|
60
|
-
:password => user.password
|
61
|
-
}
|
62
|
-
|
63
|
-
delete :destroy, :format => 'json'
|
64
|
-
assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
|
65
|
-
assert_equal 204, @response.status
|
66
|
-
end
|
67
|
-
|
68
|
-
if defined?(ActiveRecord) && ActiveRecord::Base.respond_to?(:mass_assignment_sanitizer)
|
69
|
-
test "#new doesn't raise mass-assignment exception even if sign-in key is attr_protected" do
|
70
|
-
request.env["devise.mapping"] = Devise.mappings[:user]
|
71
|
-
|
72
|
-
ActiveRecord::Base.mass_assignment_sanitizer = :strict
|
73
|
-
User.class_eval { attr_protected :email }
|
74
|
-
|
75
|
-
begin
|
76
|
-
assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do
|
77
|
-
get :new, :user => { :email => "allez viens!" }
|
78
|
-
end
|
79
|
-
ensure
|
80
|
-
ActiveRecord::Base.mass_assignment_sanitizer = :logger
|
81
|
-
User.class_eval { attr_accessible :email }
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class RoutesTest < ActionController::TestCase
|
4
|
-
tests ApplicationController
|
5
|
-
|
6
|
-
def assert_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 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
|
-
assert_path_and_url :session
|
33
|
-
assert_path_and_url :session, :new
|
34
|
-
assert_path_and_url :session, :destroy
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'should alias password to mapped user password' do
|
38
|
-
assert_path_and_url :password
|
39
|
-
assert_path_and_url :password, :new
|
40
|
-
assert_path_and_url :password, :edit
|
41
|
-
end
|
42
|
-
|
43
|
-
test 'should alias confirmation to mapped user confirmation' do
|
44
|
-
assert_path_and_url :confirmation
|
45
|
-
assert_path_and_url :confirmation, :new
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'should alias unlock to mapped user unlock' do
|
49
|
-
assert_path_and_url :unlock
|
50
|
-
assert_path_and_url :unlock, :new
|
51
|
-
end
|
52
|
-
|
53
|
-
test 'should alias registration to mapped user registration' do
|
54
|
-
assert_path_and_url :registration
|
55
|
-
assert_path_and_url :registration, :new
|
56
|
-
assert_path_and_url :registration, :edit
|
57
|
-
assert_path_and_url :registration, :cancel
|
58
|
-
end
|
59
|
-
end
|
data/test/delegator_test.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class DelegatorTest < ActiveSupport::TestCase
|
4
|
-
def delegator
|
5
|
-
Devise::Delegator.new
|
6
|
-
end
|
7
|
-
|
8
|
-
test 'failure_app returns default failure app if no warden options in env' do
|
9
|
-
assert_equal Devise::FailureApp, delegator.failure_app({})
|
10
|
-
end
|
11
|
-
|
12
|
-
test 'failure_app returns default failure app if no scope in warden options' do
|
13
|
-
assert_equal Devise::FailureApp, delegator.failure_app({"warden.options" => {}})
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'failure_app returns associated failure app by scope in the given environment' do
|
17
|
-
assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}})
|
18
|
-
end
|
19
|
-
end
|
data/test/devise_test.rb
DELETED
@@ -1,83 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Devise
|
4
|
-
def self.yield_and_restore
|
5
|
-
@@warden_configured = nil
|
6
|
-
c, b = @@warden_config, @@warden_config_block
|
7
|
-
yield
|
8
|
-
ensure
|
9
|
-
@@warden_config, @@warden_config_block = c, b
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class DeviseTest < ActiveSupport::TestCase
|
14
|
-
test 'model options can be configured through Devise' do
|
15
|
-
swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
|
16
|
-
assert_equal 113, Devise.allow_unconfirmed_access_for
|
17
|
-
assert_equal "foo", Devise.pepper
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
test 'setup block yields self' do
|
22
|
-
Devise.setup do |config|
|
23
|
-
assert_equal Devise, config
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'stores warden configuration' do
|
28
|
-
assert_kind_of Devise::Delegator, Devise.warden_config.failure_app
|
29
|
-
assert_equal :user, Devise.warden_config.default_scope
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'warden manager user configuration through a block' do
|
33
|
-
Devise.yield_and_restore do
|
34
|
-
@executed = false
|
35
|
-
Devise.warden do |config|
|
36
|
-
@executed = true
|
37
|
-
assert_kind_of Warden::Config, config
|
38
|
-
end
|
39
|
-
|
40
|
-
Devise.configure_warden!
|
41
|
-
assert @executed
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'add new module using the helper method' do
|
46
|
-
assert_nothing_raised(Exception) { Devise.add_module(:coconut) }
|
47
|
-
assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size
|
48
|
-
assert_not Devise::STRATEGIES.include?(:coconut)
|
49
|
-
assert_not defined?(Devise::Models::Coconut)
|
50
|
-
Devise::ALL.delete(:coconut)
|
51
|
-
|
52
|
-
assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) }
|
53
|
-
assert_equal :fruits, Devise::STRATEGIES[:banana]
|
54
|
-
Devise::ALL.delete(:banana)
|
55
|
-
Devise::STRATEGIES.delete(:banana)
|
56
|
-
|
57
|
-
assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
|
58
|
-
assert_equal :fruits, Devise::CONTROLLERS[:kivi]
|
59
|
-
Devise::ALL.delete(:kivi)
|
60
|
-
Devise::CONTROLLERS.delete(:kivi)
|
61
|
-
end
|
62
|
-
|
63
|
-
test 'should complain when comparing empty or different sized passes' do
|
64
|
-
[nil, ""].each do |empty|
|
65
|
-
assert_not Devise.secure_compare(empty, "something")
|
66
|
-
assert_not Devise.secure_compare("something", empty)
|
67
|
-
assert_not Devise.secure_compare(empty, empty)
|
68
|
-
end
|
69
|
-
assert_not Devise.secure_compare("size_1", "size_four")
|
70
|
-
end
|
71
|
-
|
72
|
-
test 'Devise.email_regexp should match valid email addresses' do
|
73
|
-
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"]
|
74
|
-
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com"]
|
75
|
-
|
76
|
-
valid_emails.each do |email|
|
77
|
-
assert_match Devise.email_regexp, email
|
78
|
-
end
|
79
|
-
non_valid_emails.each do |email|
|
80
|
-
assert_no_match Devise.email_regexp, email
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|