devise_invitable 1.5.3 → 1.6.0

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.
@@ -23,8 +23,8 @@ class InvitationMailTest < ActionMailer::TestCase
23
23
  assert_not_nil mail
24
24
  end
25
25
 
26
- test 'content type should be set to html' do
27
- assert_equal 'text/html; charset=UTF-8', mail.content_type
26
+ test 'content type should be set to multipart' do
27
+ assert_match /^multipart\/alternative; boundary="[^"]+"; charset=UTF-8/, mail.content_type
28
28
  end
29
29
 
30
30
  test 'send invitation to the user email' do
@@ -48,22 +48,62 @@ class InvitationMailTest < ActionMailer::TestCase
48
48
  end
49
49
 
50
50
  test 'body should have user info' do
51
- assert_match /#{user.email}/, mail.body.decoded
51
+ assert_match /#{user.email}/, mail.html_part.body.decoded
52
+ assert_match /#{user.email}/, mail.text_part.body.decoded
52
53
  end
53
54
 
54
55
  test 'body should have link to confirm the account' do
55
56
  host = ActionMailer::Base.default_url_options[:host]
56
- body = mail.body.decoded
57
+ body = mail.html_part.body.decoded
57
58
  invitation_url_regexp = %r{<a href=\"http://#{host}/users/invitation/accept\?invitation_token=#{Thread.current[:token]}">}
58
59
  assert_match invitation_url_regexp, body
60
+
61
+ body = mail.text_part.body.decoded
62
+ invitation_url_regexp = %r{http://#{host}/users/invitation/accept\?invitation_token=#{Thread.current[:token]}}
63
+ assert_match invitation_url_regexp, body
59
64
  end
60
65
 
61
66
  test 'body should have link to confirm the account on resend' do
62
67
  host = ActionMailer::Base.default_url_options[:host]
63
68
  user
64
69
  @user = User.find(user.id).invite!
65
- body = mail.body.decoded
70
+ body = mail.html_part.body.decoded
66
71
  invitation_url_regexp = %r{<a href=\"http://#{host}/users/invitation/accept\?invitation_token=#{Thread.current[:token]}">}
67
72
  assert_match invitation_url_regexp, body
73
+
74
+ body = mail.text_part.body.decoded
75
+ invitation_url_regexp = %r{http://#{host}/users/invitation/accept\?invitation_token=#{Thread.current[:token]}}
76
+ assert_match invitation_url_regexp, body
77
+ end
78
+
79
+ test 'body should have invitation due date when it exists' do
80
+ User.stubs(:invite_for => 5)
81
+
82
+ host = ActionMailer::Base.default_url_options[:host]
83
+ user
84
+ body = mail.html_part.body.decoded
85
+ due_date_regexp = %r{#{I18n.l user.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format' }}
86
+ assert_match due_date_regexp, body
87
+
88
+ body = mail.text_part.body.decoded
89
+ due_date_regexp = %r{#{I18n.l user.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format' }}
90
+ assert_match due_date_regexp, body
91
+ end
92
+
93
+ test 'options are passed to the delivery method' do
94
+ class CustomMailer < Devise::Mailer
95
+ class << self
96
+ def invitation_instructions(record, name, options = {})
97
+ fail 'Options not as expected' unless options[:invited_at].is_a?(Time)
98
+ new(record, name, options)
99
+ end
100
+ end
101
+
102
+ def initialize(*args); end
103
+ def deliver; end
104
+ end
105
+ Devise.mailer = CustomMailer
106
+
107
+ User.invite!({ email: 'valid@email.com' }, nil, { invited_at: Time.now })
68
108
  end
69
109
  end
@@ -1,5 +1,6 @@
1
1
  class ActiveSupport::TestCase
2
2
  def setup_mailer
3
+ Devise.mailer = Devise::Mailer
3
4
  ActionMailer::Base.deliveries = []
4
5
  end
5
6
 
@@ -29,9 +29,9 @@ class InvitableTest < ActiveSupport::TestCase
29
29
  user = new_user
30
30
  user.invite!
31
31
 
32
- assert_not_nil user.invitation_token
33
- assert_not_nil user.raw_invitation_token
34
- assert_not_nil user.invitation_created_at
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
- assert_not_nil user.raw_invitation_token
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
- assert_not_nil user.invitation_token
53
- assert_not_nil user.invitation_created_at
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
- assert_not_nil user.invitation_token
64
- assert_not_nil user.raw_invitation_token
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
- assert_not_equal old_invitation_sent_at, user.invitation_sent_at
92
- assert_not_equal old_invitation_created_at, user.invitation_created_at
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,27 +99,51 @@ class InvitableTest < ActiveSupport::TestCase
99
99
 
100
100
  User.stubs(:invite_for).returns(nil)
101
101
  user.invitation_created_at = Time.now.utc
102
- assert user.valid_invitation?
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
- assert user.valid_invitation?
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
- assert user.valid_invitation?
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
- assert user.valid_invitation?
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
- assert user.valid_invitation?
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
- assert !user.valid_invitation?
122
+ refute_predicate user, :valid_invitation?
123
+ end
124
+
125
+ test 'should return token validity when there is invite_for' do
126
+ User.stubs(:invite_for).returns(1.day)
127
+
128
+ user = User.invite!(:email => "valid@email.com")
129
+ sent_at = user.invitation_created_at || user.invitation_sent_at
130
+ valid_until = sent_at + User.invite_for
131
+
132
+ assert_equal user.invitation_due_at, valid_until
133
+ end
134
+
135
+ test 'should return nil for invitation due date when invite_for is nil' do
136
+ User.stubs(:invite_for).returns(nil)
137
+ user = User.invite!(:email => "valid@email.com")
138
+
139
+ assert_equal user.invitation_due_at, nil
140
+ end
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
123
147
  end
124
148
 
125
149
  test 'should never generate the same invitation token for different users' do
@@ -128,7 +152,7 @@ class InvitableTest < ActiveSupport::TestCase
128
152
  user = new_user
129
153
  user.invite!
130
154
  token = user.invitation_token
131
- assert !invitation_tokens.include?(token)
155
+ refute_includes invitation_tokens, token
132
156
  invitation_tokens << token
133
157
  end
134
158
  end
@@ -136,36 +160,49 @@ class InvitableTest < ActiveSupport::TestCase
136
160
  test 'should invite with multiple columns for invite key' do
137
161
  User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/)
138
162
  user = User.invite!(:email => "valid@email.com", :username => "name")
139
- assert user.persisted?
140
- assert user.errors.empty?
163
+ assert_predicate user, :persisted?
164
+ assert_empty user.errors
141
165
  end
142
166
 
143
167
  test 'should allow non-string columns for invite key' do
144
168
  User.stubs(:invite_key).returns(:email => Devise.email_regexp, :profile_id => :present?.to_proc, :active => true)
145
169
  user = User.invite!(:email => "valid@email.com", :profile_id => 1, :active => true)
146
- assert user.persisted?
147
- assert user.errors.empty?
170
+ assert_predicate user, :persisted?
171
+ assert_empty user.errors
148
172
  end
149
173
 
150
174
  test 'should not invite with some missing columns when invite key is an array' do
151
175
  User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/, :profile_id => :present?.to_proc, :active => true)
152
176
  user = User.invite!(:email => "valid@email.com")
153
- assert user.new_record?
154
- assert user.errors.present?
177
+ assert_predicate user, :new_record?
178
+ refute_empty user.errors
155
179
  assert user.errors[:username]
156
180
  assert user.errors[:profile_id]
157
181
  assert user.errors[:active]
158
- assert user.errors[:email].empty?
182
+ assert_empty user.errors[:email]
159
183
  end
160
184
 
161
185
  test 'should return mail object' do
162
186
  mail = User.invite_mail!(:email => 'valid@email.com')
163
- assert mail.class.name == 'Mail::Message'
187
+ assert_instance_of Mail::Message, mail
164
188
  end
165
189
 
166
190
  test 'should disallow login when invited' do
167
191
  invited_user = User.invite!(:email => "valid@email.com")
168
- assert !invited_user.valid_password?('1234')
192
+ refute invited_user.valid_password?('1234')
193
+ end
194
+
195
+ test 'should not accept invite without password' do
196
+ user = User.invite!(:email => "valid@email.com")
197
+ user = User.accept_invitation!(:invitation_token => Thread.current[:token])
198
+ refute_predicate user, :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 = User.invite!(:email => "valid@email.com")
204
+ user = User.accept_invitation!(:invitation_token => Thread.current[:token])
205
+ assert_predicate user, :invitation_accepted?
169
206
  end
170
207
 
171
208
  test 'should set password and password confirmation from params' do
@@ -178,7 +215,7 @@ class InvitableTest < ActiveSupport::TestCase
178
215
  user = User.invite!(:email => "valid@email.com")
179
216
  old_encrypted_password = user.encrypted_password
180
217
  user = User.accept_invitation!(:invitation_token => Thread.current[:token], :password => '123456789', :password_confirmation => '123456789')
181
- assert_not_equal old_encrypted_password, user.encrypted_password
218
+ refute_equal old_encrypted_password, user.encrypted_password
182
219
  end
183
220
 
184
221
  test 'should not override password on invite!' do
@@ -220,7 +257,7 @@ class InvitableTest < ActiveSupport::TestCase
220
257
  User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
221
258
  assert_nil user.reload.reset_password_token
222
259
  assert_nil user.reload.invitation_token
223
- assert !user.invited_to_sign_up?
260
+ refute_predicate user, :invited_to_sign_up?
224
261
  end
225
262
 
226
263
  test 'should not accept invitation on failing to reset the password' do
@@ -240,7 +277,7 @@ class InvitableTest < ActiveSupport::TestCase
240
277
 
241
278
  test 'should not set invitation_accepted_at if just resetting password' do
242
279
  user = User.create!(:email => "valid@email.com", :password => "123456780")
243
- assert !user.invited_to_sign_up?
280
+ refute_predicate user, :invited_to_sign_up?
244
281
  token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
245
282
  user.reset_password_sent_at = Time.now.utc
246
283
  user.save
@@ -257,30 +294,30 @@ class InvitableTest < ActiveSupport::TestCase
257
294
  assert_difference('ActionMailer::Base.deliveries.size') do
258
295
  token = user.invitation_token
259
296
  user.invite!
260
- assert_not_equal token, user.invitation_token
297
+ refute_equal token, user.invitation_token
261
298
  end
262
299
  end
263
300
 
264
301
  test 'should return a record with invitation token and no errors to send invitation by email' do
265
302
  invited_user = User.invite!(:email => "valid@email.com")
266
- assert invited_user.errors.blank?
267
- assert invited_user.invitation_token.present?
303
+ assert_empty invited_user.errors
304
+ assert_predicate invited_user.invitation_token, :present?
268
305
  assert_equal 'valid@email.com', invited_user.email
269
- assert invited_user.persisted?
306
+ assert_predicate invited_user, :persisted?
270
307
  end
271
308
 
272
309
  test 'should set all attributes with no errors' do
273
310
  invited_user = User.invite!(:email => "valid@email.com", :username => 'first name')
274
- assert invited_user.errors.blank?
311
+ assert_empty invited_user.errors
275
312
  assert_equal 'first name', invited_user.username
276
- assert invited_user.persisted?
313
+ assert_predicate invited_user, :persisted?
277
314
  end
278
315
 
279
316
  test 'should not validate other attributes when validate_on_invite is disabled' do
280
317
  validate_on_invite = User.validate_on_invite
281
318
  User.validate_on_invite = false
282
319
  invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
283
- assert invited_user.errors.empty?
320
+ assert_empty invited_user.errors
284
321
  User.validate_on_invite = validate_on_invite
285
322
  end
286
323
 
@@ -288,7 +325,7 @@ class InvitableTest < ActiveSupport::TestCase
288
325
  validate_on_invite = User.validate_on_invite
289
326
  User.validate_on_invite = true
290
327
  invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
291
- assert invited_user.errors[:username].present?
328
+ refute_empty invited_user.errors[:username]
292
329
  User.validate_on_invite = validate_on_invite
293
330
  end
294
331
 
@@ -296,8 +333,8 @@ class InvitableTest < ActiveSupport::TestCase
296
333
  validate_on_invite = User.validate_on_invite
297
334
  User.validate_on_invite = true
298
335
  invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
299
- assert invited_user.errors.present?
300
- assert invited_user.errors[:password].empty?
336
+ refute_empty invited_user.errors
337
+ assert_empty invited_user.errors[:password]
301
338
  User.validate_on_invite = validate_on_invite
302
339
  end
303
340
 
@@ -305,8 +342,8 @@ class InvitableTest < ActiveSupport::TestCase
305
342
  validate_on_invite = User.validate_on_invite
306
343
  User.validate_on_invite = true
307
344
  invited_user = User.invite!(:email => "", :username => "a"*50)
308
- assert invited_user.errors[:email].present?
309
- assert invited_user.errors[:username].present?
345
+ refute_empty invited_user.errors[:email]
346
+ refute_empty invited_user.errors[:username]
310
347
  User.validate_on_invite = validate_on_invite
311
348
  end
312
349
 
@@ -347,7 +384,7 @@ class InvitableTest < ActiveSupport::TestCase
347
384
  user = User.invite!(:email => "valid@email.com", :username => "a"*50)
348
385
  assert_equal user, existing_user
349
386
  assert_equal ['has already been taken'], user.errors[:email]
350
- assert user.errors[:username].present?
387
+ refute_empty user.errors[:username]
351
388
  ensure
352
389
  User.validate_on_invite = validate_on_invite
353
390
  end
@@ -369,7 +406,7 @@ class InvitableTest < ActiveSupport::TestCase
369
406
  invited_user = User.invite!(:email => "invalid_email.com", :username => 'first name')
370
407
  assert invited_user.new_record?
371
408
  assert_equal 'first name', invited_user.username
372
- assert invited_user.errors.present?
409
+ refute_empty invited_user.errors
373
410
  end
374
411
 
375
412
  test 'should find a user to set his password based on invitation_token' do
@@ -433,10 +470,10 @@ class InvitableTest < ActiveSupport::TestCase
433
470
  :password_confirmation => 'new_password',
434
471
  :username => 'a'*50
435
472
  )
436
- assert invited_user.errors[:username].present?
473
+ refute_empty invited_user.errors[:username]
437
474
 
438
475
  user.reload
439
- assert !user.valid_password?('new_password')
476
+ refute user.valid_password?('new_password')
440
477
  end
441
478
 
442
479
  test 'should check if created by invitation' do
@@ -476,7 +513,7 @@ class InvitableTest < ActiveSupport::TestCase
476
513
 
477
514
  user.invite!
478
515
 
479
- assert !user.confirmed?
516
+ refute_predicate user, :confirmed?
480
517
  end
481
518
 
482
519
  test 'user.has_invitations_left? test' do
@@ -492,7 +529,7 @@ class InvitableTest < ActiveSupport::TestCase
492
529
  # With an individual invitation_limit of 0, a user shouldn't be able to send an invitation
493
530
  user.invitation_limit = 0
494
531
  assert user.save
495
- assert !user.has_invitations_left?
532
+ refute_predicate user, :has_invitations_left?
496
533
 
497
534
  # With in invitation_limit of 2, a user should be able to send two invitations
498
535
  user.invitation_limit = 2
@@ -520,7 +557,7 @@ class InvitableTest < ActiveSupport::TestCase
520
557
  assert_no_difference('ActionMailer::Base.deliveries.size') do
521
558
  user.invite!
522
559
  end
523
- assert user.invitation_created_at.present?
560
+ assert_predicate user, :invitation_created_at
524
561
  assert_nil user.invitation_sent_at
525
562
  end
526
563
 
@@ -531,7 +568,7 @@ class InvitableTest < ActiveSupport::TestCase
531
568
  u.skip_invitation = true
532
569
  end
533
570
  end
534
- assert user.invitation_created_at.present?
571
+ assert_predicate user, :invitation_created_at
535
572
  assert_nil user.invitation_sent_at
536
573
  end
537
574
 
@@ -552,17 +589,17 @@ class InvitableTest < ActiveSupport::TestCase
552
589
 
553
590
  test 'user.accept_invitation! should trigger callbacks' do
554
591
  user = User.invite!(:email => "valid@email.com")
555
- assert_callbacks_not_fired user
592
+ assert_callbacks_not_fired :after_invitation_accepted, user
556
593
  user.accept_invitation!
557
- assert_callbacks_fired user
594
+ assert_callbacks_fired :after_invitation_accepted, user
558
595
  end
559
596
 
560
597
  test 'user.accept_invitation! should not trigger callbacks if validation fails' do
561
598
  user = User.invite!(:email => "valid@email.com")
562
- assert_callbacks_not_fired user
599
+ assert_callbacks_not_fired :after_invitation_accepted, user
563
600
  user.username='a'*50
564
601
  user.accept_invitation!
565
- assert_callbacks_not_fired user
602
+ assert_callbacks_not_fired :after_invitation_accepted, user
566
603
  end
567
604
 
568
605
  test 'user.accept_invitation! should confirm user if confirmable' do
@@ -577,19 +614,19 @@ class InvitableTest < ActiveSupport::TestCase
577
614
  user.username='a'*50
578
615
  user.accept_invitation!
579
616
 
580
- assert !user.confirmed?
617
+ refute_predicate user, :confirmed?
581
618
  end
582
619
 
583
- def assert_callbacks_fired(user)
584
- assert_callbacks_status user, true
620
+ def assert_callbacks_fired(callback, user)
621
+ assert_callbacks_status callback, user, true
585
622
  end
586
623
 
587
- def assert_callbacks_not_fired(user)
588
- assert_callbacks_status user, nil
624
+ def assert_callbacks_not_fired(callback, user)
625
+ assert_callbacks_status callback, user, nil
589
626
  end
590
627
 
591
- def assert_callbacks_status(user, fired)
592
- assert_equal fired, user.callback_works
628
+ def assert_callbacks_status(callback, user, fired)
629
+ assert_equal fired, user.send("#{callback}_callback_works".to_sym)
593
630
  end
594
631
 
595
632
  test "user.invite! should downcase the class's case_insensitive_keys" do
@@ -605,6 +642,13 @@ class InvitableTest < ActiveSupport::TestCase
605
642
  assert user.active == true
606
643
  end
607
644
 
645
+ test "user.invite! should trigger callbacks" do
646
+ user = User.new(email: "valid@email.com")
647
+ assert_callbacks_not_fired :after_invitation_created, user
648
+ user.invite!
649
+ assert_callbacks_fired :after_invitation_created, user
650
+ end
651
+
608
652
  test 'should pass validation before accept if field is required in post-invited instance' do
609
653
  user = User.invite!(:email => "valid@email.com")
610
654
  user.testing_accepted_or_not_invited = true
@@ -630,7 +674,7 @@ class InvitableTest < ActiveSupport::TestCase
630
674
  test 'should return instance with errors if invitation_token is nil' do
631
675
  User.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
632
676
  user = User.accept_invitation!
633
- assert !user.errors.empty?
677
+ refute_empty user.errors
634
678
  end
635
679
 
636
680
  test "should count invited, created_by_invite, accepted and not accepted invitations" do
@@ -657,4 +701,18 @@ class InvitableTest < ActiveSupport::TestCase
657
701
  retval = user.reset_password!('anewpassword', 'anewpassword')
658
702
  assert_equal true, retval
659
703
  end
704
+
705
+ test 'should set initial password with variety of characters' do
706
+ PASSWORD_FORMAT = /\A
707
+ (?=.*\d) # Must contain a digit
708
+ (?=.*[a-z]) # Must contain a lower case character
709
+ (?=.*[A-Z]) # Must contain an upper case character
710
+ (?=.*[[:^alnum:]]) # Must contain a symbol
711
+ /x
712
+ User.stubs(:invite_key).returns(:password => PASSWORD_FORMAT)
713
+ Devise.stubs(:friendly_token).returns('onlylowercaseletters')
714
+ user = User.invite!(:email => "valid@email.com")
715
+ assert user.persisted?
716
+ assert user.errors.empty?
717
+ end
660
718
  end
@@ -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 :callback_works, :bio, :token
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.callback_works = true
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}/railtie"
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
@@ -11,7 +11,8 @@ development:
11
11
  # Do not set this db to the same as development or production.
12
12
  test:
13
13
  adapter: sqlite3
14
- database: ":memory:"
14
+ #database: ":memory:"
15
+ database: db/test.sqlite3
15
16
  pool: 5
16
17
  timeout: 5000
17
18
 
@@ -30,4 +30,6 @@ RailsApp::Application.configure do
30
30
 
31
31
  # Print deprecation notices to the stderr
32
32
  config.active_support.deprecation = :stderr
33
+
34
+ config.active_support.test_order = :sorted
33
35
  end
@@ -3,6 +3,9 @@
3
3
 
4
4
  en:
5
5
  hello: "Hello world"
6
+ time:
7
+ formats:
8
+ short: "%b %d"
6
9
  devise:
7
10
  free_invitations:
8
11
  send_instructions: 'An invitation email has been sent to %{email}.'
@@ -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,11 @@ 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
- include Devise::TestHelpers
22
+ class ActionController::TestCase
23
+ include Devise::TestHelpers
24
24
  end