devise 3.4.1 → 3.5.10

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

Potentially problematic release.


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

Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +28 -19
  3. data/CHANGELOG.md +193 -104
  4. data/CODE_OF_CONDUCT.md +22 -0
  5. data/CONTRIBUTING.md +2 -0
  6. data/Gemfile +3 -2
  7. data/Gemfile.lock +90 -95
  8. data/MIT-LICENSE +1 -1
  9. data/README.md +55 -34
  10. data/Rakefile +2 -1
  11. data/app/controllers/devise/confirmations_controller.rb +4 -0
  12. data/app/controllers/devise/omniauth_callbacks_controller.rb +4 -0
  13. data/app/controllers/devise/passwords_controller.rb +14 -4
  14. data/app/controllers/devise/registrations_controller.rb +10 -11
  15. data/app/controllers/devise/sessions_controller.rb +7 -2
  16. data/app/controllers/devise/unlocks_controller.rb +3 -0
  17. data/app/controllers/devise_controller.rb +34 -18
  18. data/app/mailers/devise/mailer.rb +4 -0
  19. data/app/views/devise/confirmations/new.html.erb +1 -1
  20. data/app/views/devise/mailer/password_change.html.erb +3 -0
  21. data/app/views/devise/passwords/edit.html.erb +3 -0
  22. data/app/views/devise/registrations/new.html.erb +1 -1
  23. data/app/views/devise/shared/_links.html.erb +1 -1
  24. data/config/locales/en.yml +2 -0
  25. data/devise.gemspec +0 -2
  26. data/gemfiles/Gemfile.rails-3.2-stable.lock +52 -49
  27. data/gemfiles/Gemfile.rails-4.0-stable +1 -0
  28. data/gemfiles/Gemfile.rails-4.0-stable.lock +61 -60
  29. data/gemfiles/Gemfile.rails-4.1-stable +1 -0
  30. data/gemfiles/Gemfile.rails-4.1-stable.lock +66 -65
  31. data/gemfiles/Gemfile.rails-4.2-stable +30 -0
  32. data/gemfiles/Gemfile.rails-4.2-stable.lock +193 -0
  33. data/lib/devise/controllers/helpers.rb +12 -6
  34. data/lib/devise/controllers/rememberable.rb +9 -2
  35. data/lib/devise/controllers/sign_in_out.rb +2 -8
  36. data/lib/devise/controllers/store_location.rb +3 -1
  37. data/lib/devise/controllers/url_helpers.rb +7 -9
  38. data/lib/devise/encryptor.rb +22 -0
  39. data/lib/devise/failure_app.rb +48 -13
  40. data/lib/devise/hooks/timeoutable.rb +5 -7
  41. data/lib/devise/mapping.rb +1 -0
  42. data/lib/devise/models/authenticatable.rb +20 -26
  43. data/lib/devise/models/confirmable.rb +51 -17
  44. data/lib/devise/models/database_authenticatable.rb +17 -11
  45. data/lib/devise/models/lockable.rb +5 -1
  46. data/lib/devise/models/recoverable.rb +23 -15
  47. data/lib/devise/models/rememberable.rb +56 -22
  48. data/lib/devise/models/timeoutable.rb +0 -6
  49. data/lib/devise/models/trackable.rb +1 -2
  50. data/lib/devise/models/validatable.rb +3 -3
  51. data/lib/devise/models.rb +1 -1
  52. data/lib/devise/rails/routes.rb +27 -18
  53. data/lib/devise/rails.rb +1 -1
  54. data/lib/devise/strategies/authenticatable.rb +7 -4
  55. data/lib/devise/strategies/database_authenticatable.rb +1 -1
  56. data/lib/devise/strategies/rememberable.rb +13 -6
  57. data/lib/devise/test_helpers.rb +2 -2
  58. data/lib/devise/version.rb +1 -1
  59. data/lib/devise.rb +37 -36
  60. data/lib/generators/active_record/templates/migration.rb +1 -1
  61. data/lib/generators/active_record/templates/migration_existing.rb +1 -1
  62. data/lib/generators/devise/views_generator.rb +14 -3
  63. data/lib/generators/templates/controllers/README +2 -2
  64. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +1 -1
  65. data/lib/generators/templates/controllers/registrations_controller.rb +2 -2
  66. data/lib/generators/templates/controllers/sessions_controller.rb +1 -1
  67. data/lib/generators/templates/devise.rb +17 -11
  68. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  69. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  70. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  71. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  72. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +1 -1
  73. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +1 -1
  74. data/test/controllers/custom_registrations_controller_test.rb +6 -1
  75. data/test/controllers/helper_methods_test.rb +21 -0
  76. data/test/controllers/helpers_test.rb +5 -0
  77. data/test/controllers/inherited_controller_i18n_messages_test.rb +51 -0
  78. data/test/controllers/internal_helpers_test.rb +4 -4
  79. data/test/controllers/load_hooks_controller_test.rb +19 -0
  80. data/test/controllers/passwords_controller_test.rb +1 -1
  81. data/test/controllers/sessions_controller_test.rb +3 -3
  82. data/test/devise_test.rb +3 -3
  83. data/test/failure_app_test.rb +40 -0
  84. data/test/generators/views_generator_test.rb +7 -0
  85. data/test/integration/database_authenticatable_test.rb +11 -0
  86. data/test/integration/omniauthable_test.rb +12 -10
  87. data/test/integration/recoverable_test.rb +13 -0
  88. data/test/integration/rememberable_test.rb +50 -3
  89. data/test/integration/timeoutable_test.rb +13 -18
  90. data/test/mailers/confirmation_instructions_test.rb +1 -1
  91. data/test/mapping_test.rb +6 -0
  92. data/test/models/confirmable_test.rb +93 -37
  93. data/test/models/database_authenticatable_test.rb +20 -0
  94. data/test/models/lockable_test.rb +29 -7
  95. data/test/models/recoverable_test.rb +62 -7
  96. data/test/models/rememberable_test.rb +68 -97
  97. data/test/models/validatable_test.rb +5 -5
  98. data/test/models_test.rb +15 -6
  99. data/test/rails_app/app/active_record/user_without_email.rb +8 -0
  100. data/test/rails_app/app/controllers/admins_controller.rb +0 -5
  101. data/test/rails_app/app/controllers/custom/registrations_controller.rb +10 -0
  102. data/test/rails_app/app/mongoid/user_without_email.rb +33 -0
  103. data/test/rails_app/config/application.rb +1 -1
  104. data/test/rails_app/config/environments/production.rb +6 -2
  105. data/test/rails_app/config/environments/test.rb +7 -2
  106. data/test/rails_app/config/initializers/devise.rb +12 -15
  107. data/test/rails_app/config/routes.rb +6 -3
  108. data/test/rails_app/lib/shared_user.rb +1 -1
  109. data/test/rails_app/lib/shared_user_without_email.rb +26 -0
  110. data/test/rails_test.rb +9 -0
  111. data/test/support/helpers.rb +4 -0
  112. data/test/support/integration.rb +2 -2
  113. data/test/test_helpers_test.rb +22 -7
  114. data/test/test_models.rb +2 -2
  115. data/test/time_helpers.rb +137 -0
  116. metadata +26 -4
@@ -23,13 +23,13 @@ class RecoverableTest < ActiveSupport::TestCase
23
23
 
24
24
  test 'should reset password and password confirmation from params' do
25
25
  user = create_user
26
- user.reset_password!('123456789', '987654321')
26
+ user.reset_password('123456789', '987654321')
27
27
  assert_equal '123456789', user.password
28
28
  assert_equal '987654321', user.password_confirmation
29
29
  end
30
30
 
31
31
  test 'should reset password and save the record' do
32
- assert create_user.reset_password!('123456789', '123456789')
32
+ assert create_user.reset_password('123456789', '123456789')
33
33
  end
34
34
 
35
35
  test 'should clear reset password token while reseting the password' do
@@ -38,7 +38,53 @@ class RecoverableTest < ActiveSupport::TestCase
38
38
 
39
39
  user.send_reset_password_instructions
40
40
  assert_present user.reset_password_token
41
- assert user.reset_password!('123456789', '123456789')
41
+ assert user.reset_password('123456789', '123456789')
42
+ assert_nil user.reset_password_token
43
+ end
44
+
45
+ test 'should not clear reset password token for new user' do
46
+ user = new_user
47
+ assert_nil user.reset_password_token
48
+
49
+ user.send_reset_password_instructions
50
+ assert_present user.reset_password_token
51
+
52
+ user.save
53
+ assert_present user.reset_password_token
54
+ end
55
+
56
+ test 'should clear reset password token if changing password' do
57
+ user = create_user
58
+ assert_nil user.reset_password_token
59
+
60
+ user.send_reset_password_instructions
61
+ assert_present user.reset_password_token
62
+ user.password = "123456678"
63
+ user.password_confirmation = "123456678"
64
+ user.save!
65
+ assert_nil user.reset_password_token
66
+ end
67
+
68
+ test 'should clear reset password token if changing email' do
69
+ user = create_user
70
+ assert_nil user.reset_password_token
71
+
72
+ user.send_reset_password_instructions
73
+ assert_present user.reset_password_token
74
+ user.email = "another@example.com"
75
+ user.save!
76
+ assert_nil user.reset_password_token
77
+ end
78
+
79
+ test 'should clear reset password successfully even if there is no email' do
80
+ user = create_user_without_email
81
+ assert_nil user.reset_password_token
82
+
83
+ user.send_reset_password_instructions
84
+ assert_present user.reset_password_token
85
+ user.password = "123456678"
86
+ user.password_confirmation = "123456678"
87
+ user.save!
42
88
  assert_nil user.reset_password_token
43
89
  end
44
90
 
@@ -46,14 +92,14 @@ class RecoverableTest < ActiveSupport::TestCase
46
92
  user = create_user
47
93
  user.send_reset_password_instructions
48
94
  assert_present user.reset_password_token
49
- assert_not user.reset_password!('123456789', '987654321')
95
+ assert_not user.reset_password('123456789', '987654321')
50
96
  assert_present user.reset_password_token
51
97
  end
52
98
 
53
99
  test 'should not reset password with invalid data' do
54
100
  user = create_user
55
101
  user.stubs(:valid?).returns(false)
56
- assert_not user.reset_password!('123456789', '987654321')
102
+ assert_not user.reset_password('123456789', '987654321')
57
103
  end
58
104
 
59
105
  test 'should reset reset password token and send instructions by email' do
@@ -135,6 +181,7 @@ class RecoverableTest < ActiveSupport::TestCase
135
181
  reset_password_user = User.reset_password_by_token(reset_password_token: raw, password: '')
136
182
  assert_not reset_password_user.errors.empty?
137
183
  assert_match "can't be blank", reset_password_user.errors[:password].join
184
+ assert_equal raw, reset_password_user.reset_password_token
138
185
  end
139
186
 
140
187
  test 'should reset successfully user password given the new password and confirmation' do
@@ -142,15 +189,17 @@ class RecoverableTest < ActiveSupport::TestCase
142
189
  old_password = user.password
143
190
  raw = user.send_reset_password_instructions
144
191
 
145
- User.reset_password_by_token(
192
+ reset_password_user = User.reset_password_by_token(
146
193
  reset_password_token: raw,
147
194
  password: 'new_password',
148
195
  password_confirmation: 'new_password'
149
196
  )
150
- user.reload
197
+ assert_nil reset_password_user.reset_password_token
151
198
 
199
+ user.reload
152
200
  assert_not user.valid_password?(old_password)
153
201
  assert user.valid_password?('new_password')
202
+ assert_nil user.reset_password_token
154
203
  end
155
204
 
156
205
  test 'should not reset password after reset_password_within time' do
@@ -189,6 +238,12 @@ class RecoverableTest < ActiveSupport::TestCase
189
238
  assert_equal User.with_reset_password_token(raw), user
190
239
  end
191
240
 
241
+ test 'should return the same reset password token as generated' do
242
+ user = create_user
243
+ raw = user.send_reset_password_instructions
244
+ assert_equal Devise.token_generator.digest(self.class, :reset_password_token, raw), user.reset_password_token
245
+ end
246
+
192
247
  test 'should return nil if a user based on the raw token is not found' do
193
248
  assert_equal User.with_reset_password_token('random-token'), nil
194
249
  end
@@ -13,6 +13,19 @@ class RememberableTest < ActiveSupport::TestCase
13
13
  user = create_user
14
14
  user.expects(:valid?).never
15
15
  user.remember_me!
16
+ assert user.remember_created_at
17
+ end
18
+
19
+ test 'remember_me should not generate a new token if valid token exists' do
20
+ user = create_user
21
+ user.singleton_class.send(:attr_accessor, :remember_token)
22
+ User.to_adapter.expects(:find_first).returns(nil)
23
+
24
+ user.remember_me!
25
+ existing_token = user.remember_token
26
+
27
+ user.remember_me!
28
+ assert_equal existing_token, user.remember_token
16
29
  end
17
30
 
18
31
  test 'forget_me should not clear remember token if using salt' do
@@ -33,18 +46,68 @@ class RememberableTest < ActiveSupport::TestCase
33
46
  test 'serialize into cookie' do
34
47
  user = create_user
35
48
  user.remember_me!
36
- assert_equal [user.to_key, user.authenticatable_salt], User.serialize_into_cookie(user)
49
+ id, token, date = User.serialize_into_cookie(user)
50
+ assert_equal id, user.to_key
51
+ assert_equal token, user.authenticatable_salt
52
+ assert date.is_a?(String)
37
53
  end
38
54
 
39
55
  test 'serialize from cookie' do
40
56
  user = create_user
41
57
  user.remember_me!
42
- assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt)
58
+ assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc)
59
+ end
60
+
61
+ test 'serialize from cookie should accept a String with the datetime seconds and microseconds' do
62
+ user = create_user
63
+ user.remember_me!
64
+ assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc.to_f.to_json)
65
+ end
66
+
67
+ test 'serialize from cookie should return nil with invalid datetime' do
68
+ user = create_user
69
+ user.remember_me!
70
+ assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, "2013")
43
71
  end
44
72
 
45
- test 'raises a RuntimeError if authenticatable_salt is nil' do
73
+ test 'serialize from cookie should return nil if no resource is found' do
74
+ assert_nil resource_class.serialize_from_cookie([0], "123", Time.now.utc)
75
+ end
76
+
77
+ test 'serialize from cookie should return nil if no timestamp' do
78
+ user = create_user
79
+ user.remember_me!
80
+ assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt)
81
+ end
82
+
83
+ test 'serialize from cookie should return nil if timestamp is earlier than token creation' do
84
+ user = create_user
85
+ user.remember_me!
86
+ assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 1.day.ago)
87
+ end
88
+
89
+ test 'serialize from cookie should return nil if timestamp is older than remember_for' do
90
+ user = create_user
91
+ user.remember_created_at = 1.month.ago
92
+ user.remember_me!
93
+ assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 3.weeks.ago)
94
+ end
95
+
96
+ test 'serialize from cookie me return nil if is a valid resource with invalid token' do
97
+ user = create_user
98
+ user.remember_me!
99
+ assert_nil User.serialize_from_cookie(user.to_key, "123", Time.now.utc)
100
+ end
101
+
102
+ test 'raises a RuntimeError if authenticatable_salt is nil or empty' do
103
+ user = User.new
104
+ def user.authenticable_salt; nil; end
105
+ assert_raise RuntimeError do
106
+ user.rememberable_value
107
+ end
108
+
46
109
  user = User.new
47
- user.encrypted_password = nil
110
+ def user.authenticable_salt; ""; end
48
111
  assert_raise RuntimeError do
49
112
  user.rememberable_value
50
113
  end
@@ -87,28 +150,7 @@ class RememberableTest < ActiveSupport::TestCase
87
150
  resource.forget_me!
88
151
  end
89
152
 
90
- test 'remember is expired if not created at timestamp is set' do
91
- assert create_resource.remember_expired?
92
- end
93
-
94
- test 'serialize should return nil if no resource is found' do
95
- assert_nil resource_class.serialize_from_cookie([0], "123")
96
- end
97
-
98
- test 'remember me return nil if is a valid resource with invalid token' do
99
- resource = create_resource
100
- assert_nil resource_class.serialize_from_cookie([resource.id], "123")
101
- end
102
-
103
- test 'remember for should fallback to devise remember for default configuration' do
104
- swap Devise, remember_for: 1.day do
105
- resource = create_resource
106
- resource.remember_me!
107
- assert_not resource.remember_expired?
108
- end
109
- end
110
-
111
- test 'remember expires at should sum date of creation with remember for configuration' do
153
+ test 'remember expires at uses remember for configuration' do
112
154
  swap Devise, remember_for: 3.days do
113
155
  resource = create_resource
114
156
  resource.remember_me!
@@ -119,77 +161,6 @@ class RememberableTest < ActiveSupport::TestCase
119
161
  end
120
162
  end
121
163
 
122
- test 'remember should be expired if remember_for is zero' do
123
- swap Devise, remember_for: 0.days do
124
- Devise.remember_for = 0.days
125
- resource = create_resource
126
- resource.remember_me!
127
- assert resource.remember_expired?
128
- end
129
- end
130
-
131
- test 'remember should be expired if it was created before limit time' do
132
- swap Devise, remember_for: 1.day do
133
- resource = create_resource
134
- resource.remember_me!
135
- resource.remember_created_at = 2.days.ago
136
- resource.save
137
- assert resource.remember_expired?
138
- end
139
- end
140
-
141
- test 'remember should not be expired if it was created within the limit time' do
142
- swap Devise, remember_for: 30.days do
143
- resource = create_resource
144
- resource.remember_me!
145
- resource.remember_created_at = (30.days.ago + 2.minutes)
146
- resource.save
147
- assert_not resource.remember_expired?
148
- end
149
- end
150
-
151
- test 'if extend_remember_period is false, remember_me! should generate a new timestamp if expired' do
152
- swap Devise, remember_for: 5.minutes do
153
- resource = create_resource
154
- resource.remember_me!(false)
155
- assert resource.remember_created_at
156
-
157
- resource.remember_created_at = old = 10.minutes.ago
158
- resource.save
159
-
160
- resource.remember_me!(false)
161
- assert_not_equal old.to_i, resource.remember_created_at.to_i
162
- end
163
- end
164
-
165
- test 'if extend_remember_period is false, remember_me! should not generate a new timestamp' do
166
- swap Devise, remember_for: 1.year do
167
- resource = create_resource
168
- resource.remember_me!(false)
169
- assert resource.remember_created_at
170
-
171
- resource.remember_created_at = old = 10.minutes.ago.utc
172
- resource.save
173
-
174
- resource.remember_me!(false)
175
- assert_equal old.to_i, resource.remember_created_at.to_i
176
- end
177
- end
178
-
179
- test 'if extend_remember_period is true, remember_me! should always generate a new timestamp' do
180
- swap Devise, remember_for: 1.year do
181
- resource = create_resource
182
- resource.remember_me!(true)
183
- assert resource.remember_created_at
184
-
185
- resource.remember_created_at = old = 10.minutes.ago
186
- resource.save
187
-
188
- resource.remember_me!(true)
189
- assert_not_equal old, resource.remember_created_at
190
- end
191
- end
192
-
193
164
  test 'should have the required_fields array' do
194
165
  assert_same_content Devise::Models::Rememberable.required_fields(User), [
195
166
  :remember_created_at
@@ -92,10 +92,10 @@ class ValidatableTest < ActiveSupport::TestCase
92
92
  assert_equal 'is too short (minimum is 7 characters)', user.errors[:password].join
93
93
  end
94
94
 
95
- test 'should require a password with maximum of 128 characters long' do
96
- user = new_user(password: 'x'*129, password_confirmation: 'x'*129)
95
+ test 'should require a password with maximum of 72 characters long' do
96
+ user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
97
97
  assert user.invalid?
98
- assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
98
+ assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
99
99
  end
100
100
 
101
101
  test 'should not require password length when it\'s not changed' do
@@ -109,10 +109,10 @@ class ValidatableTest < ActiveSupport::TestCase
109
109
  end
110
110
 
111
111
  test 'should complain about length even if password is not required' do
112
- user = new_user(password: 'x'*129, password_confirmation: 'x'*129)
112
+ user = new_user(password: 'x'*73, password_confirmation: 'x'*73)
113
113
  user.stubs(:password_required?).returns(false)
114
114
  assert user.invalid?
115
- assert_equal 'is too long (maximum is 128 characters)', user.errors[:password].join
115
+ assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join
116
116
  end
117
117
 
118
118
  test 'should not be included in objects with invalid API' do
data/test/models_test.rb CHANGED
@@ -92,13 +92,20 @@ class ActiveRecordTest < ActiveSupport::TestCase
92
92
  end
93
93
  end
94
94
 
95
+ module StubModelFilters
96
+ def stub_filter(name)
97
+ define_singleton_method(name) { |*| nil }
98
+ end
99
+ end
100
+
95
101
  class CheckFieldsTest < ActiveSupport::TestCase
96
102
  test 'checks if the class respond_to the required fields' do
97
103
  Player = Class.new do
98
104
  extend Devise::Models
105
+ extend StubModelFilters
99
106
 
100
- def self.before_validation(instance)
101
- end
107
+ stub_filter :before_validation
108
+ stub_filter :after_update
102
109
 
103
110
  devise :database_authenticatable
104
111
 
@@ -113,9 +120,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
113
120
  test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\'t respond_to one of the attributes' do
114
121
  Clown = Class.new do
115
122
  extend Devise::Models
123
+ extend StubModelFilters
116
124
 
117
- def self.before_validation(instance)
118
- end
125
+ stub_filter :before_validation
126
+ stub_filter :after_update
119
127
 
120
128
  devise :database_authenticatable
121
129
 
@@ -130,9 +138,10 @@ class CheckFieldsTest < ActiveSupport::TestCase
130
138
  test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do
131
139
  Magician = Class.new do
132
140
  extend Devise::Models
141
+ extend StubModelFilters
133
142
 
134
- def self.before_validation(instance)
135
- end
143
+ stub_filter :before_validation
144
+ stub_filter :after_update
136
145
 
137
146
  devise :database_authenticatable
138
147
  end
@@ -0,0 +1,8 @@
1
+ require "shared_user_without_email"
2
+
3
+ class UserWithoutEmail < ActiveRecord::Base
4
+ self.table_name = 'users'
5
+ include Shim
6
+ include SharedUserWithoutEmail
7
+ end
8
+
@@ -3,9 +3,4 @@ class AdminsController < ApplicationController
3
3
 
4
4
  def index
5
5
  end
6
-
7
- def expire
8
- admin_session['last_request_at'] = 31.minutes.ago.utc
9
- render text: 'Admin will be expired on next request'
10
- end
11
6
  end
@@ -1,4 +1,10 @@
1
1
  class Custom::RegistrationsController < Devise::RegistrationsController
2
+ def new
3
+ super do |resource|
4
+ @new_block_called = true
5
+ end
6
+ end
7
+
2
8
  def create
3
9
  super do |resource|
4
10
  @create_block_called = true
@@ -18,4 +24,8 @@ class Custom::RegistrationsController < Devise::RegistrationsController
18
24
  def update_block_called?
19
25
  @update_block_called == true
20
26
  end
27
+
28
+ def new_block_called?
29
+ @new_block_called == true
30
+ end
21
31
  end
@@ -0,0 +1,33 @@
1
+ require "shared_user_without_email"
2
+
3
+ class UserWithoutEmail
4
+ include Mongoid::Document
5
+ include Shim
6
+ include SharedUserWithoutEmail
7
+
8
+ field :username, type: String
9
+ field :facebook_token, type: String
10
+
11
+ ## Database authenticatable
12
+ field :email, type: String, default: ""
13
+ field :encrypted_password, type: String, default: ""
14
+
15
+ ## Recoverable
16
+ field :reset_password_token, type: String
17
+ field :reset_password_sent_at, type: Time
18
+
19
+ ## Rememberable
20
+ field :remember_created_at, type: Time
21
+
22
+ ## Trackable
23
+ field :sign_in_count, type: Integer, default: 0
24
+ field :current_sign_in_at, type: Time
25
+ field :last_sign_in_at, type: Time
26
+ field :current_sign_in_ip, type: String
27
+ field :last_sign_in_ip, type: String
28
+
29
+ ## Lockable
30
+ field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts
31
+ field :unlock_token, type: String # Only if unlock strategy is :email or :both
32
+ field :locked_at, type: Time
33
+ end
@@ -17,7 +17,7 @@ module RailsApp
17
17
  class Application < Rails::Application
18
18
  # Add additional load paths for your own custom dirs
19
19
  config.autoload_paths.reject!{ |p| p =~ /\/app\/(\w+)$/ && !%w(controllers helpers mailers views).include?($1) }
20
- config.autoload_paths += [ "#{config.root}/app/#{DEVISE_ORM}" ]
20
+ config.autoload_paths += ["#{config.root}/app/#{DEVISE_ORM}"]
21
21
 
22
22
  # Configure generators values. Many other options are available, be sure to check the documentation.
23
23
  # config.generators do |g|
@@ -20,7 +20,11 @@ RailsApp::Application.configure do
20
20
  # config.action_dispatch.rack_cache = true
21
21
 
22
22
  # Disable Rails's static asset server (Apache or nginx will already do this).
23
- config.serve_static_assets = false
23
+ if Rails.version >= "4.2.0"
24
+ config.serve_static_files = false
25
+ else
26
+ config.serve_static_assets = false
27
+ end
24
28
 
25
29
  # Compress JavaScripts and CSS.
26
30
  config.assets.js_compressor = :uglifier
@@ -46,7 +50,7 @@ RailsApp::Application.configure do
46
50
  config.log_level = :info
47
51
 
48
52
  # Prepend all log lines with the following tags.
49
- # config.log_tags = [ :subdomain, :uuid ]
53
+ # config.log_tags = [:subdomain, :uuid]
50
54
 
51
55
  # Use a different logger for distributed setups.
52
56
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
@@ -12,8 +12,13 @@ RailsApp::Application.configure do
12
12
  # preloads Rails for running tests, you may have to set it to true.
13
13
  config.eager_load = false
14
14
 
15
- # Configure static asset server for tests with Cache-Control for performance.
16
- config.serve_static_assets = true
15
+ # Disable serving static files from the `/public` folder by default since
16
+ # Apache or NGINX already handles this.
17
+ if Rails.version >= "4.2.0"
18
+ config.serve_static_files = true
19
+ else
20
+ config.serve_static_assets = true
21
+ end
17
22
  config.static_cache_control = "public, max-age=3600"
18
23
 
19
24
  # Show full error reports and disable caching.
@@ -31,7 +31,7 @@ Devise.setup do |config|
31
31
  # session. If you need permissions, you should implement that in a before filter.
32
32
  # You can also supply hash where the value is a boolean expliciting if authentication
33
33
  # should be aborted or not if the value is not present. By default is empty.
34
- # config.authentication_keys = [ :email ]
34
+ # config.authentication_keys = [:email]
35
35
 
36
36
  # Configure parameters from the request object used for authentication. Each entry
37
37
  # given should be a request method and it will automatically be passed to
@@ -43,12 +43,12 @@ Devise.setup do |config|
43
43
  # Configure which authentication keys should be case-insensitive.
44
44
  # These keys will be downcased upon creating or modifying a user and when used
45
45
  # to authenticate or find a user. Default is :email.
46
- config.case_insensitive_keys = [ :email ]
46
+ config.case_insensitive_keys = [:email]
47
47
 
48
48
  # Configure which authentication keys should have whitespace stripped.
49
49
  # These keys will have whitespace before and after removed upon creating or
50
50
  # modifying a user and when used to authenticate or find a user. Default is :email.
51
- config.strip_whitespace_keys = [ :email ]
51
+ config.strip_whitespace_keys = [:email]
52
52
 
53
53
  # Tell if authentication through request.params is enabled. True by default.
54
54
  # config.params_authenticatable = true
@@ -77,21 +77,18 @@ Devise.setup do |config|
77
77
  # config.allow_unconfirmed_access_for = 2.days
78
78
 
79
79
  # Defines which key will be used when confirming an account
80
- # config.confirmation_keys = [ :email ]
80
+ # config.confirmation_keys = [:email]
81
81
 
82
82
  # ==> Configuration for :rememberable
83
83
  # The time the user will be remembered without asking for credentials again.
84
84
  # config.remember_for = 2.weeks
85
85
 
86
- # If true, a valid remember token can be re-used between multiple browsers.
87
- # config.remember_across_browsers = true
88
-
89
86
  # If true, extends the user's remember period when remembered via cookie.
90
87
  # config.extend_remember_period = false
91
88
 
92
89
  # ==> Configuration for :validatable
93
- # Range for password length. Default is 8..128.
94
- # config.password_length = 8..128
90
+ # Range for password length. Default is 8..72.
91
+ # config.password_length = 8..72
95
92
 
96
93
  # Regex to use to validate the email address
97
94
  # config.email_regexp = /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i
@@ -108,7 +105,7 @@ Devise.setup do |config|
108
105
  # config.lock_strategy = :failed_attempts
109
106
 
110
107
  # Defines which key will be used when locking and unlocking an account
111
- # config.unlock_keys = [ :email ]
108
+ # config.unlock_keys = [:email]
112
109
 
113
110
  # Defines which strategy will be used to unlock an account.
114
111
  # :email = Sends an unlock link to the user email
@@ -127,20 +124,20 @@ Devise.setup do |config|
127
124
  # ==> Configuration for :recoverable
128
125
  #
129
126
  # Defines which key will be used when recovering the password for an account
130
- # config.reset_password_keys = [ :email ]
127
+ # config.reset_password_keys = [:email]
131
128
 
132
129
  # Time interval you can reset your password with a reset password key.
133
130
  # Don't put a too small interval or your users won't have the time to
134
131
  # change their passwords.
135
132
  config.reset_password_within = 2.hours
136
133
 
134
+ # When set to false, does not sign a user in automatically after their password is
135
+ # reset. Defaults to true, so a user is signed in automatically after a reset.
136
+ # config.sign_in_after_reset_password = true
137
+
137
138
  # Setup a pepper to generate the encrypted password.
138
139
  config.pepper = "d142367154e5beacca404b1a6a4f8bc52c6fdcfa3ccc3cf8eb49f3458a688ee6ac3b9fae488432a3bfca863b8a90008368a9f3a3dfbe5a962e64b6ab8f3a3a1a"
139
140
 
140
- # ==> Configuration for :token_authenticatable
141
- # Defines name of the authentication token params key
142
- # config.token_authentication_key = :auth_token
143
-
144
141
  # ==> Scopes configuration
145
142
  # Turn scoped views on. Before rendering "sessions/new", it will first check for
146
143
  # "users/sessions/new". It's turned off by default because it's slower if you
@@ -13,9 +13,7 @@ Rails.application.routes.draw do
13
13
  end
14
14
  end
15
15
 
16
- resources :admins, only: [:index] do
17
- get :expire, on: :member
18
- end
16
+ resources :admins, only: [:index]
19
17
 
20
18
  # Users scope
21
19
  devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
@@ -30,6 +28,11 @@ Rails.application.routes.draw do
30
28
  router_name: :fake_engine,
31
29
  module: :devise
32
30
 
31
+ devise_for :user_without_email,
32
+ class_name: 'UserWithoutEmail',
33
+ router_name: :main_app,
34
+ module: :devise
35
+
33
36
  as :user do
34
37
  get "/as/sign_in", to: "devise/sessions#new"
35
38
  end
@@ -4,7 +4,7 @@ module SharedUser
4
4
  included do
5
5
  devise :database_authenticatable, :confirmable, :lockable, :recoverable,
6
6
  :registerable, :rememberable, :timeoutable,
7
- :trackable, :validatable, :omniauthable, password_length: 7..128
7
+ :trackable, :validatable, :omniauthable, password_length: 7..72
8
8
 
9
9
  attr_accessor :other_key
10
10
 
@@ -0,0 +1,26 @@
1
+ module SharedUserWithoutEmail
2
+ extend ActiveSupport::Concern
3
+
4
+ included do
5
+ # NOTE: This is missing :validatable and :confirmable, as they both require
6
+ # an email field at the moment. It is also missing :omniauthable because that
7
+ # adds unnecessary complexity to the setup
8
+ devise :database_authenticatable, :lockable, :recoverable,
9
+ :registerable, :rememberable, :timeoutable,
10
+ :trackable
11
+ end
12
+
13
+ # This test stub is a bit rubbish because it's tied very closely to the
14
+ # implementation where we care about this one case. However, completely
15
+ # removing the email field breaks "recoverable" tests completely, so we are
16
+ # just taking the approach here that "email" is something that is a not an
17
+ # ActiveRecord field.
18
+ def email_changed?
19
+ raise NoMethodError
20
+ end
21
+
22
+ def respond_to?(method_name, include_all=false)
23
+ return false if method_name.to_sym == :email_changed?
24
+ super(method_name, include_all)
25
+ end
26
+ end