devise_invitable 1.7.5 → 2.0.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of devise_invitable might be problematic. Click here for more details.

Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.rdoc +98 -111
  4. data/app/controllers/devise/invitations_controller.rb +41 -40
  5. data/app/controllers/devise_invitable/registrations_controller.rb +11 -11
  6. data/app/views/devise/invitations/edit.html.erb +14 -8
  7. data/app/views/devise/invitations/new.html.erb +11 -7
  8. data/app/views/devise/mailer/invitation_instructions.html.erb +1 -1
  9. data/app/views/devise/mailer/invitation_instructions.text.erb +1 -1
  10. data/config/locales/ar.yml +23 -0
  11. data/config/locales/da.yml +41 -0
  12. data/config/locales/de.yml +31 -0
  13. data/config/locales/es.yml +31 -0
  14. data/config/locales/et.yml +23 -0
  15. data/config/locales/fa.yml +31 -0
  16. data/config/locales/fr.yml +34 -0
  17. data/config/locales/it.yml +31 -0
  18. data/config/locales/ja.yml +31 -0
  19. data/config/locales/ko.yml +24 -0
  20. data/config/locales/nl.yml +32 -0
  21. data/config/locales/no.yml +17 -0
  22. data/config/locales/pl.yml +31 -0
  23. data/config/locales/pt-BR.yml +23 -0
  24. data/config/locales/pt.yml +23 -0
  25. data/config/locales/ru.yml +23 -0
  26. data/config/locales/tr.yml +24 -0
  27. data/config/locales/ua.yml +31 -0
  28. data/config/locales/vi.yml +25 -0
  29. data/config/locales/zh-HK.yml +31 -0
  30. data/config/locales/zh-TW.yml +31 -0
  31. data/lib/devise_invitable.rb +5 -4
  32. data/lib/devise_invitable/controllers/helpers.rb +3 -4
  33. data/lib/devise_invitable/inviter.rb +4 -3
  34. data/lib/devise_invitable/mailer.rb +1 -1
  35. data/lib/devise_invitable/mapping.rb +6 -5
  36. data/lib/devise_invitable/models.rb +28 -28
  37. data/lib/devise_invitable/models/authenticatable.rb +7 -1
  38. data/lib/devise_invitable/parameter_sanitizer.rb +18 -18
  39. data/lib/devise_invitable/routes.rb +5 -5
  40. data/lib/devise_invitable/version.rb +1 -1
  41. data/lib/generators/active_record/devise_invitable_generator.rb +3 -3
  42. data/lib/generators/active_record/templates/migration.rb +0 -1
  43. data/lib/generators/devise_invitable/devise_invitable_generator.rb +4 -8
  44. data/lib/generators/devise_invitable/install_generator.rb +11 -14
  45. data/lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb +10 -6
  46. data/lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb +10 -6
  47. data/lib/generators/devise_invitable/views_generator.rb +6 -6
  48. data/test/functional/registrations_controller_test.rb +24 -25
  49. data/test/generators/views_generator_test.rb +7 -6
  50. data/test/generators_test.rb +3 -2
  51. data/test/integration/invitation_remove_test.rb +8 -8
  52. data/test/integration/invitation_test.rb +46 -46
  53. data/test/integration_tests_helper.rb +8 -9
  54. data/test/model_tests_helper.rb +5 -5
  55. data/test/models/invitable_test.rb +120 -110
  56. data/test/models_test.rb +3 -3
  57. data/test/orm/active_record.rb +2 -2
  58. data/test/orm/mongoid.rb +2 -2
  59. data/test/rails_app/app/controllers/admins_controller.rb +4 -3
  60. data/test/rails_app/app/controllers/application_controller.rb +11 -10
  61. data/test/rails_app/app/controllers/free_invitations_controller.rb +12 -9
  62. data/test/rails_app/app/controllers/users_controller.rb +2 -2
  63. data/test/rails_app/app/models/admin.rb +7 -10
  64. data/test/rails_app/app/models/octopussy.rb +4 -4
  65. data/test/rails_app/app/models/user.rb +20 -20
  66. data/test/rails_app/app/views/admins/new.html.erb +9 -5
  67. data/test/rails_app/app/views/devise/sessions/new.html.erb +14 -6
  68. data/test/rails_app/app/views/free_invitations/new.html.erb +9 -5
  69. data/test/rails_app/app/views/layouts/application.html.erb +3 -4
  70. data/test/rails_app/app/views/users/invitations/new.html.erb +15 -9
  71. data/test/rails_app/config/application.rb +6 -6
  72. data/test/rails_app/config/boot.rb +2 -2
  73. data/test/rails_app/config/credentials.yml.enc +1 -0
  74. data/test/rails_app/config/initializers/devise.rb +4 -3
  75. data/test/rails_app/config/initializers/secret_token.rb +3 -1
  76. data/test/rails_app/config/initializers/session_store.rb +1 -1
  77. data/test/rails_app/config/initializers/wrap_parameters.rb +1 -1
  78. data/test/rails_app/config/master.key +1 -0
  79. data/test/rails_app/config/routes.rb +3 -3
  80. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -2
  81. data/test/routes_test.rb +4 -4
  82. data/test/test_helper.rb +6 -19
  83. metadata +46 -22
@@ -21,13 +21,13 @@ class ActiveSupport::TestCase
21
21
  "test#{@@email_count}@email.com"
22
22
  end
23
23
 
24
- def valid_attributes(attributes={})
25
- { :email => generate_unique_email,
26
- :password => '123456',
27
- :password_confirmation => '123456' }.update(attributes)
24
+ def valid_attributes(attributes = {})
25
+ { email: generate_unique_email,
26
+ password: '123456',
27
+ password_confirmation: '123456' }.update(attributes)
28
28
  end
29
29
 
30
- def new_user(attributes={})
30
+ def new_user(attributes = {})
31
31
  User.new(valid_attributes(attributes))
32
32
  end
33
33
 
@@ -1,6 +1,10 @@
1
1
  require 'test_helper'
2
2
  require 'model_tests_helper'
3
3
 
4
+ class Validatable < User
5
+ devise :validatable, password_length: 10..20
6
+ end
7
+
4
8
  class InvitableTest < ActiveSupport::TestCase
5
9
 
6
10
  def setup
@@ -15,7 +19,7 @@ class InvitableTest < ActiveSupport::TestCase
15
19
  if defined?(ActiveRecord)
16
20
  current_user = new_user
17
21
  2.times do |index|
18
- User.invite!({:email => "valid#{index}@email.com"}, current_user)
22
+ User.invite!({ email: "valid#{index}@email.com" }, current_user)
19
23
  end
20
24
  assert_equal current_user.reload.invitations_count, 2
21
25
  end
@@ -74,7 +78,7 @@ class InvitableTest < ActiveSupport::TestCase
74
78
  test 'should return the correct raw_invitation_token ' do
75
79
  user = new_user
76
80
  raw, enc = Devise.token_generator.generate(user.class, :invitation_token)
77
- #stub the generator so the tokens are the same
81
+ # stub the generator so the tokens are the same
78
82
  Devise.token_generator.stubs(:generate).returns([raw, enc])
79
83
  user.invite!
80
84
  assert_equal user.raw_invitation_token, raw
@@ -85,17 +89,17 @@ class InvitableTest < ActiveSupport::TestCase
85
89
  user.invite!
86
90
  old_invitation_created_at = 3.days.ago
87
91
  old_invitation_sent_at = 3.days.ago
88
- user.update_attributes(:invitation_sent_at => old_invitation_sent_at, :invitation_created_at => old_invitation_created_at)
92
+ user.update_attributes(invitation_sent_at: old_invitation_sent_at, invitation_created_at: old_invitation_created_at)
89
93
  3.times do
90
94
  user.invite!
91
95
  refute_equal old_invitation_sent_at, user.invitation_sent_at
92
96
  refute_equal old_invitation_created_at, user.invitation_created_at
93
- user.update_attributes(:invitation_sent_at => old_invitation_sent_at, :invitation_created_at => old_invitation_created_at)
97
+ user.update_attributes(invitation_sent_at: old_invitation_sent_at, invitation_created_at: old_invitation_created_at)
94
98
  end
95
99
  end
96
100
 
97
101
  test 'should test invitation sent at with invite_for configuration value' do
98
- user = User.invite!(:email => "valid@email.com")
102
+ user = User.invite!(email: 'valid@email.com')
99
103
 
100
104
  User.stubs(:invite_for).returns(nil)
101
105
  user.invitation_created_at = Time.now.utc
@@ -125,7 +129,7 @@ class InvitableTest < ActiveSupport::TestCase
125
129
  test 'should return token validity when there is invite_for' do
126
130
  User.stubs(:invite_for).returns(1.day)
127
131
 
128
- user = User.invite!(:email => "valid@email.com")
132
+ user = User.invite!(email: 'valid@email.com')
129
133
  sent_at = user.invitation_created_at || user.invitation_sent_at
130
134
  valid_until = sent_at + User.invite_for
131
135
 
@@ -134,7 +138,7 @@ class InvitableTest < ActiveSupport::TestCase
134
138
 
135
139
  test 'should return nil for invitation due date when invite_for is nil' do
136
140
  User.stubs(:invite_for).returns(nil)
137
- user = User.invite!(:email => "valid@email.com")
141
+ user = User.invite!(email: 'valid@email.com')
138
142
 
139
143
  assert_nil user.invitation_due_at
140
144
  end
@@ -158,22 +162,22 @@ class InvitableTest < ActiveSupport::TestCase
158
162
  end
159
163
 
160
164
  test 'should invite with multiple columns for invite key' do
161
- User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/)
162
- user = User.invite!(:email => "valid@email.com", :username => "name")
165
+ User.stubs(:invite_key).returns(email: Devise.email_regexp, username: /\A.+\z/)
166
+ user = User.invite!(email: 'valid@email.com', username: "name")
163
167
  assert_predicate user, :persisted?
164
168
  assert_empty user.errors
165
169
  end
166
170
 
167
171
  test 'should allow non-string columns for invite key' do
168
- User.stubs(:invite_key).returns(:email => Devise.email_regexp, :profile_id => :present?.to_proc, :active => true)
169
- user = User.invite!(:email => "valid@email.com", :profile_id => 1, :active => true)
172
+ User.stubs(:invite_key).returns(email: Devise.email_regexp, profile_id: :present?.to_proc)
173
+ user = User.invite!(email: 'valid@email.com', profile_id: 1)
170
174
  assert_predicate user, :persisted?
171
175
  assert_empty user.errors
172
176
  end
173
177
 
174
178
  test 'should not invite with some missing columns when invite key is an array' do
175
- User.stubs(:invite_key).returns(:email => Devise.email_regexp, :username => /\A.+\z/, :profile_id => :present?.to_proc, :active => true)
176
- user = User.invite!(:email => "valid@email.com")
179
+ User.stubs(:invite_key).returns(email: Devise.email_regexp, username: /\A.+\z/, profile_id: :present?.to_proc, active: true)
180
+ user = User.invite!(email: 'valid@email.com')
177
181
  assert_predicate user, :new_record?
178
182
  refute_empty user.errors
179
183
  assert user.errors[:username]
@@ -183,48 +187,48 @@ class InvitableTest < ActiveSupport::TestCase
183
187
  end
184
188
 
185
189
  test 'should return mail object' do
186
- mail = User.invite_mail!(:email => 'valid@email.com')
190
+ mail = User.invite_mail!(email: 'valid@email.com')
187
191
  assert_instance_of Mail::Message, mail
188
192
  end
189
193
 
190
194
  test 'should disallow login when invited' do
191
- invited_user = User.invite!(:email => "valid@email.com")
195
+ invited_user = User.invite!(email: 'valid@email.com')
192
196
  refute invited_user.valid_password?('1234')
193
197
  end
194
198
 
195
199
  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?
200
+ User.invite!(email: 'valid@email.com')
201
+ User.accept_invitation!(invitation_token: Thread.current[:token])
202
+ refute_predicate User.where(email: 'valid@email.com').first, :invitation_accepted?
199
203
  end
200
204
 
201
205
  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?
206
+ Devise.stubs(require_password_on_accepting: false)
207
+ User.invite!(email: 'valid@email.com')
208
+ User.accept_invitation!(invitation_token: Thread.current[:token])
209
+ assert_predicate User.where(email: 'valid@email.com').first, :invitation_accepted?
206
210
  end
207
211
 
208
212
  test 'should set password and password confirmation from params' do
209
- User.invite!(:email => "valid@email.com")
210
- user = User.accept_invitation!(:invitation_token => Thread.current[:token], :password => '123456789', :password_confirmation => '123456789')
213
+ User.invite!(email: 'valid@email.com')
214
+ user = User.accept_invitation!(invitation_token: Thread.current[:token], password: '123456789', password_confirmation: '123456789')
211
215
  assert user.valid_password?('123456789')
212
216
  end
213
217
 
214
218
  test 'should set password and save the record' do
215
- user = User.invite!(:email => "valid@email.com")
219
+ user = User.invite!(email: 'valid@email.com')
216
220
  old_encrypted_password = user.encrypted_password
217
- user = User.accept_invitation!(:invitation_token => Thread.current[:token], :password => '123456789', :password_confirmation => '123456789')
221
+ user = User.accept_invitation!(invitation_token: Thread.current[:token], password: '123456789', password_confirmation: '123456789')
218
222
  refute_equal old_encrypted_password, user.encrypted_password
219
223
  end
220
224
 
221
225
  test 'should not override password on invite!' do
222
- user = User.invite!(:email => "valid@email.com", :password => 'password', :password_confirmation => 'password', :skip_invitation => true)
226
+ user = User.invite!(email: 'valid@email.com', password: 'password', password_confirmation: 'password', skip_invitation: true)
223
227
  assert user.valid?
224
228
  end
225
229
 
226
230
  test 'should clear invitation token and set invitation_accepted_at while accepting the password' do
227
- user = User.invite!(:email => "valid@email.com")
231
+ user = User.invite!(email: 'valid@email.com')
228
232
  assert user.invitation_token.present?
229
233
  assert_nil user.invitation_accepted_at
230
234
  user.accept_invitation!
@@ -238,11 +242,11 @@ class InvitableTest < ActiveSupport::TestCase
238
242
  end
239
243
 
240
244
  test 'should not clear invitation token or set accepted_at if record is invalid' do
241
- user = User.invite!(:email => "valid@email.com")
245
+ user = User.invite!(email: 'valid@email.com')
242
246
  assert user.invitation_token.present?
243
247
  assert_nil user.invitation_accepted_at
244
248
  old_encrypted_password = user.encrypted_password
245
- User.accept_invitation!(:invitation_token => user.invitation_token, :password => '123456789', :password_confirmation => '987654321')
249
+ User.accept_invitation!(invitation_token: user.invitation_token, password: '123456789', password_confirmation: '987654321')
246
250
  user.reload
247
251
  assert_equal old_encrypted_password, user.encrypted_password
248
252
  assert user.invitation_token.present?
@@ -250,10 +254,10 @@ class InvitableTest < ActiveSupport::TestCase
250
254
  end
251
255
 
252
256
  test 'should not require reloading if invalid' do
253
- user = User.invite!(:email => "valid@email.com")
257
+ user = User.invite!(email: 'valid@email.com')
254
258
  assert user.invitation_token.present?
255
259
  assert_nil user.invitation_accepted_at
256
- user.attributes = { :password => '123456789', :password_confirmation => '987654321' }
260
+ user.attributes = { password: '123456789', password_confirmation: '987654321' }
257
261
  user.accept_invitation!
258
262
  assert user.invitation_token.present?
259
263
  assert_nil user.invitation_accepted_at
@@ -261,7 +265,7 @@ class InvitableTest < ActiveSupport::TestCase
261
265
  end
262
266
 
263
267
  test 'should clear invitation token while resetting the password' do
264
- user = User.invite!(:email => "valid@email.com")
268
+ user = User.invite!(email: 'valid@email.com')
265
269
  assert user.invited_to_sign_up?
266
270
  token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
267
271
  user.reset_password_sent_at = Time.now.utc
@@ -269,14 +273,14 @@ class InvitableTest < ActiveSupport::TestCase
269
273
 
270
274
  assert user.reset_password_token.present?
271
275
  assert user.invitation_token.present?
272
- User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
276
+ User.reset_password_by_token(reset_password_token: token, password: '123456789', password_confirmation: '123456789')
273
277
  assert_nil user.reload.reset_password_token
274
278
  assert_nil user.reload.invitation_token
275
279
  refute_predicate user, :invited_to_sign_up?
276
280
  end
277
281
 
278
282
  test 'should not accept invitation on failing to reset the password' do
279
- user = User.invite!(:email => "valid@email.com")
283
+ user = User.invite!(email: 'valid@email.com')
280
284
  assert user.invited_to_sign_up?
281
285
  token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
282
286
  user.reset_password_sent_at = Time.now.utc
@@ -284,14 +288,14 @@ class InvitableTest < ActiveSupport::TestCase
284
288
 
285
289
  assert user.reset_password_token.present?
286
290
  assert user.invitation_token.present?
287
- User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '12345678')
291
+ User.reset_password_by_token(reset_password_token: token, password: '123456789', password_confirmation: '12345678')
288
292
  assert user.reload.reset_password_token.present?
289
293
  assert user.reload.invitation_token.present?
290
294
  assert user.invited_to_sign_up?
291
295
  end
292
296
 
293
297
  test 'should not set invitation_accepted_at if just resetting password' do
294
- user = User.create!(:email => "valid@email.com", :password => "123456780")
298
+ user = User.create!(email: 'valid@email.com', password: '123456780')
295
299
  refute_predicate user, :invited_to_sign_up?
296
300
  token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
297
301
  user.reset_password_sent_at = Time.now.utc
@@ -299,7 +303,7 @@ class InvitableTest < ActiveSupport::TestCase
299
303
 
300
304
  assert user.reset_password_token.present?
301
305
  assert_nil user.invitation_token
302
- User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
306
+ User.reset_password_by_token(reset_password_token: token, password: '123456789', password_confirmation: '123456789')
303
307
  assert_nil user.reload.invitation_token
304
308
  assert_nil user.reload.invitation_accepted_at
305
309
  end
@@ -314,7 +318,7 @@ class InvitableTest < ActiveSupport::TestCase
314
318
  end
315
319
 
316
320
  test 'should return a record with invitation token and no errors to send invitation by email' do
317
- invited_user = User.invite!(:email => "valid@email.com")
321
+ invited_user = User.invite!(email: 'valid@email.com')
318
322
  assert_empty invited_user.errors
319
323
  assert_predicate invited_user.invitation_token, :present?
320
324
  assert_equal 'valid@email.com', invited_user.email
@@ -322,7 +326,7 @@ class InvitableTest < ActiveSupport::TestCase
322
326
  end
323
327
 
324
328
  test 'should set all attributes with no errors' do
325
- invited_user = User.invite!(:email => "valid@email.com", :username => 'first name')
329
+ invited_user = User.invite!(email: 'valid@email.com', username: 'first name')
326
330
  assert_empty invited_user.errors
327
331
  assert_equal 'first name', invited_user.username
328
332
  assert_predicate invited_user, :persisted?
@@ -331,7 +335,7 @@ class InvitableTest < ActiveSupport::TestCase
331
335
  test 'should not validate other attributes when validate_on_invite is disabled' do
332
336
  validate_on_invite = User.validate_on_invite
333
337
  User.validate_on_invite = false
334
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
338
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50)
335
339
  assert_empty invited_user.errors
336
340
  User.validate_on_invite = validate_on_invite
337
341
  end
@@ -339,7 +343,7 @@ class InvitableTest < ActiveSupport::TestCase
339
343
  test 'should validate other attributes when validate_on_invite is enabled' do
340
344
  validate_on_invite = User.validate_on_invite
341
345
  User.validate_on_invite = true
342
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
346
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50)
343
347
  refute_empty invited_user.errors[:username]
344
348
  User.validate_on_invite = validate_on_invite
345
349
  end
@@ -347,7 +351,7 @@ class InvitableTest < ActiveSupport::TestCase
347
351
  test 'should not validate password when validate_on_invite is enabled' do
348
352
  validate_on_invite = User.validate_on_invite
349
353
  User.validate_on_invite = true
350
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
354
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50)
351
355
  refute_empty invited_user.errors
352
356
  assert_empty invited_user.errors[:password]
353
357
  User.validate_on_invite = validate_on_invite
@@ -356,33 +360,33 @@ class InvitableTest < ActiveSupport::TestCase
356
360
  test 'should validate other attributes when validate_on_invite is enabled and email is not present' do
357
361
  validate_on_invite = User.validate_on_invite
358
362
  User.validate_on_invite = true
359
- invited_user = User.invite!(:email => "", :username => "a"*50)
363
+ invited_user = User.invite!(email: '', username: 'a' * 50)
360
364
  refute_empty invited_user.errors[:email]
361
365
  refute_empty invited_user.errors[:username]
362
366
  User.validate_on_invite = validate_on_invite
363
367
  end
364
368
 
365
369
  test 'should return a record with errors if user was found by e-mail' do
366
- existing_user = User.new(:email => "valid@email.com")
367
- existing_user.save(:validate => false)
368
- user = User.invite!(:email => "valid@email.com")
370
+ existing_user = User.new(email: 'valid@email.com')
371
+ existing_user.save(validate: false)
372
+ user = User.invite!(email: 'valid@email.com')
369
373
  assert_equal user, existing_user
370
374
  assert_equal ['has already been taken'], user.errors[:email]
371
- same_user = User.invite!("email" => "valid@email.com")
375
+ same_user = User.invite!(email: 'valid@email.com')
372
376
  assert_equal same_user, existing_user
373
377
  assert_equal ['has already been taken'], same_user.errors[:email]
374
378
  end
375
379
 
376
380
  test 'should return a record with errors if user with pending invitation was found by e-mail' do
377
- existing_user = User.invite!(:email => "valid@email.com")
378
- user = User.invite!(:email => "valid@email.com")
381
+ existing_user = User.invite!(email: 'valid@email.com')
382
+ user = User.invite!(email: 'valid@email.com')
379
383
  assert_equal user, existing_user
380
384
  assert_equal [], user.errors[:email]
381
385
  resend_invitation = User.resend_invitation
382
386
  begin
383
387
  User.resend_invitation = false
384
388
 
385
- user = User.invite!(:email => "valid@email.com")
389
+ user = User.invite!(email: 'valid@email.com')
386
390
  assert_equal user, existing_user
387
391
  assert_equal ['has already been taken'], user.errors[:email]
388
392
  ensure
@@ -394,9 +398,9 @@ class InvitableTest < ActiveSupport::TestCase
394
398
  begin
395
399
  validate_on_invite = User.validate_on_invite
396
400
  User.validate_on_invite = true
397
- existing_user = User.new(:email => "valid@email.com")
398
- existing_user.save(:validate => false)
399
- user = User.invite!(:email => "valid@email.com", :username => "a"*50)
401
+ existing_user = User.new(email: 'valid@email.com')
402
+ existing_user.save(validate: false)
403
+ user = User.invite!(email: 'valid@email.com', username: 'a' * 50)
400
404
  assert_equal user, existing_user
401
405
  assert_equal ['has already been taken'], user.errors[:email]
402
406
  refute_empty user.errors[:username]
@@ -406,19 +410,19 @@ class InvitableTest < ActiveSupport::TestCase
406
410
  end
407
411
 
408
412
  test 'should return a new record with errors if e-mail is blank' do
409
- invited_user = User.invite!(:email => '')
413
+ invited_user = User.invite!(email: '')
410
414
  assert invited_user.new_record?
411
415
  assert_equal ["can't be blank"], invited_user.errors[:email]
412
416
  end
413
417
 
414
418
  test 'should return a new record with errors if e-mail is invalid' do
415
- invited_user = User.invite!(:email => 'invalid_email')
419
+ invited_user = User.invite!(email: 'invalid_email')
416
420
  assert invited_user.new_record?
417
- assert_equal ["is invalid"], invited_user.errors[:email]
421
+ assert_equal ['is invalid'], invited_user.errors[:email]
418
422
  end
419
423
 
420
424
  test 'should set all attributes with errors if e-mail is invalid' do
421
- invited_user = User.invite!(:email => "invalid_email.com", :username => 'first name')
425
+ invited_user = User.invite!(email: 'invalid_email.com', username: 'first name')
422
426
  assert invited_user.new_record?
423
427
  assert_equal 'first name', invited_user.username
424
428
  refute_empty invited_user.errors
@@ -427,34 +431,34 @@ class InvitableTest < ActiveSupport::TestCase
427
431
  test 'should find a user to set his password based on invitation_token' do
428
432
  user = new_user
429
433
  user.invite!
430
- invited_user = User.accept_invitation!(:invitation_token => Thread.current[:token])
434
+ invited_user = User.accept_invitation!(invitation_token: Thread.current[:token])
431
435
  assert_equal invited_user, user
432
436
  end
433
437
 
434
438
  test 'should return a new record with errors if no invitation_token is found' do
435
- invited_user = User.accept_invitation!(:invitation_token => 'invalid_token')
439
+ invited_user = User.accept_invitation!(invitation_token: 'invalid_token')
436
440
  assert invited_user.new_record?
437
441
  assert_equal ['is invalid'], invited_user.errors[:invitation_token]
438
442
  end
439
443
 
440
444
  test 'should return a new record with errors if invitation_token is blank' do
441
- invited_user = User.accept_invitation!(:invitation_token => '')
445
+ invited_user = User.accept_invitation!(invitation_token: '')
442
446
  assert invited_user.new_record?
443
447
  assert_equal ["can't be blank"], invited_user.errors[:invitation_token]
444
448
  end
445
449
 
446
450
  test 'should return record with errors if invitation_token has expired' do
447
451
  User.stubs(:invite_for).returns(10.hours)
448
- invited_user = User.invite!(:email => "valid@email.com")
452
+ invited_user = User.invite!(email: 'valid@email.com')
449
453
  invited_user.invitation_created_at = 2.days.ago
450
- invited_user.save(:validate => false)
451
- user = User.accept_invitation!(:invitation_token => Thread.current[:token])
454
+ invited_user.save(validate: false)
455
+ user = User.accept_invitation!(invitation_token: Thread.current[:token])
452
456
  assert_equal user, invited_user
453
- assert_equal ["is invalid"], user.errors[:invitation_token]
457
+ assert_equal ['is invalid'], user.errors[:invitation_token]
454
458
  end
455
459
 
456
460
  test 'should allow record modification using block' do
457
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50) do |u|
461
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50) do |u|
458
462
  u.password = '123123'
459
463
  u.password_confirmation = '123123'
460
464
  end
@@ -462,13 +466,13 @@ class InvitableTest < ActiveSupport::TestCase
462
466
  end
463
467
 
464
468
  test 'should set successfully user password given the new password and confirmation' do
465
- user = new_user(:password => nil, :password_confirmation => nil)
469
+ user = new_user(password: nil, password_confirmation: nil)
466
470
  user.invite!
467
471
 
468
472
  User.accept_invitation!(
469
- :invitation_token => Thread.current[:token],
470
- :password => 'new_password',
471
- :password_confirmation => 'new_password'
473
+ invitation_token: Thread.current[:token],
474
+ password: 'new_password',
475
+ password_confirmation: 'new_password',
472
476
  )
473
477
  user.reload
474
478
 
@@ -476,14 +480,14 @@ class InvitableTest < ActiveSupport::TestCase
476
480
  end
477
481
 
478
482
  test 'should return errors on other attributes even when password is valid' do
479
- user = new_user(:password => nil, :password_confirmation => nil)
483
+ user = new_user(password: nil, password_confirmation: nil)
480
484
  user.invite!
481
485
 
482
486
  invited_user = User.accept_invitation!(
483
- :invitation_token => Thread.current[:token],
484
- :password => 'new_password',
485
- :password_confirmation => 'new_password',
486
- :username => 'a'*50
487
+ invitation_token: Thread.current[:token],
488
+ password: 'new_password',
489
+ password_confirmation: 'new_password',
490
+ username: 'a' * 50,
487
491
  )
488
492
  refute_empty invited_user.errors[:username]
489
493
 
@@ -492,14 +496,14 @@ class InvitableTest < ActiveSupport::TestCase
492
496
  end
493
497
 
494
498
  test 'should check if created by invitation' do
495
- user = User.invite!(:email => "valid@email.com")
499
+ user = User.invite!(email: 'valid@email.com')
496
500
  assert user.created_by_invite?
497
501
 
498
502
  invited_user = User.accept_invitation!(
499
- :invitation_token => Thread.current[:token],
500
- :password => 'new_password',
501
- :password_confirmation => 'new_password',
502
- :username => 'a'
503
+ invitation_token: Thread.current[:token],
504
+ password: 'new_password',
505
+ password_confirmation: 'new_password',
506
+ username: 'a',
503
507
  )
504
508
  user.reload
505
509
  assert user.created_by_invite?
@@ -507,14 +511,14 @@ class InvitableTest < ActiveSupport::TestCase
507
511
 
508
512
 
509
513
  test 'should set other attributes on accepting invitation' do
510
- user = new_user(:password => nil, :password_confirmation => nil)
514
+ user = new_user(password: nil, password_confirmation: nil)
511
515
  user.invite!
512
516
 
513
517
  invited_user = User.accept_invitation!(
514
- :invitation_token => Thread.current[:token],
515
- :password => 'new_password',
516
- :password_confirmation => 'new_password',
517
- :username => 'a'
518
+ invitation_token: Thread.current[:token],
519
+ password: 'new_password',
520
+ password_confirmation: 'new_password',
521
+ username: 'a',
518
522
  )
519
523
  assert invited_user.errors[:username].blank?
520
524
 
@@ -554,13 +558,13 @@ class InvitableTest < ActiveSupport::TestCase
554
558
 
555
559
  test 'should not send an invitation if we want to skip the invitation' do
556
560
  assert_no_difference('ActionMailer::Base.deliveries.size') do
557
- User.invite!(:email => "valid@email.com", :username => "a"*50, :skip_invitation => true)
561
+ User.invite!(email: 'valid@email.com', username: 'a' * 50, skip_invitation: true)
558
562
  end
559
563
  end
560
564
 
561
565
  test 'should not send an invitation if we want to skip the invitation with block' do
562
566
  assert_no_difference('ActionMailer::Base.deliveries.size') do
563
- User.invite!(:email => "valid@email.com", :username => "a"*50) do |u|
567
+ User.invite!(email: 'valid@email.com', username: 'a' * 50) do |u|
564
568
  u.skip_invitation = true
565
569
  end
566
570
  end
@@ -595,22 +599,22 @@ class InvitableTest < ActiveSupport::TestCase
595
599
 
596
600
  test 'user.invite! should set the invited_by attribute if passed' do
597
601
  user = new_user
598
- inviting_user = User.new(:email => "valid@email.com")
599
- inviting_user.save(:validate => false)
602
+ inviting_user = User.new(email: 'valid@email.com')
603
+ inviting_user.save(validate: false)
600
604
  user.invite!(inviting_user)
601
605
  assert_equal inviting_user, user.invited_by
602
606
  assert_equal inviting_user.class.to_s, user.invited_by_type
603
607
  end
604
608
 
605
609
  test 'user.accept_invitation! should trigger callbacks' do
606
- user = User.invite!(:email => "valid@email.com")
610
+ user = User.invite!(email: 'valid@email.com')
607
611
  assert_callbacks_not_fired :after_invitation_accepted, user
608
612
  user.accept_invitation!
609
613
  assert_callbacks_fired :after_invitation_accepted, user
610
614
  end
611
615
 
612
616
  test 'user.accept_invitation! should not trigger callbacks if validation fails' do
613
- user = User.invite!(:email => "valid@email.com")
617
+ user = User.invite!(email: 'valid@email.com')
614
618
  assert_callbacks_not_fired :after_invitation_accepted, user
615
619
  user.username='a'*50
616
620
  user.accept_invitation!
@@ -618,7 +622,7 @@ class InvitableTest < ActiveSupport::TestCase
618
622
  end
619
623
 
620
624
  test 'user.accept_invitation! should confirm user if confirmable' do
621
- user = User.invite!(:email => "valid@email.com")
625
+ user = User.invite!(email: 'valid@email.com')
622
626
  user.accept_invitation!
623
627
 
624
628
  assert user.confirmed?
@@ -626,7 +630,7 @@ class InvitableTest < ActiveSupport::TestCase
626
630
  end
627
631
 
628
632
  test 'user.accept_invitation! should not confirm user if validation fails' do
629
- user = User.invite!(:email => "valid@email.com")
633
+ user = User.invite!(email: 'valid@email.com')
630
634
  user.username='a'*50
631
635
  user.accept_invitation!
632
636
  user.reload
@@ -640,7 +644,7 @@ class InvitableTest < ActiveSupport::TestCase
640
644
  begin
641
645
  User.send_password_change_notification = true
642
646
 
643
- user = User.invite!(:email => "valid@email.com")
647
+ user = User.invite!(email: 'valid@email.com')
644
648
 
645
649
  assert_no_difference('ActionMailer::Base.deliveries.size') do
646
650
  user.password = user.password_confirmation = '123456789'
@@ -671,53 +675,53 @@ class InvitableTest < ActiveSupport::TestCase
671
675
 
672
676
  test "user.invite! should downcase the class's case_insensitive_keys" do
673
677
  # Devise default is :email
674
- user = User.invite!(:email => "UPPERCASE@email.com")
675
- assert user.email == "uppercase@email.com"
678
+ user = User.invite!(email: 'UPPERCASE@email.com')
679
+ assert user.email == 'uppercase@email.com'
676
680
  end
677
681
 
678
682
  test "user.invite! should strip whitespace from the class's strip_whitespace_keys" do
679
683
  # Devise default is email
680
- user = User.invite!(:email => " valid@email.com ", :active => true)
681
- assert user.email == "valid@email.com"
684
+ user = User.invite!(email: ' valid@email.com ', active: true)
685
+ assert user.email == 'valid@email.com'
682
686
  assert user.active == true
683
687
  end
684
688
 
685
689
  test "user.invite! should trigger callbacks" do
686
- user = User.new(email: "valid@email.com")
690
+ user = User.new(email: 'valid@email.com')
687
691
  assert_callbacks_not_fired :after_invitation_created, user
688
692
  user.invite!
689
693
  assert_callbacks_fired :after_invitation_created, user
690
694
  end
691
695
 
692
696
  test 'should pass validation before accept if field is required in post-invited instance' do
693
- user = User.invite!(:email => "valid@email.com")
697
+ user = User.invite!(email: 'valid@email.com')
694
698
  user.testing_accepted_or_not_invited = true
695
699
  user.valid?
696
700
  assert_empty user.errors
697
701
  end
698
702
 
699
703
  test 'should fail validation after accept if field is required in post-invited instance' do
700
- user = User.invite!(:email => "valid@email.com")
704
+ user = User.invite!(email: 'valid@email.com')
701
705
  user.testing_accepted_or_not_invited = true
702
706
  assert_predicate user, :accept_invitation!
703
- user = User.where(:email => "valid@email.com").first
707
+ user = User.where(email: 'valid@email.com').first
704
708
  user.valid?
705
709
  refute_empty user.errors
706
710
  end
707
711
 
708
712
  test 'should pass validation after accept if field is required in post-invited instance' do
709
- user = User.invite!(:email => "valid@email.com")
713
+ user = User.invite!(email: 'valid@email.com')
710
714
  user.username = 'test'
711
715
  user.testing_accepted_or_not_invited = true
712
716
  assert_predicate user, :accept_invitation!
713
- user = User.where(:email => "valid@email.com").first
717
+ user = User.where(email: 'valid@email.com').first
714
718
  user.bio = "Test"
715
719
  user.valid?
716
720
  assert_empty user.errors
717
721
  end
718
722
 
719
723
  test 'should return instance with errors if invitation_token is nil' do
720
- User.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
724
+ User.create(email: 'admin@test.com', password: '123456', password_confirmation: '123456')
721
725
  user = User.accept_invitation!
722
726
  refute_empty user.errors
723
727
  end
@@ -727,9 +731,9 @@ class InvitableTest < ActiveSupport::TestCase
727
731
  assert_equal 0, User.invitation_accepted.count
728
732
  assert_equal 0, User.created_by_invite.count
729
733
 
730
- User.invite!(:email => "invalid@email.com")
731
- User.invite!(:email => "another_invalid@email.com")
732
- user = User.invite!(:email => "valid@email.com")
734
+ User.invite!(email: 'invalid@email.com')
735
+ User.invite!(email: 'another_invalid@email.com')
736
+ user = User.invite!(email: 'valid@email.com')
733
737
 
734
738
  assert_equal 3, User.invitation_not_accepted.count
735
739
  assert_equal 0, User.invitation_accepted.count
@@ -754,10 +758,16 @@ class InvitableTest < ActiveSupport::TestCase
754
758
  (?=.*[A-Z]) # Must contain an upper case character
755
759
  (?=.*[[:^alnum:]]) # Must contain a symbol
756
760
  /x
757
- User.stubs(:invite_key).returns(:password => PASSWORD_FORMAT)
761
+ User.stubs(:invite_key).returns(password: PASSWORD_FORMAT)
758
762
  Devise.stubs(:friendly_token).returns('onlylowercaseletters')
759
- user = User.invite!(:email => "valid@email.com")
763
+ user = User.invite!(email: 'valid@email.com')
760
764
  assert user.persisted?
761
765
  assert user.errors.empty?
762
766
  end
767
+
768
+ test 'should set initial password following devise password_length' do
769
+ user = Validatable.invite!(email: 'valid@email.com')
770
+ user.update_attributes(profile_id: 1)
771
+ assert_empty user.errors
772
+ end
763
773
  end