devise_invitable 1.7.5 → 2.0.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.

Potentially problematic release.


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

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.rdoc +75 -82
  4. data/app/controllers/devise/invitations_controller.rb +10 -10
  5. data/app/controllers/devise_invitable/registrations_controller.rb +1 -1
  6. data/app/views/devise/invitations/edit.html.erb +14 -8
  7. data/app/views/devise/invitations/new.html.erb +11 -7
  8. data/lib/devise_invitable.rb +3 -3
  9. data/lib/devise_invitable/controllers/helpers.rb +1 -1
  10. data/lib/devise_invitable/mailer.rb +1 -1
  11. data/lib/devise_invitable/mapping.rb +1 -1
  12. data/lib/devise_invitable/models.rb +17 -17
  13. data/lib/devise_invitable/routes.rb +4 -4
  14. data/lib/devise_invitable/version.rb +1 -1
  15. data/lib/generators/active_record/devise_invitable_generator.rb +3 -3
  16. data/lib/generators/devise_invitable/devise_invitable_generator.rb +4 -8
  17. data/lib/generators/devise_invitable/install_generator.rb +7 -11
  18. data/lib/generators/devise_invitable/templates/simple_form_for/invitations/edit.html.erb +10 -6
  19. data/lib/generators/devise_invitable/templates/simple_form_for/invitations/new.html.erb +10 -6
  20. data/lib/generators/devise_invitable/views_generator.rb +6 -6
  21. data/test/functional/registrations_controller_test.rb +24 -25
  22. data/test/integration/invitation_remove_test.rb +8 -8
  23. data/test/integration/invitation_test.rb +46 -46
  24. data/test/integration_tests_helper.rb +8 -8
  25. data/test/model_tests_helper.rb +5 -5
  26. data/test/models/invitable_test.rb +110 -110
  27. data/test/models_test.rb +3 -3
  28. data/test/orm/active_record.rb +2 -2
  29. data/test/orm/mongoid.rb +2 -2
  30. data/test/rails_app/app/controllers/admins_controller.rb +1 -1
  31. data/test/rails_app/app/controllers/application_controller.rb +1 -1
  32. data/test/rails_app/app/controllers/users_controller.rb +2 -2
  33. data/test/rails_app/app/models/admin.rb +7 -10
  34. data/test/rails_app/app/models/octopussy.rb +4 -4
  35. data/test/rails_app/app/models/user.rb +20 -20
  36. data/test/rails_app/app/views/admins/new.html.erb +9 -5
  37. data/test/rails_app/app/views/devise/sessions/new.html.erb +14 -6
  38. data/test/rails_app/app/views/free_invitations/new.html.erb +9 -5
  39. data/test/rails_app/app/views/layouts/application.html.erb +3 -4
  40. data/test/rails_app/app/views/users/invitations/new.html.erb +15 -9
  41. data/test/rails_app/config/application.rb +6 -6
  42. data/test/rails_app/config/boot.rb +2 -2
  43. data/test/rails_app/config/credentials.yml.enc +1 -0
  44. data/test/rails_app/config/initializers/session_store.rb +1 -1
  45. data/test/rails_app/config/initializers/wrap_parameters.rb +1 -1
  46. data/test/rails_app/config/master.key +1 -0
  47. data/test/rails_app/config/routes.rb +3 -3
  48. data/test/routes_test.rb +4 -4
  49. data/test/test_helper.rb +2 -2
  50. metadata +22 -20
  51. data/test/rails_app/config/initializers/secret_token.rb +0 -7
@@ -4,26 +4,26 @@ require 'integration_tests_helper'
4
4
  class InvitationRemoveTest < ActionDispatch::IntegrationTest
5
5
 
6
6
  test 'invited user can choose to remove his account/invite' do
7
- User.invite!(:email => "valid@email.com")
7
+ User.invite!(email: 'valid@email.com')
8
8
 
9
9
  # remove!
10
- visit remove_user_invitation_path(:invitation_token => Thread.current[:token])
10
+ visit remove_user_invitation_path(invitation_token: Thread.current[:token])
11
11
  assert_equal root_path, current_path
12
- assert page.has_css?('p#notice', :text => 'Your invitation was removed.')
12
+ assert page.has_css?('p#notice', text: 'Your invitation was removed.')
13
13
 
14
14
  # try to remove again!
15
- visit remove_user_invitation_path(:invitation_token => Thread.current[:token])
15
+ visit remove_user_invitation_path(invitation_token: Thread.current[:token])
16
16
  assert_equal root_path, current_path
17
- assert page.has_css?('p#alert', :text => 'The invitation token provided is not valid!')
17
+ assert page.has_css?('p#alert', text: 'The invitation token provided is not valid!')
18
18
  end
19
19
 
20
20
  test 'accepted user cannot remove his account (by using the original invitation token)' do
21
- user = User.invite!(:email => "valid@email.com")
21
+ user = User.invite!(email: 'valid@email.com')
22
22
  saved_token = Thread.current[:token]
23
23
  user.accept_invitation!
24
24
 
25
- visit remove_user_invitation_path(:invitation_token => saved_token)
25
+ visit remove_user_invitation_path(invitation_token: saved_token)
26
26
  assert_equal root_path, current_path
27
- assert page.has_css?('p#alert', :text => 'The invitation token provided is not valid!')
27
+ assert page.has_css?('p#alert', text: 'The invitation token provided is not valid!')
28
28
  end
29
29
  end
@@ -9,18 +9,18 @@ class InvitationTest < ActionDispatch::IntegrationTest
9
9
  def send_invitation(url = new_user_invitation_path, &block)
10
10
  visit url
11
11
 
12
- fill_in 'user_email', :with => 'user@test.com'
12
+ fill_in 'user_email', with: 'user@test.com'
13
13
  yield if block_given?
14
14
  click_button 'Send an invitation'
15
15
  end
16
16
 
17
- def set_password(options={}, &block)
17
+ def set_password(options = {}, &block)
18
18
  unless options[:visit] == false
19
- visit accept_user_invitation_path(:invitation_token => options[:invitation_token])
19
+ visit accept_user_invitation_path(invitation_token: options[:invitation_token])
20
20
  end
21
21
 
22
- fill_in 'user_password', :with => '987654321'
23
- fill_in 'user_password_confirmation', :with => '987654321'
22
+ fill_in 'user_password', with: '987654321'
23
+ fill_in 'user_password_confirmation', with: '987654321'
24
24
  yield if block_given?
25
25
  click_button options[:button] || 'Set my password'
26
26
  end
@@ -28,7 +28,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
28
28
  test 'not authenticated user should be able to send a free invitation' do
29
29
  send_invitation new_free_invitation_path
30
30
  assert_equal root_path, current_path
31
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
31
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
32
32
  end
33
33
 
34
34
  test 'not authenticated user should not be able to send an invitation' do
@@ -41,19 +41,19 @@ class InvitationTest < ActionDispatch::IntegrationTest
41
41
 
42
42
  send_invitation
43
43
  assert_equal root_path, current_path
44
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
44
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
45
45
  end
46
46
 
47
47
  test 'authenticated user with existing email should receive an error message' do
48
48
  user = create_full_user
49
49
  sign_in_as_user(user)
50
50
  send_invitation do
51
- fill_in 'user_email', :with => user.email
51
+ fill_in 'user_email', with: user.email
52
52
  end
53
53
 
54
54
  assert_equal user_invitation_path, current_path
55
55
  assert page.has_css?("input[type=text][value='#{user.email}']")
56
- assert page.has_css?('#error_explanation li', :text => 'Email has already been taken')
56
+ assert page.has_css?('#error_explanation li', text: 'Email has already been taken')
57
57
  end
58
58
 
59
59
  test 'authenticated user should not be able to visit edit invitation page' do
@@ -65,63 +65,63 @@ class InvitationTest < ActionDispatch::IntegrationTest
65
65
  end
66
66
 
67
67
  test 'invited user without password should not be able to sign in' do
68
- user = User.invite!(:email => "valid@email.com")
68
+ user = User.invite!(email: 'valid@email.com')
69
69
  user.password = 'test'
70
70
  sign_in_as_user user
71
71
 
72
72
  assert_equal new_user_session_path, current_path
73
- assert page.has_css?('p#alert', :text => 'You have a pending invitation, accept it to finish creating your account.')
73
+ assert page.has_css?('p#alert', text: 'You have a pending invitation, accept it to finish creating your account.')
74
74
  end
75
75
 
76
76
  test 'invited user with password should not be able to sign in' do
77
- user = User.invite!(:email => "valid@email.com")
77
+ user = User.invite!(email: 'valid@email.com')
78
78
  user.password = '987654321'
79
79
  user.save
80
80
  sign_in_as_user user
81
81
 
82
82
  assert_equal new_user_session_path, current_path
83
- assert page.has_css?('p#alert', :text => 'You have a pending invitation, accept it to finish creating your account.')
83
+ assert page.has_css?('p#alert', text: 'You have a pending invitation, accept it to finish creating your account.')
84
84
  end
85
85
 
86
86
  test 'not authenticated user with invalid invitation token should not be able to set his password' do
87
- user = User.invite!(:email => "valid@email.com")
87
+ user = User.invite!(email: 'valid@email.com')
88
88
  user.accept_invitation!
89
- visit accept_user_invitation_path(:invitation_token => 'invalid_token')
89
+ visit accept_user_invitation_path(invitation_token: 'invalid_token')
90
90
 
91
91
  assert_equal root_path, current_path
92
- assert page.has_css?('p#alert', :text => 'The invitation token provided is not valid!')
92
+ assert page.has_css?('p#alert', text: 'The invitation token provided is not valid!')
93
93
  end
94
94
 
95
95
  test 'not authenticated user with valid invitation token but invalid password should not be able to set his password' do
96
- user = User.invite!(:email => "valid@email.com")
97
- set_password :invitation_token => Thread.current[:token] do
98
- fill_in 'Password confirmation', :with => 'other_password'
96
+ user = User.invite!(email: 'valid@email.com')
97
+ set_password invitation_token: Thread.current[:token] do
98
+ fill_in 'Password confirmation', with: 'other_password'
99
99
  end
100
100
  assert_equal user_invitation_path, current_path
101
- assert page.has_css?('#error_explanation li', :text => /Password .*doesn\'t match/)
101
+ assert page.has_css?('#error_explanation li', text: /Password .*doesn\'t match/)
102
102
  assert !user.confirmed?
103
103
  end
104
104
 
105
105
  test 'not authenticated user with valid data should be able to change his password' do
106
- user = User.invite!(:email => "valid@email.com")
107
- set_password :invitation_token => Thread.current[:token]
106
+ user = User.invite!(email: 'valid@email.com')
107
+ set_password invitation_token: Thread.current[:token]
108
108
 
109
109
  assert_equal root_path, current_path
110
- assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
110
+ assert page.has_css?('p#notice', text: 'Your password was set successfully. You are now signed in.')
111
111
  assert user.reload.valid_password?('987654321')
112
112
  assert user.confirmed?
113
113
  end
114
114
 
115
115
  test 'after entering invalid data user should still be able to set his password' do
116
- user = User.invite!(:email => "valid@email.com")
117
- set_password :invitation_token => Thread.current[:token] do
118
- fill_in 'Password confirmation', :with => 'other_password'
116
+ user = User.invite!(email: 'valid@email.com')
117
+ set_password invitation_token: Thread.current[:token] do
118
+ fill_in 'Password confirmation', with: 'other_password'
119
119
  end
120
120
  assert_equal user_invitation_path, current_path
121
121
  assert page.has_css?('#error_explanation')
122
122
 
123
- set_password :visit => false
124
- assert page.has_css?('p#notice', :text => 'Your password was set successfully. You are now signed in.')
123
+ set_password visit: false
124
+ assert page.has_css?('p#notice', text: 'Your password was set successfully. You are now signed in.')
125
125
  assert user.reload.valid_password?('987654321')
126
126
  end
127
127
 
@@ -129,8 +129,8 @@ class InvitationTest < ActionDispatch::IntegrationTest
129
129
  original_option_value = Devise.allow_insecure_sign_in_after_accept
130
130
  Devise.allow_insecure_sign_in_after_accept = true
131
131
 
132
- User.invite!(:email => "valid@email.com")
133
- set_password :invitation_token => Thread.current[:token]
132
+ User.invite!(email: 'valid@email.com')
133
+ set_password invitation_token: Thread.current[:token]
134
134
 
135
135
  assert_equal root_path, current_path
136
136
  Devise.allow_insecure_sign_in_after_accept = original_option_value
@@ -140,22 +140,22 @@ class InvitationTest < ActionDispatch::IntegrationTest
140
140
  original_option_value = Devise.allow_insecure_sign_in_after_accept
141
141
  Devise.allow_insecure_sign_in_after_accept = false
142
142
 
143
- User.invite!(:email => "valid@email.com")
144
- set_password :invitation_token => Thread.current[:token]
143
+ User.invite!(email: 'valid@email.com')
144
+ set_password invitation_token: Thread.current[:token]
145
145
 
146
146
  assert_equal new_user_session_path, current_path
147
147
  Devise.allow_insecure_sign_in_after_accept = original_option_value
148
148
  end
149
149
 
150
150
  test 'clear token and set invitation_accepted_at after recover password instead of accept_invitation' do
151
- user = User.invite!(:email => "valid@email.com")
151
+ user = User.invite!(email: 'valid@email.com')
152
152
 
153
153
  visit new_user_password_path
154
- fill_in 'user_email', :with => 'valid@email.com'
154
+ fill_in 'user_email', with: 'valid@email.com'
155
155
  click_button 'Send me reset password instructions'
156
156
 
157
- visit edit_user_password_path(:reset_password_token => Thread.current[:token])
158
- set_password :visit => false, :button => 'Change my password'
157
+ visit edit_user_password_path(reset_password_token: Thread.current[:token])
158
+ set_password visit: false, button: 'Change my password'
159
159
 
160
160
  user.reload
161
161
  assert_nil user.invitation_token
@@ -174,7 +174,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
174
174
  send_invitation
175
175
  end
176
176
  assert_equal root_path, current_path
177
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
177
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
178
178
  user = User.find(user.id)
179
179
  assert !user.has_invitations_left?
180
180
  end
@@ -191,7 +191,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
191
191
  send_invitation
192
192
  end
193
193
  assert_equal user_invitation_path, current_path
194
- assert page.has_css?('p#alert', :text => 'No invitations remaining')
194
+ assert page.has_css?('p#alert', text: 'No invitations remaining')
195
195
  end
196
196
 
197
197
  test 'user with nil invitation_limit should default to User.invitation_limit' do
@@ -204,7 +204,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
204
204
 
205
205
  send_invitation
206
206
  assert_equal root_path, current_path
207
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
207
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
208
208
  user = User.find(user.id)
209
209
  assert_equal 2, user.invitation_limit
210
210
  end
@@ -219,13 +219,13 @@ class InvitationTest < ActionDispatch::IntegrationTest
219
219
 
220
220
  send_invitation
221
221
  assert_equal root_path, current_path
222
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
222
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
223
223
  user = User.find(user.id)
224
224
  assert_equal 2, user.invitation_limit
225
225
 
226
226
  send_invitation
227
227
  assert_equal root_path, current_path
228
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
228
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
229
229
  user = User.find(user.id)
230
230
  assert_equal 2, user.invitation_limit
231
231
  end
@@ -235,7 +235,7 @@ class InvitationTest < ActionDispatch::IntegrationTest
235
235
  sign_in_as_user(user)
236
236
  send_invitation
237
237
 
238
- invited_user = User.where(:email => 'user@test.com').first
238
+ invited_user = User.where(email: 'user@test.com').first
239
239
  assert invited_user
240
240
  assert_equal user, invited_user.invited_by
241
241
  end
@@ -248,20 +248,20 @@ class InvitationTest < ActionDispatch::IntegrationTest
248
248
  end
249
249
 
250
250
  test 'authenticated admin should be able to send an admin invitation' do
251
- admin = Admin.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
251
+ admin = Admin.create(email: 'admin@test.com', password: '123456', password_confirmation: '123456')
252
252
  sign_in_as_user admin
253
253
 
254
254
  send_invitation new_admin_path
255
255
  assert_equal root_path, current_path
256
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
256
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
257
257
  end
258
258
 
259
259
  test 'authenticated admin should be redirected to own page after send a free invitation' do
260
- admin = Admin.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
260
+ admin = Admin.create(email: 'admin@test.com', password: '123456', password_confirmation: '123456')
261
261
  sign_in_as_user admin
262
262
 
263
263
  send_invitation new_free_invitation_path
264
264
  assert_equal root_path, current_path
265
- assert page.has_css?('p#notice', :text => 'An invitation email has been sent to user@test.com.')
265
+ assert page.has_css?('p#notice', text: 'An invitation email has been sent to user@test.com.')
266
266
  end
267
267
  end
@@ -7,11 +7,11 @@ class ActionDispatch::IntegrationTest
7
7
  def create_full_user
8
8
  @user ||= begin
9
9
  user = User.create!(
10
- :username => 'usertest',
11
- :email => 'fulluser@test.com',
12
- :password => '123456',
13
- :password_confirmation => '123456',
14
- :created_at => Time.now.utc
10
+ username: 'usertest',
11
+ email: 'fulluser@test.com',
12
+ password: '123456',
13
+ password_confirmation: '123456',
14
+ created_at: Time.now.utc,
15
15
  )
16
16
  user.confirm
17
17
  user
@@ -22,8 +22,8 @@ class ActionDispatch::IntegrationTest
22
22
  user ||= create_full_user
23
23
  resource_name = user.class.name.underscore
24
24
  visit send("new_#{resource_name}_session_path")
25
- fill_in "#{resource_name}_email", :with => user.email
26
- fill_in "#{resource_name}_password", :with => user.password
25
+ fill_in "#{resource_name}_email", with: user.email
26
+ fill_in "#{resource_name}_password", with: user.password
27
27
  click_button 'Log in'
28
28
  end
29
29
 
@@ -35,7 +35,7 @@ class ActionDispatch::IntegrationTest
35
35
  "Expected status to be 301 or 302, got #{@integration_session.status}"
36
36
 
37
37
  url = prepend_host(url)
38
- location = prepend_host(@integration_session.headers["Location"])
38
+ location = prepend_host(@integration_session.headers['Location'])
39
39
  assert_equal url, location
40
40
  end
41
41
 
@@ -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
 
@@ -15,7 +15,7 @@ class InvitableTest < ActiveSupport::TestCase
15
15
  if defined?(ActiveRecord)
16
16
  current_user = new_user
17
17
  2.times do |index|
18
- User.invite!({:email => "valid#{index}@email.com"}, current_user)
18
+ User.invite!({ email: "valid#{index}@email.com" }, current_user)
19
19
  end
20
20
  assert_equal current_user.reload.invitations_count, 2
21
21
  end
@@ -74,7 +74,7 @@ class InvitableTest < ActiveSupport::TestCase
74
74
  test 'should return the correct raw_invitation_token ' do
75
75
  user = new_user
76
76
  raw, enc = Devise.token_generator.generate(user.class, :invitation_token)
77
- #stub the generator so the tokens are the same
77
+ # stub the generator so the tokens are the same
78
78
  Devise.token_generator.stubs(:generate).returns([raw, enc])
79
79
  user.invite!
80
80
  assert_equal user.raw_invitation_token, raw
@@ -85,17 +85,17 @@ class InvitableTest < ActiveSupport::TestCase
85
85
  user.invite!
86
86
  old_invitation_created_at = 3.days.ago
87
87
  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)
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
91
  refute_equal old_invitation_sent_at, user.invitation_sent_at
92
92
  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)
93
+ user.update_attributes(invitation_sent_at: old_invitation_sent_at, invitation_created_at: old_invitation_created_at)
94
94
  end
95
95
  end
96
96
 
97
97
  test 'should test invitation sent at with invite_for configuration value' do
98
- user = User.invite!(:email => "valid@email.com")
98
+ user = User.invite!(email: 'valid@email.com')
99
99
 
100
100
  User.stubs(:invite_for).returns(nil)
101
101
  user.invitation_created_at = Time.now.utc
@@ -125,7 +125,7 @@ class InvitableTest < ActiveSupport::TestCase
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
+ user = User.invite!(email: 'valid@email.com')
129
129
  sent_at = user.invitation_created_at || user.invitation_sent_at
130
130
  valid_until = sent_at + User.invite_for
131
131
 
@@ -134,7 +134,7 @@ class InvitableTest < ActiveSupport::TestCase
134
134
 
135
135
  test 'should return nil for invitation due date when invite_for is nil' do
136
136
  User.stubs(:invite_for).returns(nil)
137
- user = User.invite!(:email => "valid@email.com")
137
+ user = User.invite!(email: 'valid@email.com')
138
138
 
139
139
  assert_nil user.invitation_due_at
140
140
  end
@@ -158,22 +158,22 @@ class InvitableTest < ActiveSupport::TestCase
158
158
  end
159
159
 
160
160
  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")
161
+ User.stubs(:invite_key).returns(email: Devise.email_regexp, username: /\A.+\z/)
162
+ user = User.invite!(email: 'valid@email.com', username: "name")
163
163
  assert_predicate user, :persisted?
164
164
  assert_empty user.errors
165
165
  end
166
166
 
167
167
  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)
168
+ User.stubs(:invite_key).returns(email: Devise.email_regexp, profile_id: :present?.to_proc)
169
+ user = User.invite!(email: 'valid@email.com', profile_id: 1)
170
170
  assert_predicate user, :persisted?
171
171
  assert_empty user.errors
172
172
  end
173
173
 
174
174
  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")
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')
177
177
  assert_predicate user, :new_record?
178
178
  refute_empty user.errors
179
179
  assert user.errors[:username]
@@ -183,48 +183,48 @@ class InvitableTest < ActiveSupport::TestCase
183
183
  end
184
184
 
185
185
  test 'should return mail object' do
186
- mail = User.invite_mail!(:email => 'valid@email.com')
186
+ mail = User.invite_mail!(email: 'valid@email.com')
187
187
  assert_instance_of Mail::Message, mail
188
188
  end
189
189
 
190
190
  test 'should disallow login when invited' do
191
- invited_user = User.invite!(:email => "valid@email.com")
191
+ invited_user = User.invite!(email: 'valid@email.com')
192
192
  refute invited_user.valid_password?('1234')
193
193
  end
194
194
 
195
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?
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
199
  end
200
200
 
201
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?
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
206
  end
207
207
 
208
208
  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')
209
+ User.invite!(email: 'valid@email.com')
210
+ user = User.accept_invitation!(invitation_token: Thread.current[:token], password: '123456789', password_confirmation: '123456789')
211
211
  assert user.valid_password?('123456789')
212
212
  end
213
213
 
214
214
  test 'should set password and save the record' do
215
- user = User.invite!(:email => "valid@email.com")
215
+ user = User.invite!(email: 'valid@email.com')
216
216
  old_encrypted_password = user.encrypted_password
217
- user = User.accept_invitation!(:invitation_token => Thread.current[:token], :password => '123456789', :password_confirmation => '123456789')
217
+ user = User.accept_invitation!(invitation_token: Thread.current[:token], password: '123456789', password_confirmation: '123456789')
218
218
  refute_equal old_encrypted_password, user.encrypted_password
219
219
  end
220
220
 
221
221
  test 'should not override password on invite!' do
222
- user = User.invite!(:email => "valid@email.com", :password => 'password', :password_confirmation => 'password', :skip_invitation => true)
222
+ user = User.invite!(email: 'valid@email.com', password: 'password', password_confirmation: 'password', skip_invitation: true)
223
223
  assert user.valid?
224
224
  end
225
225
 
226
226
  test 'should clear invitation token and set invitation_accepted_at while accepting the password' do
227
- user = User.invite!(:email => "valid@email.com")
227
+ user = User.invite!(email: 'valid@email.com')
228
228
  assert user.invitation_token.present?
229
229
  assert_nil user.invitation_accepted_at
230
230
  user.accept_invitation!
@@ -238,11 +238,11 @@ class InvitableTest < ActiveSupport::TestCase
238
238
  end
239
239
 
240
240
  test 'should not clear invitation token or set accepted_at if record is invalid' do
241
- user = User.invite!(:email => "valid@email.com")
241
+ user = User.invite!(email: 'valid@email.com')
242
242
  assert user.invitation_token.present?
243
243
  assert_nil user.invitation_accepted_at
244
244
  old_encrypted_password = user.encrypted_password
245
- User.accept_invitation!(:invitation_token => user.invitation_token, :password => '123456789', :password_confirmation => '987654321')
245
+ User.accept_invitation!(invitation_token: user.invitation_token, password: '123456789', password_confirmation: '987654321')
246
246
  user.reload
247
247
  assert_equal old_encrypted_password, user.encrypted_password
248
248
  assert user.invitation_token.present?
@@ -250,10 +250,10 @@ class InvitableTest < ActiveSupport::TestCase
250
250
  end
251
251
 
252
252
  test 'should not require reloading if invalid' do
253
- user = User.invite!(:email => "valid@email.com")
253
+ user = User.invite!(email: 'valid@email.com')
254
254
  assert user.invitation_token.present?
255
255
  assert_nil user.invitation_accepted_at
256
- user.attributes = { :password => '123456789', :password_confirmation => '987654321' }
256
+ user.attributes = { password: '123456789', password_confirmation: '987654321' }
257
257
  user.accept_invitation!
258
258
  assert user.invitation_token.present?
259
259
  assert_nil user.invitation_accepted_at
@@ -261,7 +261,7 @@ class InvitableTest < ActiveSupport::TestCase
261
261
  end
262
262
 
263
263
  test 'should clear invitation token while resetting the password' do
264
- user = User.invite!(:email => "valid@email.com")
264
+ user = User.invite!(email: 'valid@email.com')
265
265
  assert user.invited_to_sign_up?
266
266
  token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
267
267
  user.reset_password_sent_at = Time.now.utc
@@ -269,14 +269,14 @@ class InvitableTest < ActiveSupport::TestCase
269
269
 
270
270
  assert user.reset_password_token.present?
271
271
  assert user.invitation_token.present?
272
- User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
272
+ User.reset_password_by_token(reset_password_token: token, password: '123456789', password_confirmation: '123456789')
273
273
  assert_nil user.reload.reset_password_token
274
274
  assert_nil user.reload.invitation_token
275
275
  refute_predicate user, :invited_to_sign_up?
276
276
  end
277
277
 
278
278
  test 'should not accept invitation on failing to reset the password' do
279
- user = User.invite!(:email => "valid@email.com")
279
+ user = User.invite!(email: 'valid@email.com')
280
280
  assert user.invited_to_sign_up?
281
281
  token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
282
282
  user.reset_password_sent_at = Time.now.utc
@@ -284,14 +284,14 @@ class InvitableTest < ActiveSupport::TestCase
284
284
 
285
285
  assert user.reset_password_token.present?
286
286
  assert user.invitation_token.present?
287
- User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '12345678')
287
+ User.reset_password_by_token(reset_password_token: token, password: '123456789', password_confirmation: '12345678')
288
288
  assert user.reload.reset_password_token.present?
289
289
  assert user.reload.invitation_token.present?
290
290
  assert user.invited_to_sign_up?
291
291
  end
292
292
 
293
293
  test 'should not set invitation_accepted_at if just resetting password' do
294
- user = User.create!(:email => "valid@email.com", :password => "123456780")
294
+ user = User.create!(email: 'valid@email.com', password: '123456780')
295
295
  refute_predicate user, :invited_to_sign_up?
296
296
  token, user.reset_password_token = Devise.token_generator.generate(User, :reset_password_token)
297
297
  user.reset_password_sent_at = Time.now.utc
@@ -299,7 +299,7 @@ class InvitableTest < ActiveSupport::TestCase
299
299
 
300
300
  assert user.reset_password_token.present?
301
301
  assert_nil user.invitation_token
302
- User.reset_password_by_token(:reset_password_token => token, :password => '123456789', :password_confirmation => '123456789')
302
+ User.reset_password_by_token(reset_password_token: token, password: '123456789', password_confirmation: '123456789')
303
303
  assert_nil user.reload.invitation_token
304
304
  assert_nil user.reload.invitation_accepted_at
305
305
  end
@@ -314,7 +314,7 @@ class InvitableTest < ActiveSupport::TestCase
314
314
  end
315
315
 
316
316
  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")
317
+ invited_user = User.invite!(email: 'valid@email.com')
318
318
  assert_empty invited_user.errors
319
319
  assert_predicate invited_user.invitation_token, :present?
320
320
  assert_equal 'valid@email.com', invited_user.email
@@ -322,7 +322,7 @@ class InvitableTest < ActiveSupport::TestCase
322
322
  end
323
323
 
324
324
  test 'should set all attributes with no errors' do
325
- invited_user = User.invite!(:email => "valid@email.com", :username => 'first name')
325
+ invited_user = User.invite!(email: 'valid@email.com', username: 'first name')
326
326
  assert_empty invited_user.errors
327
327
  assert_equal 'first name', invited_user.username
328
328
  assert_predicate invited_user, :persisted?
@@ -331,7 +331,7 @@ class InvitableTest < ActiveSupport::TestCase
331
331
  test 'should not validate other attributes when validate_on_invite is disabled' do
332
332
  validate_on_invite = User.validate_on_invite
333
333
  User.validate_on_invite = false
334
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
334
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50)
335
335
  assert_empty invited_user.errors
336
336
  User.validate_on_invite = validate_on_invite
337
337
  end
@@ -339,7 +339,7 @@ class InvitableTest < ActiveSupport::TestCase
339
339
  test 'should validate other attributes when validate_on_invite is enabled' do
340
340
  validate_on_invite = User.validate_on_invite
341
341
  User.validate_on_invite = true
342
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
342
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50)
343
343
  refute_empty invited_user.errors[:username]
344
344
  User.validate_on_invite = validate_on_invite
345
345
  end
@@ -347,7 +347,7 @@ class InvitableTest < ActiveSupport::TestCase
347
347
  test 'should not validate password when validate_on_invite is enabled' do
348
348
  validate_on_invite = User.validate_on_invite
349
349
  User.validate_on_invite = true
350
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50)
350
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50)
351
351
  refute_empty invited_user.errors
352
352
  assert_empty invited_user.errors[:password]
353
353
  User.validate_on_invite = validate_on_invite
@@ -356,33 +356,33 @@ class InvitableTest < ActiveSupport::TestCase
356
356
  test 'should validate other attributes when validate_on_invite is enabled and email is not present' do
357
357
  validate_on_invite = User.validate_on_invite
358
358
  User.validate_on_invite = true
359
- invited_user = User.invite!(:email => "", :username => "a"*50)
359
+ invited_user = User.invite!(email: '', username: 'a' * 50)
360
360
  refute_empty invited_user.errors[:email]
361
361
  refute_empty invited_user.errors[:username]
362
362
  User.validate_on_invite = validate_on_invite
363
363
  end
364
364
 
365
365
  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")
366
+ existing_user = User.new(email: 'valid@email.com')
367
+ existing_user.save(validate: false)
368
+ user = User.invite!(email: 'valid@email.com')
369
369
  assert_equal user, existing_user
370
370
  assert_equal ['has already been taken'], user.errors[:email]
371
- same_user = User.invite!("email" => "valid@email.com")
371
+ same_user = User.invite!(email: 'valid@email.com')
372
372
  assert_equal same_user, existing_user
373
373
  assert_equal ['has already been taken'], same_user.errors[:email]
374
374
  end
375
375
 
376
376
  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")
377
+ existing_user = User.invite!(email: 'valid@email.com')
378
+ user = User.invite!(email: 'valid@email.com')
379
379
  assert_equal user, existing_user
380
380
  assert_equal [], user.errors[:email]
381
381
  resend_invitation = User.resend_invitation
382
382
  begin
383
383
  User.resend_invitation = false
384
384
 
385
- user = User.invite!(:email => "valid@email.com")
385
+ user = User.invite!(email: 'valid@email.com')
386
386
  assert_equal user, existing_user
387
387
  assert_equal ['has already been taken'], user.errors[:email]
388
388
  ensure
@@ -394,9 +394,9 @@ class InvitableTest < ActiveSupport::TestCase
394
394
  begin
395
395
  validate_on_invite = User.validate_on_invite
396
396
  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)
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)
400
400
  assert_equal user, existing_user
401
401
  assert_equal ['has already been taken'], user.errors[:email]
402
402
  refute_empty user.errors[:username]
@@ -406,19 +406,19 @@ class InvitableTest < ActiveSupport::TestCase
406
406
  end
407
407
 
408
408
  test 'should return a new record with errors if e-mail is blank' do
409
- invited_user = User.invite!(:email => '')
409
+ invited_user = User.invite!(email: '')
410
410
  assert invited_user.new_record?
411
411
  assert_equal ["can't be blank"], invited_user.errors[:email]
412
412
  end
413
413
 
414
414
  test 'should return a new record with errors if e-mail is invalid' do
415
- invited_user = User.invite!(:email => 'invalid_email')
415
+ invited_user = User.invite!(email: 'invalid_email')
416
416
  assert invited_user.new_record?
417
- assert_equal ["is invalid"], invited_user.errors[:email]
417
+ assert_equal ['is invalid'], invited_user.errors[:email]
418
418
  end
419
419
 
420
420
  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')
421
+ invited_user = User.invite!(email: 'invalid_email.com', username: 'first name')
422
422
  assert invited_user.new_record?
423
423
  assert_equal 'first name', invited_user.username
424
424
  refute_empty invited_user.errors
@@ -427,34 +427,34 @@ class InvitableTest < ActiveSupport::TestCase
427
427
  test 'should find a user to set his password based on invitation_token' do
428
428
  user = new_user
429
429
  user.invite!
430
- invited_user = User.accept_invitation!(:invitation_token => Thread.current[:token])
430
+ invited_user = User.accept_invitation!(invitation_token: Thread.current[:token])
431
431
  assert_equal invited_user, user
432
432
  end
433
433
 
434
434
  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')
435
+ invited_user = User.accept_invitation!(invitation_token: 'invalid_token')
436
436
  assert invited_user.new_record?
437
437
  assert_equal ['is invalid'], invited_user.errors[:invitation_token]
438
438
  end
439
439
 
440
440
  test 'should return a new record with errors if invitation_token is blank' do
441
- invited_user = User.accept_invitation!(:invitation_token => '')
441
+ invited_user = User.accept_invitation!(invitation_token: '')
442
442
  assert invited_user.new_record?
443
443
  assert_equal ["can't be blank"], invited_user.errors[:invitation_token]
444
444
  end
445
445
 
446
446
  test 'should return record with errors if invitation_token has expired' do
447
447
  User.stubs(:invite_for).returns(10.hours)
448
- invited_user = User.invite!(:email => "valid@email.com")
448
+ invited_user = User.invite!(email: 'valid@email.com')
449
449
  invited_user.invitation_created_at = 2.days.ago
450
- invited_user.save(:validate => false)
451
- user = User.accept_invitation!(:invitation_token => Thread.current[:token])
450
+ invited_user.save(validate: false)
451
+ user = User.accept_invitation!(invitation_token: Thread.current[:token])
452
452
  assert_equal user, invited_user
453
- assert_equal ["is invalid"], user.errors[:invitation_token]
453
+ assert_equal ['is invalid'], user.errors[:invitation_token]
454
454
  end
455
455
 
456
456
  test 'should allow record modification using block' do
457
- invited_user = User.invite!(:email => "valid@email.com", :username => "a"*50) do |u|
457
+ invited_user = User.invite!(email: 'valid@email.com', username: 'a' * 50) do |u|
458
458
  u.password = '123123'
459
459
  u.password_confirmation = '123123'
460
460
  end
@@ -462,13 +462,13 @@ class InvitableTest < ActiveSupport::TestCase
462
462
  end
463
463
 
464
464
  test 'should set successfully user password given the new password and confirmation' do
465
- user = new_user(:password => nil, :password_confirmation => nil)
465
+ user = new_user(password: nil, password_confirmation: nil)
466
466
  user.invite!
467
467
 
468
468
  User.accept_invitation!(
469
- :invitation_token => Thread.current[:token],
470
- :password => 'new_password',
471
- :password_confirmation => 'new_password'
469
+ invitation_token: Thread.current[:token],
470
+ password: 'new_password',
471
+ password_confirmation: 'new_password',
472
472
  )
473
473
  user.reload
474
474
 
@@ -476,14 +476,14 @@ class InvitableTest < ActiveSupport::TestCase
476
476
  end
477
477
 
478
478
  test 'should return errors on other attributes even when password is valid' do
479
- user = new_user(:password => nil, :password_confirmation => nil)
479
+ user = new_user(password: nil, password_confirmation: nil)
480
480
  user.invite!
481
481
 
482
482
  invited_user = User.accept_invitation!(
483
- :invitation_token => Thread.current[:token],
484
- :password => 'new_password',
485
- :password_confirmation => 'new_password',
486
- :username => 'a'*50
483
+ invitation_token: Thread.current[:token],
484
+ password: 'new_password',
485
+ password_confirmation: 'new_password',
486
+ username: 'a' * 50,
487
487
  )
488
488
  refute_empty invited_user.errors[:username]
489
489
 
@@ -492,14 +492,14 @@ class InvitableTest < ActiveSupport::TestCase
492
492
  end
493
493
 
494
494
  test 'should check if created by invitation' do
495
- user = User.invite!(:email => "valid@email.com")
495
+ user = User.invite!(email: 'valid@email.com')
496
496
  assert user.created_by_invite?
497
497
 
498
498
  invited_user = User.accept_invitation!(
499
- :invitation_token => Thread.current[:token],
500
- :password => 'new_password',
501
- :password_confirmation => 'new_password',
502
- :username => 'a'
499
+ invitation_token: Thread.current[:token],
500
+ password: 'new_password',
501
+ password_confirmation: 'new_password',
502
+ username: 'a',
503
503
  )
504
504
  user.reload
505
505
  assert user.created_by_invite?
@@ -507,14 +507,14 @@ class InvitableTest < ActiveSupport::TestCase
507
507
 
508
508
 
509
509
  test 'should set other attributes on accepting invitation' do
510
- user = new_user(:password => nil, :password_confirmation => nil)
510
+ user = new_user(password: nil, password_confirmation: nil)
511
511
  user.invite!
512
512
 
513
513
  invited_user = User.accept_invitation!(
514
- :invitation_token => Thread.current[:token],
515
- :password => 'new_password',
516
- :password_confirmation => 'new_password',
517
- :username => 'a'
514
+ invitation_token: Thread.current[:token],
515
+ password: 'new_password',
516
+ password_confirmation: 'new_password',
517
+ username: 'a',
518
518
  )
519
519
  assert invited_user.errors[:username].blank?
520
520
 
@@ -554,13 +554,13 @@ class InvitableTest < ActiveSupport::TestCase
554
554
 
555
555
  test 'should not send an invitation if we want to skip the invitation' do
556
556
  assert_no_difference('ActionMailer::Base.deliveries.size') do
557
- User.invite!(:email => "valid@email.com", :username => "a"*50, :skip_invitation => true)
557
+ User.invite!(email: 'valid@email.com', username: 'a' * 50, skip_invitation: true)
558
558
  end
559
559
  end
560
560
 
561
561
  test 'should not send an invitation if we want to skip the invitation with block' do
562
562
  assert_no_difference('ActionMailer::Base.deliveries.size') do
563
- User.invite!(:email => "valid@email.com", :username => "a"*50) do |u|
563
+ User.invite!(email: 'valid@email.com', username: 'a' * 50) do |u|
564
564
  u.skip_invitation = true
565
565
  end
566
566
  end
@@ -595,22 +595,22 @@ class InvitableTest < ActiveSupport::TestCase
595
595
 
596
596
  test 'user.invite! should set the invited_by attribute if passed' do
597
597
  user = new_user
598
- inviting_user = User.new(:email => "valid@email.com")
599
- inviting_user.save(:validate => false)
598
+ inviting_user = User.new(email: 'valid@email.com')
599
+ inviting_user.save(validate: false)
600
600
  user.invite!(inviting_user)
601
601
  assert_equal inviting_user, user.invited_by
602
602
  assert_equal inviting_user.class.to_s, user.invited_by_type
603
603
  end
604
604
 
605
605
  test 'user.accept_invitation! should trigger callbacks' do
606
- user = User.invite!(:email => "valid@email.com")
606
+ user = User.invite!(email: 'valid@email.com')
607
607
  assert_callbacks_not_fired :after_invitation_accepted, user
608
608
  user.accept_invitation!
609
609
  assert_callbacks_fired :after_invitation_accepted, user
610
610
  end
611
611
 
612
612
  test 'user.accept_invitation! should not trigger callbacks if validation fails' do
613
- user = User.invite!(:email => "valid@email.com")
613
+ user = User.invite!(email: 'valid@email.com')
614
614
  assert_callbacks_not_fired :after_invitation_accepted, user
615
615
  user.username='a'*50
616
616
  user.accept_invitation!
@@ -618,7 +618,7 @@ class InvitableTest < ActiveSupport::TestCase
618
618
  end
619
619
 
620
620
  test 'user.accept_invitation! should confirm user if confirmable' do
621
- user = User.invite!(:email => "valid@email.com")
621
+ user = User.invite!(email: 'valid@email.com')
622
622
  user.accept_invitation!
623
623
 
624
624
  assert user.confirmed?
@@ -626,7 +626,7 @@ class InvitableTest < ActiveSupport::TestCase
626
626
  end
627
627
 
628
628
  test 'user.accept_invitation! should not confirm user if validation fails' do
629
- user = User.invite!(:email => "valid@email.com")
629
+ user = User.invite!(email: 'valid@email.com')
630
630
  user.username='a'*50
631
631
  user.accept_invitation!
632
632
  user.reload
@@ -640,7 +640,7 @@ class InvitableTest < ActiveSupport::TestCase
640
640
  begin
641
641
  User.send_password_change_notification = true
642
642
 
643
- user = User.invite!(:email => "valid@email.com")
643
+ user = User.invite!(email: 'valid@email.com')
644
644
 
645
645
  assert_no_difference('ActionMailer::Base.deliveries.size') do
646
646
  user.password = user.password_confirmation = '123456789'
@@ -671,53 +671,53 @@ class InvitableTest < ActiveSupport::TestCase
671
671
 
672
672
  test "user.invite! should downcase the class's case_insensitive_keys" do
673
673
  # Devise default is :email
674
- user = User.invite!(:email => "UPPERCASE@email.com")
675
- assert user.email == "uppercase@email.com"
674
+ user = User.invite!(email: 'UPPERCASE@email.com')
675
+ assert user.email == 'uppercase@email.com'
676
676
  end
677
677
 
678
678
  test "user.invite! should strip whitespace from the class's strip_whitespace_keys" do
679
679
  # Devise default is email
680
- user = User.invite!(:email => " valid@email.com ", :active => true)
681
- assert user.email == "valid@email.com"
680
+ user = User.invite!(email: ' valid@email.com ', active: true)
681
+ assert user.email == 'valid@email.com'
682
682
  assert user.active == true
683
683
  end
684
684
 
685
685
  test "user.invite! should trigger callbacks" do
686
- user = User.new(email: "valid@email.com")
686
+ user = User.new(email: 'valid@email.com')
687
687
  assert_callbacks_not_fired :after_invitation_created, user
688
688
  user.invite!
689
689
  assert_callbacks_fired :after_invitation_created, user
690
690
  end
691
691
 
692
692
  test 'should pass validation before accept if field is required in post-invited instance' do
693
- user = User.invite!(:email => "valid@email.com")
693
+ user = User.invite!(email: 'valid@email.com')
694
694
  user.testing_accepted_or_not_invited = true
695
695
  user.valid?
696
696
  assert_empty user.errors
697
697
  end
698
698
 
699
699
  test 'should fail validation after accept if field is required in post-invited instance' do
700
- user = User.invite!(:email => "valid@email.com")
700
+ user = User.invite!(email: 'valid@email.com')
701
701
  user.testing_accepted_or_not_invited = true
702
702
  assert_predicate user, :accept_invitation!
703
- user = User.where(:email => "valid@email.com").first
703
+ user = User.where(email: 'valid@email.com').first
704
704
  user.valid?
705
705
  refute_empty user.errors
706
706
  end
707
707
 
708
708
  test 'should pass validation after accept if field is required in post-invited instance' do
709
- user = User.invite!(:email => "valid@email.com")
709
+ user = User.invite!(email: 'valid@email.com')
710
710
  user.username = 'test'
711
711
  user.testing_accepted_or_not_invited = true
712
712
  assert_predicate user, :accept_invitation!
713
- user = User.where(:email => "valid@email.com").first
713
+ user = User.where(email: 'valid@email.com').first
714
714
  user.bio = "Test"
715
715
  user.valid?
716
716
  assert_empty user.errors
717
717
  end
718
718
 
719
719
  test 'should return instance with errors if invitation_token is nil' do
720
- User.create(:email => 'admin@test.com', :password => '123456', :password_confirmation => '123456')
720
+ User.create(email: 'admin@test.com', password: '123456', password_confirmation: '123456')
721
721
  user = User.accept_invitation!
722
722
  refute_empty user.errors
723
723
  end
@@ -727,9 +727,9 @@ class InvitableTest < ActiveSupport::TestCase
727
727
  assert_equal 0, User.invitation_accepted.count
728
728
  assert_equal 0, User.created_by_invite.count
729
729
 
730
- User.invite!(:email => "invalid@email.com")
731
- User.invite!(:email => "another_invalid@email.com")
732
- user = User.invite!(:email => "valid@email.com")
730
+ User.invite!(email: 'invalid@email.com')
731
+ User.invite!(email: 'another_invalid@email.com')
732
+ user = User.invite!(email: 'valid@email.com')
733
733
 
734
734
  assert_equal 3, User.invitation_not_accepted.count
735
735
  assert_equal 0, User.invitation_accepted.count
@@ -754,9 +754,9 @@ class InvitableTest < ActiveSupport::TestCase
754
754
  (?=.*[A-Z]) # Must contain an upper case character
755
755
  (?=.*[[:^alnum:]]) # Must contain a symbol
756
756
  /x
757
- User.stubs(:invite_key).returns(:password => PASSWORD_FORMAT)
757
+ User.stubs(:invite_key).returns(password: PASSWORD_FORMAT)
758
758
  Devise.stubs(:friendly_token).returns('onlylowercaseletters')
759
- user = User.invite!(:email => "valid@email.com")
759
+ user = User.invite!(email: 'valid@email.com')
760
760
  assert user.persisted?
761
761
  assert user.errors.empty?
762
762
  end