devise_invitable 1.5.5 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -7
- data/CHANGELOG +21 -0
- data/README.rdoc +32 -14
- data/app/controllers/devise/invitations_controller.rb +19 -7
- data/app/views/devise/invitations/edit.html.erb +2 -0
- data/app/views/devise/mailer/invitation_instructions.text.erb +11 -0
- data/config/locales/en.yml +1 -1
- data/lib/devise_invitable/controllers/helpers.rb +2 -2
- data/lib/devise_invitable/mapping.rb +3 -7
- data/lib/devise_invitable/model.rb +55 -20
- data/lib/devise_invitable/parameter_sanitizer.rb +27 -19
- data/lib/devise_invitable/rails.rb +2 -2
- data/lib/devise_invitable/version.rb +1 -1
- data/lib/devise_invitable.rb +7 -1
- data/lib/generators/devise_invitable/install_generator.rb +2 -2
- data/test/functional/controller_helpers_test.rb +11 -6
- data/test/mailers/invitation_mail_test.rb +20 -6
- data/test/models/invitable_test.rb +102 -67
- data/test/rails_app/app/models/user.rb +8 -3
- data/test/rails_app/config/application.rb +5 -1
- data/test/rails_app/config/database.yml +2 -1
- data/test/rails_app/config/environments/test.rb +6 -0
- data/test/rails_app/config/initializers/devise.rb +1 -1
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +1 -1
- data/test/test_helper.rb +14 -4
- metadata +51 -46
|
@@ -29,9 +29,9 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
29
29
|
user = new_user
|
|
30
30
|
user.invite!
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
refute_nil user.invitation_token
|
|
33
|
+
refute_nil user.raw_invitation_token
|
|
34
|
+
refute_nil user.invitation_created_at
|
|
35
35
|
|
|
36
36
|
3.times do
|
|
37
37
|
user = User.find(user.id)
|
|
@@ -40,7 +40,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
40
40
|
user.invite!
|
|
41
41
|
user.invitation_token
|
|
42
42
|
}.call
|
|
43
|
-
|
|
43
|
+
refute_nil user.raw_invitation_token
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -49,8 +49,8 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
49
49
|
user.skip_invitation = true
|
|
50
50
|
user.invite!
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
refute_nil user.invitation_token
|
|
53
|
+
refute_nil user.invitation_created_at
|
|
54
54
|
|
|
55
55
|
3.times do
|
|
56
56
|
user = User.find(user.id)
|
|
@@ -60,8 +60,8 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
60
60
|
user.invite!
|
|
61
61
|
user.invitation_token
|
|
62
62
|
}.call
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
refute_nil user.invitation_token
|
|
64
|
+
refute_nil user.raw_invitation_token
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
@@ -88,8 +88,8 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
88
88
|
user.update_attributes(:invitation_sent_at => old_invitation_sent_at, :invitation_created_at => old_invitation_created_at)
|
|
89
89
|
3.times do
|
|
90
90
|
user.invite!
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
refute_equal old_invitation_sent_at, user.invitation_sent_at
|
|
92
|
+
refute_equal old_invitation_created_at, user.invitation_created_at
|
|
93
93
|
user.update_attributes(:invitation_sent_at => old_invitation_sent_at, :invitation_created_at => old_invitation_created_at)
|
|
94
94
|
end
|
|
95
95
|
end
|
|
@@ -99,31 +99,32 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
99
99
|
|
|
100
100
|
User.stubs(:invite_for).returns(nil)
|
|
101
101
|
user.invitation_created_at = Time.now.utc
|
|
102
|
-
|
|
102
|
+
assert_predicate user, :valid_invitation?
|
|
103
103
|
|
|
104
104
|
User.stubs(:invite_for).returns(nil)
|
|
105
105
|
user.invitation_created_at = 1.year.ago
|
|
106
|
-
|
|
106
|
+
assert_predicate user, :valid_invitation?
|
|
107
107
|
|
|
108
108
|
User.stubs(:invite_for).returns(0)
|
|
109
109
|
user.invitation_created_at = Time.now.utc
|
|
110
|
-
|
|
110
|
+
assert_predicate user, :valid_invitation?
|
|
111
111
|
|
|
112
112
|
User.stubs(:invite_for).returns(0)
|
|
113
113
|
user.invitation_created_at = 1.day.ago
|
|
114
|
-
|
|
114
|
+
assert_predicate user, :valid_invitation?
|
|
115
115
|
|
|
116
116
|
User.stubs(:invite_for).returns(1.day)
|
|
117
117
|
user.invitation_created_at = Time.now.utc
|
|
118
|
-
|
|
118
|
+
assert_predicate user, :valid_invitation?
|
|
119
119
|
|
|
120
120
|
User.stubs(:invite_for).returns(1.day)
|
|
121
121
|
user.invitation_created_at = 2.days.ago
|
|
122
|
-
|
|
122
|
+
refute_predicate user, :valid_invitation?
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
test 'should return token validity when there is invite_for' do
|
|
126
126
|
User.stubs(:invite_for).returns(1.day)
|
|
127
|
+
|
|
127
128
|
user = User.invite!(:email => "valid@email.com")
|
|
128
129
|
sent_at = user.invitation_created_at || user.invitation_sent_at
|
|
129
130
|
valid_until = sent_at + User.invite_for
|
|
@@ -131,20 +132,27 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
131
132
|
assert_equal user.invitation_due_at, valid_until
|
|
132
133
|
end
|
|
133
134
|
|
|
134
|
-
test 'should return nil
|
|
135
|
+
test 'should return nil for invitation due date when invite_for is nil' do
|
|
135
136
|
User.stubs(:invite_for).returns(nil)
|
|
136
137
|
user = User.invite!(:email => "valid@email.com")
|
|
137
138
|
|
|
138
139
|
assert_equal user.invitation_due_at, nil
|
|
139
140
|
end
|
|
140
141
|
|
|
142
|
+
test 'should return nil for invitation due date when invite_for is 0' do
|
|
143
|
+
User.stubs(:invite_for).returns(0)
|
|
144
|
+
user = User.invite!(email: 'valid@email.com')
|
|
145
|
+
|
|
146
|
+
assert_equal user.invitation_due_at, nil
|
|
147
|
+
end
|
|
148
|
+
|
|
141
149
|
test 'should never generate the same invitation token for different users' do
|
|
142
150
|
invitation_tokens = []
|
|
143
151
|
3.times do
|
|
144
152
|
user = new_user
|
|
145
153
|
user.invite!
|
|
146
154
|
token = user.invitation_token
|
|
147
|
-
|
|
155
|
+
refute_includes invitation_tokens, token
|
|
148
156
|
invitation_tokens << token
|
|
149
157
|
end
|
|
150
158
|
end
|
|
@@ -152,36 +160,49 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
152
160
|
test 'should invite with multiple columns for invite key' do
|
|
153
161
|
User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/)
|
|
154
162
|
user = User.invite!(:email => "valid@email.com", :username => "name")
|
|
155
|
-
|
|
156
|
-
|
|
163
|
+
assert_predicate user, :persisted?
|
|
164
|
+
assert_empty user.errors
|
|
157
165
|
end
|
|
158
166
|
|
|
159
167
|
test 'should allow non-string columns for invite key' do
|
|
160
168
|
User.stubs(:invite_key).returns(:email => Devise.email_regexp, :profile_id => :present?.to_proc, :active => true)
|
|
161
169
|
user = User.invite!(:email => "valid@email.com", :profile_id => 1, :active => true)
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
assert_predicate user, :persisted?
|
|
171
|
+
assert_empty user.errors
|
|
164
172
|
end
|
|
165
173
|
|
|
166
174
|
test 'should not invite with some missing columns when invite key is an array' do
|
|
167
175
|
User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/, :profile_id => :present?.to_proc, :active => true)
|
|
168
176
|
user = User.invite!(:email => "valid@email.com")
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
assert_predicate user, :new_record?
|
|
178
|
+
refute_empty user.errors
|
|
171
179
|
assert user.errors[:username]
|
|
172
180
|
assert user.errors[:profile_id]
|
|
173
181
|
assert user.errors[:active]
|
|
174
|
-
|
|
182
|
+
assert_empty user.errors[:email]
|
|
175
183
|
end
|
|
176
184
|
|
|
177
185
|
test 'should return mail object' do
|
|
178
186
|
mail = User.invite_mail!(:email => 'valid@email.com')
|
|
179
|
-
|
|
187
|
+
assert_instance_of Mail::Message, mail
|
|
180
188
|
end
|
|
181
189
|
|
|
182
190
|
test 'should disallow login when invited' do
|
|
183
191
|
invited_user = User.invite!(:email => "valid@email.com")
|
|
184
|
-
|
|
192
|
+
refute invited_user.valid_password?('1234')
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
test 'should not accept invite without password' do
|
|
196
|
+
User.invite!(:email => "valid@email.com")
|
|
197
|
+
User.accept_invitation!(:invitation_token => Thread.current[:token])
|
|
198
|
+
refute_predicate User.where(:email => 'valid@email.com').first, :invitation_accepted?
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
test 'should accept invite without password if enforce is disabled' do
|
|
202
|
+
Devise.stubs(:require_password_on_accepting => false)
|
|
203
|
+
User.invite!(:email => "valid@email.com")
|
|
204
|
+
User.accept_invitation!(:invitation_token => Thread.current[:token])
|
|
205
|
+
assert_predicate User.where(:email => 'valid@email.com').first, :invitation_accepted?
|
|
185
206
|
end
|
|
186
207
|
|
|
187
208
|
test 'should set password and password confirmation from params' do
|
|
@@ -194,7 +215,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
194
215
|
user = User.invite!(:email => "valid@email.com")
|
|
195
216
|
old_encrypted_password = user.encrypted_password
|
|
196
217
|
user = User.accept_invitation!(:invitation_token => Thread.current[:token], :password => '123456789', :password_confirmation => '123456789')
|
|
197
|
-
|
|
218
|
+
refute_equal old_encrypted_password, user.encrypted_password
|
|
198
219
|
end
|
|
199
220
|
|
|
200
221
|
test 'should not override password on invite!' do
|
|
@@ -236,7 +257,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
236
257
|
User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
|
|
237
258
|
assert_nil user.reload.reset_password_token
|
|
238
259
|
assert_nil user.reload.invitation_token
|
|
239
|
-
|
|
260
|
+
refute_predicate user, :invited_to_sign_up?
|
|
240
261
|
end
|
|
241
262
|
|
|
242
263
|
test 'should not accept invitation on failing to reset the password' do
|
|
@@ -256,7 +277,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
256
277
|
|
|
257
278
|
test 'should not set invitation_accepted_at if just resetting password' do
|
|
258
279
|
user = User.create!(:email => "valid@email.com", :password => "123456780")
|
|
259
|
-
|
|
280
|
+
refute_predicate user, :invited_to_sign_up?
|
|
260
281
|
token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
|
|
261
282
|
user.reset_password_sent_at = Time.now.utc
|
|
262
283
|
user.save
|
|
@@ -273,30 +294,30 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
273
294
|
assert_difference('ActionMailer::Base.deliveries.size') do
|
|
274
295
|
token = user.invitation_token
|
|
275
296
|
user.invite!
|
|
276
|
-
|
|
297
|
+
refute_equal token, user.invitation_token
|
|
277
298
|
end
|
|
278
299
|
end
|
|
279
300
|
|
|
280
301
|
test 'should return a record with invitation token and no errors to send invitation by email' do
|
|
281
302
|
invited_user = User.invite!(:email => "valid@email.com")
|
|
282
|
-
|
|
283
|
-
|
|
303
|
+
assert_empty invited_user.errors
|
|
304
|
+
assert_predicate invited_user.invitation_token, :present?
|
|
284
305
|
assert_equal 'valid@email.com', invited_user.email
|
|
285
|
-
|
|
306
|
+
assert_predicate invited_user, :persisted?
|
|
286
307
|
end
|
|
287
308
|
|
|
288
309
|
test 'should set all attributes with no errors' do
|
|
289
310
|
invited_user = User.invite!(:email => "valid@email.com", :username => 'first name')
|
|
290
|
-
|
|
311
|
+
assert_empty invited_user.errors
|
|
291
312
|
assert_equal 'first name', invited_user.username
|
|
292
|
-
|
|
313
|
+
assert_predicate invited_user, :persisted?
|
|
293
314
|
end
|
|
294
315
|
|
|
295
316
|
test 'should not validate other attributes when validate_on_invite is disabled' do
|
|
296
317
|
validate_on_invite = User.validate_on_invite
|
|
297
318
|
User.validate_on_invite = false
|
|
298
319
|
invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
|
|
299
|
-
|
|
320
|
+
assert_empty invited_user.errors
|
|
300
321
|
User.validate_on_invite = validate_on_invite
|
|
301
322
|
end
|
|
302
323
|
|
|
@@ -304,7 +325,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
304
325
|
validate_on_invite = User.validate_on_invite
|
|
305
326
|
User.validate_on_invite = true
|
|
306
327
|
invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
|
|
307
|
-
|
|
328
|
+
refute_empty invited_user.errors[:username]
|
|
308
329
|
User.validate_on_invite = validate_on_invite
|
|
309
330
|
end
|
|
310
331
|
|
|
@@ -312,8 +333,8 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
312
333
|
validate_on_invite = User.validate_on_invite
|
|
313
334
|
User.validate_on_invite = true
|
|
314
335
|
invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
|
|
315
|
-
|
|
316
|
-
|
|
336
|
+
refute_empty invited_user.errors
|
|
337
|
+
assert_empty invited_user.errors[:password]
|
|
317
338
|
User.validate_on_invite = validate_on_invite
|
|
318
339
|
end
|
|
319
340
|
|
|
@@ -321,8 +342,8 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
321
342
|
validate_on_invite = User.validate_on_invite
|
|
322
343
|
User.validate_on_invite = true
|
|
323
344
|
invited_user = User.invite!(:email => "", :username => "a"*50)
|
|
324
|
-
|
|
325
|
-
|
|
345
|
+
refute_empty invited_user.errors[:email]
|
|
346
|
+
refute_empty invited_user.errors[:username]
|
|
326
347
|
User.validate_on_invite = validate_on_invite
|
|
327
348
|
end
|
|
328
349
|
|
|
@@ -363,7 +384,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
363
384
|
user = User.invite!(:email => "valid@email.com", :username => "a"*50)
|
|
364
385
|
assert_equal user, existing_user
|
|
365
386
|
assert_equal ['has already been taken'], user.errors[:email]
|
|
366
|
-
|
|
387
|
+
refute_empty user.errors[:username]
|
|
367
388
|
ensure
|
|
368
389
|
User.validate_on_invite = validate_on_invite
|
|
369
390
|
end
|
|
@@ -385,7 +406,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
385
406
|
invited_user = User.invite!(:email => "invalid_email.com", :username => 'first name')
|
|
386
407
|
assert invited_user.new_record?
|
|
387
408
|
assert_equal 'first name', invited_user.username
|
|
388
|
-
|
|
409
|
+
refute_empty invited_user.errors
|
|
389
410
|
end
|
|
390
411
|
|
|
391
412
|
test 'should find a user to set his password based on invitation_token' do
|
|
@@ -449,10 +470,10 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
449
470
|
:password_confirmation => 'new_password',
|
|
450
471
|
:username => 'a'*50
|
|
451
472
|
)
|
|
452
|
-
|
|
473
|
+
refute_empty invited_user.errors[:username]
|
|
453
474
|
|
|
454
475
|
user.reload
|
|
455
|
-
|
|
476
|
+
refute user.valid_password?('new_password')
|
|
456
477
|
end
|
|
457
478
|
|
|
458
479
|
test 'should check if created by invitation' do
|
|
@@ -492,7 +513,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
492
513
|
|
|
493
514
|
user.invite!
|
|
494
515
|
|
|
495
|
-
|
|
516
|
+
refute_predicate user, :confirmed?
|
|
496
517
|
end
|
|
497
518
|
|
|
498
519
|
test 'user.has_invitations_left? test' do
|
|
@@ -508,7 +529,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
508
529
|
# With an individual invitation_limit of 0, a user shouldn't be able to send an invitation
|
|
509
530
|
user.invitation_limit = 0
|
|
510
531
|
assert user.save
|
|
511
|
-
|
|
532
|
+
refute_predicate user, :has_invitations_left?
|
|
512
533
|
|
|
513
534
|
# With in invitation_limit of 2, a user should be able to send two invitations
|
|
514
535
|
user.invitation_limit = 2
|
|
@@ -536,7 +557,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
536
557
|
assert_no_difference('ActionMailer::Base.deliveries.size') do
|
|
537
558
|
user.invite!
|
|
538
559
|
end
|
|
539
|
-
|
|
560
|
+
assert_predicate user, :invitation_created_at
|
|
540
561
|
assert_nil user.invitation_sent_at
|
|
541
562
|
end
|
|
542
563
|
|
|
@@ -547,7 +568,7 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
547
568
|
u.skip_invitation = true
|
|
548
569
|
end
|
|
549
570
|
end
|
|
550
|
-
|
|
571
|
+
assert_predicate user, :invitation_created_at
|
|
551
572
|
assert_nil user.invitation_sent_at
|
|
552
573
|
end
|
|
553
574
|
|
|
@@ -568,17 +589,17 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
568
589
|
|
|
569
590
|
test 'user.accept_invitation! should trigger callbacks' do
|
|
570
591
|
user = User.invite!(:email => "valid@email.com")
|
|
571
|
-
assert_callbacks_not_fired user
|
|
592
|
+
assert_callbacks_not_fired :after_invitation_accepted, user
|
|
572
593
|
user.accept_invitation!
|
|
573
|
-
assert_callbacks_fired user
|
|
594
|
+
assert_callbacks_fired :after_invitation_accepted, user
|
|
574
595
|
end
|
|
575
596
|
|
|
576
597
|
test 'user.accept_invitation! should not trigger callbacks if validation fails' do
|
|
577
598
|
user = User.invite!(:email => "valid@email.com")
|
|
578
|
-
assert_callbacks_not_fired user
|
|
599
|
+
assert_callbacks_not_fired :after_invitation_accepted, user
|
|
579
600
|
user.username='a'*50
|
|
580
601
|
user.accept_invitation!
|
|
581
|
-
assert_callbacks_not_fired user
|
|
602
|
+
assert_callbacks_not_fired :after_invitation_accepted, user
|
|
582
603
|
end
|
|
583
604
|
|
|
584
605
|
test 'user.accept_invitation! should confirm user if confirmable' do
|
|
@@ -586,26 +607,28 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
586
607
|
user.accept_invitation!
|
|
587
608
|
|
|
588
609
|
assert user.confirmed?
|
|
610
|
+
refute user.changed?
|
|
589
611
|
end
|
|
590
612
|
|
|
591
613
|
test 'user.accept_invitation! should not confirm user if validation fails' do
|
|
592
614
|
user = User.invite!(:email => "valid@email.com")
|
|
593
615
|
user.username='a'*50
|
|
594
616
|
user.accept_invitation!
|
|
617
|
+
user.reload
|
|
595
618
|
|
|
596
|
-
|
|
619
|
+
refute_predicate user, :confirmed?
|
|
597
620
|
end
|
|
598
621
|
|
|
599
|
-
def assert_callbacks_fired(user)
|
|
600
|
-
assert_callbacks_status user, true
|
|
622
|
+
def assert_callbacks_fired(callback, user)
|
|
623
|
+
assert_callbacks_status callback, user, true
|
|
601
624
|
end
|
|
602
625
|
|
|
603
|
-
def assert_callbacks_not_fired(user)
|
|
604
|
-
assert_callbacks_status user, nil
|
|
626
|
+
def assert_callbacks_not_fired(callback, user)
|
|
627
|
+
assert_callbacks_status callback, user, nil
|
|
605
628
|
end
|
|
606
629
|
|
|
607
|
-
def assert_callbacks_status(user, fired)
|
|
608
|
-
assert_equal fired, user.
|
|
630
|
+
def assert_callbacks_status(callback, user, fired)
|
|
631
|
+
assert_equal fired, user.send("#{callback}_callback_works".to_sym)
|
|
609
632
|
end
|
|
610
633
|
|
|
611
634
|
test "user.invite! should downcase the class's case_insensitive_keys" do
|
|
@@ -621,32 +644,44 @@ class InvitableTest < ActiveSupport::TestCase
|
|
|
621
644
|
assert user.active == true
|
|
622
645
|
end
|
|
623
646
|
|
|
647
|
+
test "user.invite! should trigger callbacks" do
|
|
648
|
+
user = User.new(email: "valid@email.com")
|
|
649
|
+
assert_callbacks_not_fired :after_invitation_created, user
|
|
650
|
+
user.invite!
|
|
651
|
+
assert_callbacks_fired :after_invitation_created, user
|
|
652
|
+
end
|
|
653
|
+
|
|
624
654
|
test 'should pass validation before accept if field is required in post-invited instance' do
|
|
625
655
|
user = User.invite!(:email => "valid@email.com")
|
|
626
656
|
user.testing_accepted_or_not_invited = true
|
|
627
|
-
|
|
657
|
+
user.valid?
|
|
658
|
+
assert_empty user.errors
|
|
628
659
|
end
|
|
629
660
|
|
|
630
661
|
test 'should fail validation after accept if field is required in post-invited instance' do
|
|
631
662
|
user = User.invite!(:email => "valid@email.com")
|
|
632
663
|
user.testing_accepted_or_not_invited = true
|
|
633
|
-
user
|
|
634
|
-
|
|
664
|
+
assert_predicate user, :accept_invitation!
|
|
665
|
+
user = User.where(:email => "valid@email.com").first
|
|
666
|
+
user.valid?
|
|
667
|
+
refute_empty user.errors
|
|
635
668
|
end
|
|
636
669
|
|
|
637
670
|
test 'should pass validation after accept if field is required in post-invited instance' do
|
|
638
671
|
user = User.invite!(:email => "valid@email.com")
|
|
639
672
|
user.username = 'test'
|
|
640
673
|
user.testing_accepted_or_not_invited = true
|
|
674
|
+
assert_predicate user, :accept_invitation!
|
|
675
|
+
user = User.where(:email => "valid@email.com").first
|
|
641
676
|
user.bio = "Test"
|
|
642
|
-
user.
|
|
643
|
-
|
|
677
|
+
user.valid?
|
|
678
|
+
assert_empty user.errors
|
|
644
679
|
end
|
|
645
680
|
|
|
646
681
|
test 'should return instance with errors if invitation_token is nil' do
|
|
647
682
|
User.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
|
|
648
683
|
user = User.accept_invitation!
|
|
649
|
-
|
|
684
|
+
refute_empty user.errors
|
|
650
685
|
end
|
|
651
686
|
|
|
652
687
|
test "should count invited, created_by_invite, accepted and not accepted invitations" do
|
|
@@ -36,10 +36,11 @@ class User < PARENT_MODEL_CLASS
|
|
|
36
36
|
|
|
37
37
|
devise :database_authenticatable, :registerable, :validatable, :confirmable, :invitable, :recoverable
|
|
38
38
|
|
|
39
|
-
attr_accessor :
|
|
39
|
+
attr_accessor :after_invitation_created_callback_works, :after_invitation_accepted_callback_works, :bio, :token
|
|
40
40
|
validates :username, :length => { :maximum => 20 }
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
attr_accessor :testing_accepted_or_not_invited
|
|
43
|
+
|
|
43
44
|
validates :username, :presence => true, :if => :testing_accepted_or_not_invited_validator?
|
|
44
45
|
validates :bio, :presence => true, :if => :invitation_accepted?
|
|
45
46
|
|
|
@@ -47,8 +48,12 @@ class User < PARENT_MODEL_CLASS
|
|
|
47
48
|
testing_accepted_or_not_invited && accepted_or_not_invited?
|
|
48
49
|
end
|
|
49
50
|
|
|
51
|
+
after_invitation_created do |object|
|
|
52
|
+
object.after_invitation_created_callback_works = true
|
|
53
|
+
end
|
|
54
|
+
|
|
50
55
|
after_invitation_accepted do |object|
|
|
51
|
-
object.
|
|
56
|
+
object.after_invitation_accepted_callback_works = true
|
|
52
57
|
end
|
|
53
58
|
|
|
54
59
|
def send_devise_notification(method, raw, *args)
|
|
@@ -7,7 +7,8 @@ require "rails/test_unit/railtie"
|
|
|
7
7
|
Bundler.require(:default, DEVISE_ORM) if defined?(Bundler)
|
|
8
8
|
|
|
9
9
|
begin
|
|
10
|
-
require "#{DEVISE_ORM}
|
|
10
|
+
require "#{DEVISE_ORM}" if DEVISE_ORM == :mongoid
|
|
11
|
+
require "#{DEVISE_ORM}/railtie" unless DEVISE_ORM == :mongoid && Mongoid::VERSION >= '5.0.0'
|
|
11
12
|
rescue LoadError
|
|
12
13
|
end
|
|
13
14
|
PARENT_MODEL_CLASS = DEVISE_ORM == :active_record ? ActiveRecord::Base : Object
|
|
@@ -20,5 +21,8 @@ module RailsApp
|
|
|
20
21
|
class Application < Rails::Application
|
|
21
22
|
config.filter_parameters << :password
|
|
22
23
|
config.action_mailer.default_url_options = { :host => "localhost:3000" }
|
|
24
|
+
if DEVISE_ORM == :active_record && Rails.version.start_with?('5')
|
|
25
|
+
config.active_record.maintain_test_schema = false
|
|
26
|
+
end
|
|
23
27
|
end
|
|
24
28
|
end
|
|
@@ -28,6 +28,12 @@ RailsApp::Application.configure do
|
|
|
28
28
|
# like if you have constraints or database-specific column types
|
|
29
29
|
# config.active_record.schema_format = :sql
|
|
30
30
|
|
|
31
|
+
if Rails.version >= '4.2' && config.respond_to?(:active_record)
|
|
32
|
+
config.active_record.raise_in_transactional_callbacks = true
|
|
33
|
+
end
|
|
34
|
+
|
|
31
35
|
# Print deprecation notices to the stderr
|
|
32
36
|
config.active_support.deprecation = :stderr
|
|
37
|
+
|
|
38
|
+
config.active_support.test_order = :sorted
|
|
33
39
|
end
|
|
@@ -172,7 +172,7 @@ Devise.setup do |config|
|
|
|
172
172
|
# Email regex used to validate email formats. It simply asserts that
|
|
173
173
|
# an one (and only one) @ exists in the given string. This is mainly
|
|
174
174
|
# to give user feedback and not to assert the e-mail validity.
|
|
175
|
-
|
|
175
|
+
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/
|
|
176
176
|
|
|
177
177
|
# ==> Configuration for :timeoutable
|
|
178
178
|
# The time you want to timeout the user session without activity. After this
|
|
@@ -29,7 +29,7 @@ class CreateTables < ActiveRecord::Migration
|
|
|
29
29
|
t.string :invited_by_type
|
|
30
30
|
t.integer :invitations_count, :default => 0
|
|
31
31
|
|
|
32
|
-
t.timestamps
|
|
32
|
+
t.timestamps :null => false
|
|
33
33
|
end
|
|
34
34
|
add_index :users, :invitation_token, :unique => true
|
|
35
35
|
add_index :users, :invitations_count
|
data/test/test_helper.rb
CHANGED
|
@@ -4,9 +4,8 @@ DEVISE_ORM = (ENV["DEVISE_ORM"] || :active_record).to_sym
|
|
|
4
4
|
$:.unshift File.dirname(__FILE__)
|
|
5
5
|
puts "\n==> Devise.orm = #{DEVISE_ORM.inspect}"
|
|
6
6
|
require "rails_app/config/environment"
|
|
7
|
-
include Devise::TestHelpers
|
|
8
|
-
require "orm/#{DEVISE_ORM}"
|
|
9
7
|
require 'rails/test_help'
|
|
8
|
+
require "orm/#{DEVISE_ORM}"
|
|
10
9
|
require 'capybara/rails'
|
|
11
10
|
require 'mocha/setup'
|
|
12
11
|
|
|
@@ -15,10 +14,21 @@ ActionMailer::Base.perform_deliveries = true
|
|
|
15
14
|
ActionMailer::Base.default_url_options[:host] = 'test.com'
|
|
16
15
|
|
|
17
16
|
ActiveSupport::Deprecation.silenced = true
|
|
17
|
+
$VERBOSE = false
|
|
18
18
|
|
|
19
19
|
class ActionDispatch::IntegrationTest
|
|
20
20
|
include Capybara::DSL
|
|
21
21
|
end
|
|
22
|
-
class ActionController::TestCase
|
|
23
|
-
|
|
22
|
+
class ActionController::TestCase
|
|
23
|
+
if defined? Devise::Test
|
|
24
|
+
include Devise::Test::ControllerHelpers
|
|
25
|
+
else
|
|
26
|
+
include Devise::TestHelpers
|
|
27
|
+
end
|
|
28
|
+
if Rails.version >= '5.0.0'
|
|
29
|
+
self.use_transactional_tests = true
|
|
30
|
+
else
|
|
31
|
+
require 'test_after_commit' rescue nil
|
|
32
|
+
self.use_transactional_fixtures = true
|
|
33
|
+
end
|
|
24
34
|
end
|