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,443 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ConfirmableTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
setup_mailer
|
7
|
-
end
|
8
|
-
|
9
|
-
test 'should generate confirmation token after creating a record' do
|
10
|
-
assert_nil new_user.confirmation_token
|
11
|
-
assert_not_nil create_user.confirmation_token
|
12
|
-
end
|
13
|
-
|
14
|
-
test 'should never generate the same confirmation token for different users' do
|
15
|
-
confirmation_tokens = []
|
16
|
-
3.times do
|
17
|
-
token = create_user.confirmation_token
|
18
|
-
assert !confirmation_tokens.include?(token)
|
19
|
-
confirmation_tokens << token
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'should confirm a user by updating confirmed at' do
|
24
|
-
user = create_user
|
25
|
-
assert_nil user.confirmed_at
|
26
|
-
assert user.confirm!
|
27
|
-
assert_not_nil user.confirmed_at
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'should clear confirmation token while confirming a user' do
|
31
|
-
user = create_user
|
32
|
-
assert_present user.confirmation_token
|
33
|
-
user.confirm!
|
34
|
-
assert_nil user.confirmation_token
|
35
|
-
end
|
36
|
-
|
37
|
-
test 'should verify whether a user is confirmed or not' do
|
38
|
-
assert_not new_user.confirmed?
|
39
|
-
user = create_user
|
40
|
-
assert_not user.confirmed?
|
41
|
-
user.confirm!
|
42
|
-
assert user.confirmed?
|
43
|
-
end
|
44
|
-
|
45
|
-
test 'should not confirm a user already confirmed' do
|
46
|
-
user = create_user
|
47
|
-
assert user.confirm!
|
48
|
-
assert_blank user.errors[:email]
|
49
|
-
|
50
|
-
assert_not user.confirm!
|
51
|
-
assert_equal "was already confirmed, please try signing in", user.errors[:email].join
|
52
|
-
end
|
53
|
-
|
54
|
-
test 'should find and confirm a user automatically' do
|
55
|
-
user = create_user
|
56
|
-
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
57
|
-
assert_equal confirmed_user, user
|
58
|
-
assert user.reload.confirmed?
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'should return a new record with errors when a invalid token is given' do
|
62
|
-
confirmed_user = User.confirm_by_token('invalid_confirmation_token')
|
63
|
-
assert_not confirmed_user.persisted?
|
64
|
-
assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
|
65
|
-
end
|
66
|
-
|
67
|
-
test 'should return a new record with errors when a blank token is given' do
|
68
|
-
confirmed_user = User.confirm_by_token('')
|
69
|
-
assert_not confirmed_user.persisted?
|
70
|
-
assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'should generate errors for a user email if user is already confirmed' do
|
74
|
-
user = create_user
|
75
|
-
user.confirmed_at = Time.now
|
76
|
-
user.save
|
77
|
-
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
78
|
-
assert confirmed_user.confirmed?
|
79
|
-
assert_equal "was already confirmed, please try signing in", confirmed_user.errors[:email].join
|
80
|
-
end
|
81
|
-
|
82
|
-
test 'should send confirmation instructions by email' do
|
83
|
-
assert_email_sent "mynewuser@example.com" do
|
84
|
-
create_user :email => "mynewuser@example.com"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
test 'should not send confirmation when trying to save an invalid user' do
|
89
|
-
assert_email_not_sent do
|
90
|
-
user = new_user
|
91
|
-
user.stubs(:valid?).returns(false)
|
92
|
-
user.save
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
test 'should not generate a new token neither send e-mail if skip_confirmation! is invoked' do
|
97
|
-
user = new_user
|
98
|
-
user.skip_confirmation!
|
99
|
-
|
100
|
-
assert_email_not_sent do
|
101
|
-
user.save!
|
102
|
-
assert_nil user.confirmation_token
|
103
|
-
assert_not_nil user.confirmed_at
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do
|
108
|
-
user = new_user
|
109
|
-
user.skip_confirmation_notification!
|
110
|
-
|
111
|
-
assert_email_not_sent do
|
112
|
-
user.save!
|
113
|
-
assert !user.confirmed?
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
test 'should not send confirmation when no email is provided' do
|
118
|
-
assert_email_not_sent do
|
119
|
-
user = new_user
|
120
|
-
user.email = ''
|
121
|
-
user.save(:validate => false)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
test 'should find a user to send confirmation instructions' do
|
126
|
-
user = create_user
|
127
|
-
confirmation_user = User.send_confirmation_instructions(:email => user.email)
|
128
|
-
assert_equal confirmation_user, user
|
129
|
-
end
|
130
|
-
|
131
|
-
test 'should return a new user if no email was found' do
|
132
|
-
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
|
133
|
-
assert_not confirmation_user.persisted?
|
134
|
-
end
|
135
|
-
|
136
|
-
test 'should add error to new user email if no email was found' do
|
137
|
-
confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
|
138
|
-
assert confirmation_user.errors[:email]
|
139
|
-
assert_equal "not found", confirmation_user.errors[:email].join
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'should send email instructions for the user confirm its email' do
|
143
|
-
user = create_user
|
144
|
-
assert_email_sent user.email do
|
145
|
-
User.send_confirmation_instructions(:email => user.email)
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
test 'should always have confirmation token when email is sent' do
|
150
|
-
user = new_user
|
151
|
-
user.instance_eval { def confirmation_required?; false end }
|
152
|
-
user.save
|
153
|
-
user.send_confirmation_instructions
|
154
|
-
assert_not_nil user.reload.confirmation_token
|
155
|
-
end
|
156
|
-
|
157
|
-
test 'should not resend email instructions if the user change his email' do
|
158
|
-
user = create_user
|
159
|
-
user.email = 'new_test@example.com'
|
160
|
-
assert_email_not_sent do
|
161
|
-
user.save!
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
test 'should not reset confirmation status or token when updating email' do
|
166
|
-
user = create_user
|
167
|
-
user.confirm!
|
168
|
-
user.email = 'new_test@example.com'
|
169
|
-
user.save!
|
170
|
-
|
171
|
-
user.reload
|
172
|
-
assert user.confirmed?
|
173
|
-
assert_nil user.confirmation_token
|
174
|
-
end
|
175
|
-
|
176
|
-
test 'should not be able to send instructions if the user is already confirmed' do
|
177
|
-
user = create_user
|
178
|
-
user.confirm!
|
179
|
-
assert_not user.resend_confirmation_token
|
180
|
-
assert user.confirmed?
|
181
|
-
assert_equal 'was already confirmed, please try signing in', user.errors[:email].join
|
182
|
-
end
|
183
|
-
|
184
|
-
test 'confirm time should fallback to devise confirm in default configuration' do
|
185
|
-
swap Devise, :allow_unconfirmed_access_for => 1.day do
|
186
|
-
user = new_user
|
187
|
-
user.confirmation_sent_at = 2.days.ago
|
188
|
-
assert_not user.active_for_authentication?
|
189
|
-
|
190
|
-
Devise.allow_unconfirmed_access_for = 3.days
|
191
|
-
assert user.active_for_authentication?
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
test 'should be active when confirmation sent at is not overpast' do
|
196
|
-
swap Devise, :allow_unconfirmed_access_for => 5.days do
|
197
|
-
Devise.allow_unconfirmed_access_for = 5.days
|
198
|
-
user = create_user
|
199
|
-
|
200
|
-
user.confirmation_sent_at = 4.days.ago
|
201
|
-
assert user.active_for_authentication?
|
202
|
-
|
203
|
-
user.confirmation_sent_at = 5.days.ago
|
204
|
-
assert_not user.active_for_authentication?
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
test 'should be active when already confirmed' do
|
209
|
-
user = create_user
|
210
|
-
assert_not user.confirmed?
|
211
|
-
assert_not user.active_for_authentication?
|
212
|
-
|
213
|
-
user.confirm!
|
214
|
-
assert user.confirmed?
|
215
|
-
assert user.active_for_authentication?
|
216
|
-
end
|
217
|
-
|
218
|
-
test 'should not be active when confirm in is zero' do
|
219
|
-
Devise.allow_unconfirmed_access_for = 0.days
|
220
|
-
user = create_user
|
221
|
-
user.confirmation_sent_at = Date.today
|
222
|
-
assert_not user.active_for_authentication?
|
223
|
-
end
|
224
|
-
|
225
|
-
test 'should be active when we set allow_unconfirmed_access_for to nil' do
|
226
|
-
Devise.allow_unconfirmed_access_for = nil
|
227
|
-
user = create_user
|
228
|
-
user.confirmation_sent_at = Date.today
|
229
|
-
assert user.active_for_authentication?
|
230
|
-
end
|
231
|
-
|
232
|
-
test 'should not be active without confirmation' do
|
233
|
-
user = create_user
|
234
|
-
user.confirmation_sent_at = nil
|
235
|
-
user.save
|
236
|
-
assert_not user.reload.active_for_authentication?
|
237
|
-
end
|
238
|
-
|
239
|
-
test 'should be active without confirmation when confirmation is not required' do
|
240
|
-
user = create_user
|
241
|
-
user.instance_eval { def confirmation_required?; false end }
|
242
|
-
user.confirmation_sent_at = nil
|
243
|
-
user.save
|
244
|
-
assert user.reload.active_for_authentication?
|
245
|
-
end
|
246
|
-
|
247
|
-
test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do
|
248
|
-
swap Devise, :authentication_keys => [:username, :email] do
|
249
|
-
user = create_user
|
250
|
-
confirm_user = User.send_confirmation_instructions(:email => user.email, :username => user.username)
|
251
|
-
assert_equal confirm_user, user
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
test 'should require all confirmation_keys' do
|
256
|
-
swap Devise, :confirmation_keys => [:username, :email] do
|
257
|
-
user = create_user
|
258
|
-
confirm_user = User.send_confirmation_instructions(:email => user.email)
|
259
|
-
assert_not confirm_user.persisted?
|
260
|
-
assert_equal "can't be blank", confirm_user.errors[:username].join
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
|
-
def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
|
265
|
-
user = create_user
|
266
|
-
user.update_attribute(:confirmation_sent_at, confirmation_sent_at)
|
267
|
-
confirmed_user = User.confirm_by_token(user.confirmation_token)
|
268
|
-
assert_equal confirmed_user, user
|
269
|
-
user.reload.confirmed?
|
270
|
-
end
|
271
|
-
|
272
|
-
test 'should accept confirmation email token even after 5 years when no expiration is set' do
|
273
|
-
assert confirm_user_by_token_with_confirmation_sent_at(5.years.ago)
|
274
|
-
end
|
275
|
-
|
276
|
-
test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do
|
277
|
-
swap Devise, :confirm_within => 3.days do
|
278
|
-
assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
|
283
|
-
swap Devise, :confirm_within => 3.days do
|
284
|
-
assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
test 'should generate a new token if the previous one has expired' do
|
289
|
-
swap Devise, :confirm_within => 3.days do
|
290
|
-
user = create_user
|
291
|
-
user.update_attribute(:confirmation_sent_at, 4.days.ago)
|
292
|
-
old = user.confirmation_token
|
293
|
-
user.resend_confirmation_token
|
294
|
-
assert_not_equal user.confirmation_token, old
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
test 'should generate a new token when a valid one does not exist' do
|
299
|
-
swap Devise, :confirm_within => 3.days do
|
300
|
-
user = create_user
|
301
|
-
user.update_attribute(:confirmation_sent_at, 4.days.ago)
|
302
|
-
old = user.confirmation_token
|
303
|
-
user.ensure_confirmation_token!
|
304
|
-
assert_not_equal user.confirmation_token, old
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
test 'should not generate a new token when a valid one exists' do
|
309
|
-
user = create_user
|
310
|
-
assert_not_nil user.confirmation_token
|
311
|
-
old = user.confirmation_token
|
312
|
-
user.ensure_confirmation_token!
|
313
|
-
assert_equal user.confirmation_token, old
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
class ReconfirmableTest < ActiveSupport::TestCase
|
318
|
-
test 'should not worry about validations on confirm even with reconfirmable' do
|
319
|
-
admin = create_admin
|
320
|
-
admin.reset_password_token = "a"
|
321
|
-
assert admin.confirm!
|
322
|
-
end
|
323
|
-
|
324
|
-
test 'should generate confirmation token after changing email' do
|
325
|
-
admin = create_admin
|
326
|
-
assert admin.confirm!
|
327
|
-
assert_nil admin.confirmation_token
|
328
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
329
|
-
assert_not_nil admin.confirmation_token
|
330
|
-
end
|
331
|
-
|
332
|
-
test 'should not generate confirmation token if skipping reconfirmation after changing email' do
|
333
|
-
admin = create_admin
|
334
|
-
assert admin.confirm!
|
335
|
-
admin.skip_reconfirmation!
|
336
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
337
|
-
assert_nil admin.confirmation_token
|
338
|
-
end
|
339
|
-
|
340
|
-
test 'should regenerate confirmation token after changing email' do
|
341
|
-
admin = create_admin
|
342
|
-
assert admin.confirm!
|
343
|
-
assert admin.update_attributes(:email => 'old_test@example.com')
|
344
|
-
token = admin.confirmation_token
|
345
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
346
|
-
assert_not_equal token, admin.confirmation_token
|
347
|
-
end
|
348
|
-
|
349
|
-
test 'should send confirmation instructions by email after changing email' do
|
350
|
-
admin = create_admin
|
351
|
-
assert admin.confirm!
|
352
|
-
assert_email_sent "new_test@example.com" do
|
353
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
354
|
-
end
|
355
|
-
assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
|
356
|
-
end
|
357
|
-
|
358
|
-
test 'should not send confirmation by email after changing password' do
|
359
|
-
admin = create_admin
|
360
|
-
assert admin.confirm!
|
361
|
-
assert_email_not_sent do
|
362
|
-
assert admin.update_attributes(:password => 'newpass', :password_confirmation => 'newpass')
|
363
|
-
end
|
364
|
-
end
|
365
|
-
|
366
|
-
test 'should not send confirmation by email after changing to a blank email' do
|
367
|
-
admin = create_admin
|
368
|
-
assert admin.confirm!
|
369
|
-
assert_email_not_sent do
|
370
|
-
admin.email = ''
|
371
|
-
admin.save(:validate => false)
|
372
|
-
end
|
373
|
-
end
|
374
|
-
|
375
|
-
test 'should stay confirmed when email is changed' do
|
376
|
-
admin = create_admin
|
377
|
-
assert admin.confirm!
|
378
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
379
|
-
assert admin.confirmed?
|
380
|
-
end
|
381
|
-
|
382
|
-
test 'should update email only when it is confirmed' do
|
383
|
-
admin = create_admin
|
384
|
-
assert admin.confirm!
|
385
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
386
|
-
assert_not_equal 'new_test@example.com', admin.email
|
387
|
-
assert admin.confirm!
|
388
|
-
assert_equal 'new_test@example.com', admin.email
|
389
|
-
end
|
390
|
-
|
391
|
-
test 'should not allow admin to get past confirmation email by resubmitting their new address' do
|
392
|
-
admin = create_admin
|
393
|
-
assert admin.confirm!
|
394
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
395
|
-
assert_not_equal 'new_test@example.com', admin.email
|
396
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
397
|
-
assert_not_equal 'new_test@example.com', admin.email
|
398
|
-
end
|
399
|
-
|
400
|
-
test 'should find a admin by send confirmation instructions with unconfirmed_email' do
|
401
|
-
admin = create_admin
|
402
|
-
assert admin.confirm!
|
403
|
-
assert admin.update_attributes(:email => 'new_test@example.com')
|
404
|
-
confirmation_admin = Admin.send_confirmation_instructions(:email => admin.unconfirmed_email)
|
405
|
-
assert_equal confirmation_admin, admin
|
406
|
-
end
|
407
|
-
|
408
|
-
test 'should return a new admin if no email or unconfirmed_email was found' do
|
409
|
-
confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
|
410
|
-
assert_not confirmation_admin.persisted?
|
411
|
-
end
|
412
|
-
|
413
|
-
test 'should add error to new admin email if no email or unconfirmed_email was found' do
|
414
|
-
confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
|
415
|
-
assert confirmation_admin.errors[:email]
|
416
|
-
assert_equal "not found", confirmation_admin.errors[:email].join
|
417
|
-
end
|
418
|
-
|
419
|
-
test 'should find admin with email in unconfirmed_emails' do
|
420
|
-
admin = create_admin
|
421
|
-
admin.unconfirmed_email = "new_test@email.com"
|
422
|
-
assert admin.save
|
423
|
-
admin = Admin.find_by_unconfirmed_email_with_errors(:email => "new_test@email.com")
|
424
|
-
assert admin.persisted?
|
425
|
-
end
|
426
|
-
|
427
|
-
test 'required_fields should contain the fields that Devise uses' do
|
428
|
-
assert_same_content Devise::Models::Confirmable.required_fields(User), [
|
429
|
-
:confirmation_sent_at,
|
430
|
-
:confirmation_token,
|
431
|
-
:confirmed_at
|
432
|
-
]
|
433
|
-
end
|
434
|
-
|
435
|
-
test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do
|
436
|
-
assert_same_content Devise::Models::Confirmable.required_fields(Admin), [
|
437
|
-
:confirmation_sent_at,
|
438
|
-
:confirmation_token,
|
439
|
-
:confirmed_at,
|
440
|
-
:unconfirmed_email
|
441
|
-
]
|
442
|
-
end
|
443
|
-
end
|
@@ -1,226 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'test_models'
|
3
|
-
require 'digest/sha1'
|
4
|
-
|
5
|
-
class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
6
|
-
test 'should downcase case insensitive keys when saving' do
|
7
|
-
# case_insensitive_keys is set to :email by default.
|
8
|
-
email = 'Foo@Bar.com'
|
9
|
-
user = new_user(:email => email)
|
10
|
-
|
11
|
-
assert_equal email, user.email
|
12
|
-
user.save!
|
13
|
-
assert_equal email.downcase, user.email
|
14
|
-
end
|
15
|
-
|
16
|
-
test 'should downcase case insensitive keys that refer to virtual attributes when saving' do
|
17
|
-
email = 'Foo@Bar1.com'
|
18
|
-
confirmation = 'Foo@Bar1.com'
|
19
|
-
attributes = valid_attributes(:email => email, :email_confirmation => confirmation)
|
20
|
-
user = UserWithVirtualAttributes.new(attributes)
|
21
|
-
|
22
|
-
assert_equal confirmation, user.email_confirmation
|
23
|
-
user.save!
|
24
|
-
assert_equal confirmation.downcase, user.email_confirmation
|
25
|
-
end
|
26
|
-
|
27
|
-
test 'should remove whitespace from strip whitespace keys when saving' do
|
28
|
-
# strip_whitespace_keys is set to :email by default.
|
29
|
-
email = ' foo@bar.com '
|
30
|
-
user = new_user(:email => email)
|
31
|
-
|
32
|
-
assert_equal email, user.email
|
33
|
-
user.save!
|
34
|
-
assert_equal email.strip, user.email
|
35
|
-
end
|
36
|
-
|
37
|
-
test "doesn't throw exception when globally configured strip_whitespace_keys are not present on a model" do
|
38
|
-
swap Devise, :strip_whitespace_keys => [:fake_key] do
|
39
|
-
assert_nothing_raised { create_user }
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
test "doesn't throw exception when globally configured case_insensitive_keys are not present on a model" do
|
44
|
-
swap Devise, :case_insensitive_keys => [:fake_key] do
|
45
|
-
assert_nothing_raised { create_user }
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
test "param filter should not convert booleans and integer to strings" do
|
50
|
-
conditions = { "login" => "foo@bar.com", "bool1" => true, "bool2" => false, "fixnum" => 123, "will_be_converted" => (1..10) }
|
51
|
-
conditions = Devise::ParameterFilter.new([], []).filter(conditions)
|
52
|
-
assert_equal( { "login" => "foo@bar.com", "bool1" => "true", "bool2" => "false", "fixnum" => "123", "will_be_converted" => "1..10" }, conditions)
|
53
|
-
end
|
54
|
-
|
55
|
-
test 'param filter should filter case_insensitive_keys as insensitive' do
|
56
|
-
conditions = {'insensitive' => 'insensitive_VAL', 'sensitive' => 'sensitive_VAL'}
|
57
|
-
conditions = Devise::ParameterFilter.new(['insensitive'], []).filter(conditions)
|
58
|
-
assert_equal( {'insensitive' => 'insensitive_val', 'sensitive' => 'sensitive_VAL'}, conditions )
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'param filter should filter strip_whitespace_keys stripping whitespaces' do
|
62
|
-
conditions = {'strip_whitespace' => ' strip_whitespace_val ', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}
|
63
|
-
conditions = Devise::ParameterFilter.new([], ['strip_whitespace']).filter(conditions)
|
64
|
-
assert_equal( {'strip_whitespace' => 'strip_whitespace_val', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}, conditions )
|
65
|
-
end
|
66
|
-
|
67
|
-
test 'should respond to password and password confirmation' do
|
68
|
-
user = new_user
|
69
|
-
assert user.respond_to?(:password)
|
70
|
-
assert user.respond_to?(:password_confirmation)
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'should generate encrypted password while setting password' do
|
74
|
-
user = new_user
|
75
|
-
assert_present user.encrypted_password
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'allow authenticatable_salt to work even with nil encrypted password' do
|
79
|
-
user = User.new
|
80
|
-
user.encrypted_password = nil
|
81
|
-
assert_nil user.authenticatable_salt
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'should not generate encrypted password if password is blank' do
|
85
|
-
assert_blank new_user(:password => nil).encrypted_password
|
86
|
-
assert_blank new_user(:password => '').encrypted_password
|
87
|
-
end
|
88
|
-
|
89
|
-
test 'should encrypt password again if password has changed' do
|
90
|
-
user = create_user
|
91
|
-
encrypted_password = user.encrypted_password
|
92
|
-
user.password = user.password_confirmation = 'new_password'
|
93
|
-
user.save!
|
94
|
-
assert_not_equal encrypted_password, user.encrypted_password
|
95
|
-
end
|
96
|
-
|
97
|
-
test 'should test for a valid password' do
|
98
|
-
user = create_user
|
99
|
-
assert user.valid_password?('12345678')
|
100
|
-
assert_not user.valid_password?('654321')
|
101
|
-
end
|
102
|
-
|
103
|
-
test 'should not raise error with an empty password' do
|
104
|
-
user = create_user
|
105
|
-
user.encrypted_password = ''
|
106
|
-
assert_nothing_raised { user.valid_password?('12345678') }
|
107
|
-
end
|
108
|
-
|
109
|
-
test 'should be an invalid password if the user has an empty password' do
|
110
|
-
user = create_user
|
111
|
-
user.encrypted_password = ''
|
112
|
-
assert_not user.valid_password?('654321')
|
113
|
-
end
|
114
|
-
|
115
|
-
test 'should respond to current password' do
|
116
|
-
assert new_user.respond_to?(:current_password)
|
117
|
-
end
|
118
|
-
|
119
|
-
test 'should update password with valid current password' do
|
120
|
-
user = create_user
|
121
|
-
assert user.update_with_password(:current_password => '12345678',
|
122
|
-
:password => 'pass4321', :password_confirmation => 'pass4321')
|
123
|
-
assert user.reload.valid_password?('pass4321')
|
124
|
-
end
|
125
|
-
|
126
|
-
test 'should add an error to current password when it is invalid' do
|
127
|
-
user = create_user
|
128
|
-
assert_not user.update_with_password(:current_password => 'other',
|
129
|
-
:password => 'pass4321', :password_confirmation => 'pass4321')
|
130
|
-
assert user.reload.valid_password?('12345678')
|
131
|
-
assert_match "is invalid", user.errors[:current_password].join
|
132
|
-
end
|
133
|
-
|
134
|
-
test 'should add an error to current password when it is blank' do
|
135
|
-
user = create_user
|
136
|
-
assert_not user.update_with_password(:password => 'pass4321',
|
137
|
-
:password_confirmation => 'pass4321')
|
138
|
-
assert user.reload.valid_password?('12345678')
|
139
|
-
assert_match "can't be blank", user.errors[:current_password].join
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'should run validations even when current password is invalid or blank' do
|
143
|
-
user = UserWithValidation.create!(valid_attributes)
|
144
|
-
user.save
|
145
|
-
assert user.persisted?
|
146
|
-
assert_not user.update_with_password(:username => "")
|
147
|
-
assert_match "usertest", user.reload.username
|
148
|
-
assert_match "can't be blank", user.errors[:username].join
|
149
|
-
end
|
150
|
-
|
151
|
-
test 'should ignore password and its confirmation if they are blank' do
|
152
|
-
user = create_user
|
153
|
-
assert user.update_with_password(:current_password => '12345678', :email => "new@example.com")
|
154
|
-
assert_equal "new@example.com", user.email
|
155
|
-
end
|
156
|
-
|
157
|
-
test 'should not update password with invalid confirmation' do
|
158
|
-
user = create_user
|
159
|
-
assert_not user.update_with_password(:current_password => '12345678',
|
160
|
-
:password => 'pass4321', :password_confirmation => 'other')
|
161
|
-
assert user.reload.valid_password?('12345678')
|
162
|
-
end
|
163
|
-
|
164
|
-
test 'should clean up password fields on failure' do
|
165
|
-
user = create_user
|
166
|
-
assert_not user.update_with_password(:current_password => '12345678',
|
167
|
-
:password => 'pass4321', :password_confirmation => 'other')
|
168
|
-
assert user.password.blank?
|
169
|
-
assert user.password_confirmation.blank?
|
170
|
-
end
|
171
|
-
|
172
|
-
test 'should update the user without password' do
|
173
|
-
user = create_user
|
174
|
-
user.update_without_password(:email => 'new@example.com')
|
175
|
-
assert_equal 'new@example.com', user.email
|
176
|
-
end
|
177
|
-
|
178
|
-
test 'should not update password without password' do
|
179
|
-
user = create_user
|
180
|
-
user.update_without_password(:password => 'pass4321', :password_confirmation => 'pass4321')
|
181
|
-
assert !user.reload.valid_password?('pass4321')
|
182
|
-
assert user.valid_password?('12345678')
|
183
|
-
end
|
184
|
-
|
185
|
-
test 'should destroy user if current password is valid' do
|
186
|
-
user = create_user
|
187
|
-
assert user.destroy_with_password('12345678')
|
188
|
-
assert !user.persisted?
|
189
|
-
end
|
190
|
-
|
191
|
-
test 'should not destroy user with invalid password' do
|
192
|
-
user = create_user
|
193
|
-
assert_not user.destroy_with_password('other')
|
194
|
-
assert user.persisted?
|
195
|
-
assert_match "is invalid", user.errors[:current_password].join
|
196
|
-
end
|
197
|
-
|
198
|
-
test 'should not destroy user with blank password' do
|
199
|
-
user = create_user
|
200
|
-
assert_not user.destroy_with_password(nil)
|
201
|
-
assert user.persisted?
|
202
|
-
assert_match "can't be blank", user.errors[:current_password].join
|
203
|
-
end
|
204
|
-
|
205
|
-
test 'downcase_keys with validation' do
|
206
|
-
user = User.create(:email => "HEllO@example.com", :password => "123456")
|
207
|
-
user = User.create(:email => "HEllO@example.com", :password => "123456")
|
208
|
-
assert !user.valid?
|
209
|
-
end
|
210
|
-
|
211
|
-
test 'required_fiels should be encryptable_password and the email field by default' do
|
212
|
-
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
213
|
-
:email,
|
214
|
-
:encrypted_password
|
215
|
-
]
|
216
|
-
end
|
217
|
-
|
218
|
-
test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do
|
219
|
-
swap Devise, :authentication_keys => [:login] do
|
220
|
-
assert_same_content Devise::Models::DatabaseAuthenticatable.required_fields(User), [
|
221
|
-
:encrypted_password,
|
222
|
-
:login
|
223
|
-
]
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|