devise 3.2.2 → 4.6.0

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 (235) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +242 -978
  3. data/MIT-LICENSE +1 -1
  4. data/README.md +371 -100
  5. data/app/controllers/devise/confirmations_controller.rb +11 -5
  6. data/app/controllers/devise/omniauth_callbacks_controller.rb +12 -6
  7. data/app/controllers/devise/passwords_controller.rb +21 -8
  8. data/app/controllers/devise/registrations_controller.rb +59 -26
  9. data/app/controllers/devise/sessions_controller.rb +47 -17
  10. data/app/controllers/devise/unlocks_controller.rb +9 -4
  11. data/app/controllers/devise_controller.rb +67 -31
  12. data/app/helpers/devise_helper.rb +12 -19
  13. data/app/mailers/devise/mailer.rb +10 -0
  14. data/app/views/devise/confirmations/new.html.erb +9 -5
  15. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  16. data/app/views/devise/mailer/email_changed.html.erb +7 -0
  17. data/app/views/devise/mailer/password_change.html.erb +3 -0
  18. data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
  19. data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
  20. data/app/views/devise/passwords/edit.html.erb +16 -7
  21. data/app/views/devise/passwords/new.html.erb +9 -5
  22. data/app/views/devise/registrations/edit.html.erb +29 -15
  23. data/app/views/devise/registrations/new.html.erb +20 -9
  24. data/app/views/devise/sessions/new.html.erb +19 -10
  25. data/app/views/devise/shared/_error_messages.html.erb +15 -0
  26. data/app/views/devise/shared/{_links.erb → _links.html.erb} +9 -9
  27. data/app/views/devise/unlocks/new.html.erb +9 -5
  28. data/config/locales/en.yml +23 -17
  29. data/lib/devise/controllers/helpers.rb +112 -32
  30. data/lib/devise/controllers/rememberable.rb +15 -6
  31. data/lib/devise/controllers/scoped_views.rb +3 -1
  32. data/lib/devise/controllers/sign_in_out.rb +42 -26
  33. data/lib/devise/controllers/store_location.rb +31 -5
  34. data/lib/devise/controllers/url_helpers.rb +9 -7
  35. data/lib/devise/delegator.rb +2 -0
  36. data/lib/devise/encryptor.rb +24 -0
  37. data/lib/devise/failure_app.rb +125 -39
  38. data/lib/devise/hooks/activatable.rb +7 -6
  39. data/lib/devise/hooks/csrf_cleaner.rb +5 -1
  40. data/lib/devise/hooks/forgetable.rb +2 -0
  41. data/lib/devise/hooks/lockable.rb +7 -2
  42. data/lib/devise/hooks/proxy.rb +4 -2
  43. data/lib/devise/hooks/rememberable.rb +4 -2
  44. data/lib/devise/hooks/timeoutable.rb +16 -9
  45. data/lib/devise/hooks/trackable.rb +3 -1
  46. data/lib/devise/mailers/helpers.rb +15 -12
  47. data/lib/devise/mapping.rb +8 -2
  48. data/lib/devise/models/authenticatable.rb +82 -56
  49. data/lib/devise/models/confirmable.rb +125 -42
  50. data/lib/devise/models/database_authenticatable.rb +110 -32
  51. data/lib/devise/models/lockable.rb +30 -17
  52. data/lib/devise/models/omniauthable.rb +3 -1
  53. data/lib/devise/models/recoverable.rb +62 -26
  54. data/lib/devise/models/registerable.rb +4 -0
  55. data/lib/devise/models/rememberable.rb +62 -33
  56. data/lib/devise/models/timeoutable.rb +4 -8
  57. data/lib/devise/models/trackable.rb +20 -4
  58. data/lib/devise/models/validatable.rb +16 -9
  59. data/lib/devise/models.rb +3 -1
  60. data/lib/devise/modules.rb +12 -10
  61. data/lib/devise/omniauth/config.rb +2 -0
  62. data/lib/devise/omniauth/url_helpers.rb +14 -5
  63. data/lib/devise/omniauth.rb +2 -0
  64. data/lib/devise/orm/active_record.rb +5 -1
  65. data/lib/devise/orm/mongoid.rb +6 -2
  66. data/lib/devise/parameter_filter.rb +4 -0
  67. data/lib/devise/parameter_sanitizer.rb +139 -65
  68. data/lib/devise/rails/routes.rb +147 -116
  69. data/lib/devise/rails/warden_compat.rb +3 -10
  70. data/lib/devise/rails.rb +10 -13
  71. data/lib/devise/secret_key_finder.rb +27 -0
  72. data/lib/devise/strategies/authenticatable.rb +20 -9
  73. data/lib/devise/strategies/base.rb +3 -1
  74. data/lib/devise/strategies/database_authenticatable.rb +14 -6
  75. data/lib/devise/strategies/rememberable.rb +15 -3
  76. data/lib/devise/test/controller_helpers.rb +165 -0
  77. data/lib/devise/test/integration_helpers.rb +63 -0
  78. data/lib/devise/test_helpers.rb +7 -124
  79. data/lib/devise/time_inflector.rb +4 -2
  80. data/lib/devise/token_generator.rb +3 -41
  81. data/lib/devise/version.rb +3 -1
  82. data/lib/devise.rb +111 -84
  83. data/lib/generators/active_record/devise_generator.rb +49 -12
  84. data/lib/generators/active_record/templates/migration.rb +9 -7
  85. data/lib/generators/active_record/templates/migration_existing.rb +9 -7
  86. data/lib/generators/devise/controllers_generator.rb +46 -0
  87. data/lib/generators/devise/devise_generator.rb +7 -5
  88. data/lib/generators/devise/install_generator.rb +21 -0
  89. data/lib/generators/devise/orm_helpers.rb +10 -21
  90. data/lib/generators/devise/views_generator.rb +49 -28
  91. data/lib/generators/mongoid/devise_generator.rb +21 -19
  92. data/lib/generators/templates/README +5 -12
  93. data/lib/generators/templates/controllers/README +14 -0
  94. data/lib/generators/templates/controllers/confirmations_controller.rb +30 -0
  95. data/lib/generators/templates/controllers/omniauth_callbacks_controller.rb +30 -0
  96. data/lib/generators/templates/controllers/passwords_controller.rb +34 -0
  97. data/lib/generators/templates/controllers/registrations_controller.rb +62 -0
  98. data/lib/generators/templates/controllers/sessions_controller.rb +27 -0
  99. data/lib/generators/templates/controllers/unlocks_controller.rb +30 -0
  100. data/lib/generators/templates/devise.rb +81 -36
  101. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  102. data/lib/generators/templates/markerb/email_changed.markerb +7 -0
  103. data/lib/generators/templates/markerb/password_change.markerb +3 -0
  104. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  105. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  106. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +6 -2
  107. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +9 -4
  108. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +5 -2
  109. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +14 -6
  110. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +12 -4
  111. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +11 -6
  112. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +5 -2
  113. metadata +52 -280
  114. data/.gitignore +0 -10
  115. data/.travis.yml +0 -20
  116. data/.yardopts +0 -9
  117. data/CONTRIBUTING.md +0 -14
  118. data/Gemfile +0 -31
  119. data/Gemfile.lock +0 -160
  120. data/Rakefile +0 -35
  121. data/devise.gemspec +0 -27
  122. data/devise.png +0 -0
  123. data/gemfiles/Gemfile.rails-3.2.x +0 -31
  124. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
  125. data/test/controllers/custom_strategy_test.rb +0 -62
  126. data/test/controllers/helpers_test.rb +0 -276
  127. data/test/controllers/internal_helpers_test.rb +0 -120
  128. data/test/controllers/passwords_controller_test.rb +0 -31
  129. data/test/controllers/sessions_controller_test.rb +0 -99
  130. data/test/controllers/url_helpers_test.rb +0 -59
  131. data/test/delegator_test.rb +0 -19
  132. data/test/devise_test.rb +0 -94
  133. data/test/failure_app_test.rb +0 -232
  134. data/test/generators/active_record_generator_test.rb +0 -103
  135. data/test/generators/devise_generator_test.rb +0 -39
  136. data/test/generators/install_generator_test.rb +0 -13
  137. data/test/generators/mongoid_generator_test.rb +0 -23
  138. data/test/generators/views_generator_test.rb +0 -67
  139. data/test/helpers/devise_helper_test.rb +0 -51
  140. data/test/integration/authenticatable_test.rb +0 -713
  141. data/test/integration/confirmable_test.rb +0 -284
  142. data/test/integration/database_authenticatable_test.rb +0 -84
  143. data/test/integration/http_authenticatable_test.rb +0 -105
  144. data/test/integration/lockable_test.rb +0 -239
  145. data/test/integration/omniauthable_test.rb +0 -133
  146. data/test/integration/recoverable_test.rb +0 -334
  147. data/test/integration/registerable_test.rb +0 -349
  148. data/test/integration/rememberable_test.rb +0 -167
  149. data/test/integration/timeoutable_test.rb +0 -183
  150. data/test/integration/trackable_test.rb +0 -92
  151. data/test/mailers/confirmation_instructions_test.rb +0 -115
  152. data/test/mailers/reset_password_instructions_test.rb +0 -96
  153. data/test/mailers/unlock_instructions_test.rb +0 -91
  154. data/test/mapping_test.rb +0 -127
  155. data/test/models/authenticatable_test.rb +0 -13
  156. data/test/models/confirmable_test.rb +0 -454
  157. data/test/models/database_authenticatable_test.rb +0 -249
  158. data/test/models/lockable_test.rb +0 -298
  159. data/test/models/omniauthable_test.rb +0 -7
  160. data/test/models/recoverable_test.rb +0 -184
  161. data/test/models/registerable_test.rb +0 -7
  162. data/test/models/rememberable_test.rb +0 -183
  163. data/test/models/serializable_test.rb +0 -49
  164. data/test/models/timeoutable_test.rb +0 -51
  165. data/test/models/trackable_test.rb +0 -13
  166. data/test/models/validatable_test.rb +0 -127
  167. data/test/models_test.rb +0 -144
  168. data/test/omniauth/config_test.rb +0 -57
  169. data/test/omniauth/url_helpers_test.rb +0 -54
  170. data/test/orm/active_record.rb +0 -10
  171. data/test/orm/mongoid.rb +0 -13
  172. data/test/parameter_sanitizer_test.rb +0 -81
  173. data/test/rails_app/Rakefile +0 -6
  174. data/test/rails_app/app/active_record/admin.rb +0 -6
  175. data/test/rails_app/app/active_record/shim.rb +0 -2
  176. data/test/rails_app/app/active_record/user.rb +0 -6
  177. data/test/rails_app/app/controllers/admins/sessions_controller.rb +0 -6
  178. data/test/rails_app/app/controllers/admins_controller.rb +0 -11
  179. data/test/rails_app/app/controllers/application_controller.rb +0 -9
  180. data/test/rails_app/app/controllers/home_controller.rb +0 -25
  181. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +0 -2
  182. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +0 -2
  183. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +0 -14
  184. data/test/rails_app/app/controllers/users_controller.rb +0 -31
  185. data/test/rails_app/app/helpers/application_helper.rb +0 -3
  186. data/test/rails_app/app/mailers/users/mailer.rb +0 -12
  187. data/test/rails_app/app/mongoid/admin.rb +0 -29
  188. data/test/rails_app/app/mongoid/shim.rb +0 -23
  189. data/test/rails_app/app/mongoid/user.rb +0 -39
  190. data/test/rails_app/app/views/admins/index.html.erb +0 -1
  191. data/test/rails_app/app/views/admins/sessions/new.html.erb +0 -2
  192. data/test/rails_app/app/views/home/admin_dashboard.html.erb +0 -1
  193. data/test/rails_app/app/views/home/index.html.erb +0 -1
  194. data/test/rails_app/app/views/home/join.html.erb +0 -1
  195. data/test/rails_app/app/views/home/private.html.erb +0 -1
  196. data/test/rails_app/app/views/home/user_dashboard.html.erb +0 -1
  197. data/test/rails_app/app/views/layouts/application.html.erb +0 -24
  198. data/test/rails_app/app/views/users/edit_form.html.erb +0 -1
  199. data/test/rails_app/app/views/users/index.html.erb +0 -1
  200. data/test/rails_app/app/views/users/mailer/confirmation_instructions.erb +0 -1
  201. data/test/rails_app/app/views/users/sessions/new.html.erb +0 -1
  202. data/test/rails_app/bin/bundle +0 -3
  203. data/test/rails_app/bin/rails +0 -4
  204. data/test/rails_app/bin/rake +0 -4
  205. data/test/rails_app/config/application.rb +0 -40
  206. data/test/rails_app/config/boot.rb +0 -14
  207. data/test/rails_app/config/database.yml +0 -18
  208. data/test/rails_app/config/environment.rb +0 -5
  209. data/test/rails_app/config/environments/development.rb +0 -30
  210. data/test/rails_app/config/environments/production.rb +0 -80
  211. data/test/rails_app/config/environments/test.rb +0 -36
  212. data/test/rails_app/config/initializers/backtrace_silencers.rb +0 -7
  213. data/test/rails_app/config/initializers/devise.rb +0 -181
  214. data/test/rails_app/config/initializers/inflections.rb +0 -2
  215. data/test/rails_app/config/initializers/secret_token.rb +0 -8
  216. data/test/rails_app/config/initializers/session_store.rb +0 -1
  217. data/test/rails_app/config/routes.rb +0 -104
  218. data/test/rails_app/config.ru +0 -4
  219. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +0 -71
  220. data/test/rails_app/db/schema.rb +0 -55
  221. data/test/rails_app/lib/shared_admin.rb +0 -17
  222. data/test/rails_app/lib/shared_user.rb +0 -29
  223. data/test/rails_app/public/404.html +0 -26
  224. data/test/rails_app/public/422.html +0 -26
  225. data/test/rails_app/public/500.html +0 -26
  226. data/test/rails_app/public/favicon.ico +0 -0
  227. data/test/routes_test.rb +0 -250
  228. data/test/support/assertions.rb +0 -40
  229. data/test/support/helpers.rb +0 -70
  230. data/test/support/integration.rb +0 -92
  231. data/test/support/locale/en.yml +0 -8
  232. data/test/support/webrat/integrations/rails.rb +0 -24
  233. data/test/test_helper.rb +0 -27
  234. data/test/test_helpers_test.rb +0 -173
  235. data/test/test_models.rb +0 -33
@@ -1,91 +0,0 @@
1
- require 'test_helper'
2
-
3
- class UnlockInstructionsTest < ActionMailer::TestCase
4
-
5
- def setup
6
- setup_mailer
7
- Devise.mailer = 'Devise::Mailer'
8
- Devise.mailer_sender = 'test@example.com'
9
- end
10
-
11
- def teardown
12
- Devise.mailer = 'Devise::Mailer'
13
- Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'
14
- end
15
-
16
- def user
17
- @user ||= begin
18
- user = create_user
19
- user.lock_access!
20
- user
21
- end
22
- end
23
-
24
- def mail
25
- @mail ||= begin
26
- user
27
- ActionMailer::Base.deliveries.last
28
- end
29
- end
30
-
31
- test 'email sent after locking the user' do
32
- assert_not_nil mail
33
- end
34
-
35
- test 'content type should be set to html' do
36
- assert mail.content_type.include?('text/html')
37
- end
38
-
39
- test 'send unlock instructions to the user email' do
40
- assert_equal [user.email], mail.to
41
- end
42
-
43
- test 'setup sender from configuration' do
44
- assert_equal ['test@example.com'], mail.from
45
- end
46
-
47
- test 'setup sender from custom mailer defaults' do
48
- Devise.mailer = 'Users::Mailer'
49
- assert_equal ['custom@example.com'], mail.from
50
- end
51
-
52
- test 'setup sender from custom mailer defaults with proc' do
53
- Devise.mailer = 'Users::FromProcMailer'
54
- assert_equal ['custom@example.com'], mail.from
55
- end
56
-
57
- test 'custom mailer renders parent mailer template' do
58
- Devise.mailer = 'Users::Mailer'
59
- assert_not_blank mail.body.encoded
60
- end
61
-
62
- test 'setup reply to as copy from sender' do
63
- assert_equal ['test@example.com'], mail.reply_to
64
- end
65
-
66
- test 'setup subject from I18n' do
67
- store_translations :en, :devise => { :mailer => { :unlock_instructions => { :subject => 'Yo unlock instructions' } } } do
68
- assert_equal 'Yo unlock instructions', mail.subject
69
- end
70
- end
71
-
72
- test 'subject namespaced by model' do
73
- store_translations :en, :devise => { :mailer => { :unlock_instructions => { :user_subject => 'User Unlock Instructions' } } } do
74
- assert_equal 'User Unlock Instructions', mail.subject
75
- end
76
- end
77
-
78
- test 'body should have user info' do
79
- assert_match user.email, mail.body.encoded
80
- end
81
-
82
- test 'body should have link to unlock the account' do
83
- host = ActionMailer::Base.default_url_options[:host]
84
-
85
- if mail.body.encoded =~ %r{<a href=\"http://#{host}/users/unlock\?unlock_token=([^"]+)">}
86
- assert_equal Devise.token_generator.digest(user.class, :unlock_token, $1), user.unlock_token
87
- else
88
- flunk "expected unlock url regex to match"
89
- end
90
- end
91
- end
data/test/mapping_test.rb DELETED
@@ -1,127 +0,0 @@
1
- require 'test_helper'
2
-
3
- class FakeRequest < Struct.new(:path_info, :params)
4
- end
5
-
6
- class MappingTest < ActiveSupport::TestCase
7
- def fake_request(path, params={})
8
- FakeRequest.new(path, params)
9
- end
10
-
11
- test 'store options' do
12
- mapping = Devise.mappings[:user]
13
- assert_equal User, mapping.to
14
- assert_equal User.devise_modules, mapping.modules
15
- assert_equal "users", mapping.scoped_path
16
- assert_equal :user, mapping.singular
17
- assert_equal "users", mapping.path
18
- assert_equal "/users", mapping.fullpath
19
- end
20
-
21
- test 'store options with namespace' do
22
- mapping = Devise.mappings[:publisher_account]
23
- assert_equal Admin, mapping.to
24
- assert_equal "publisher/accounts", mapping.scoped_path
25
- assert_equal :publisher_account, mapping.singular
26
- assert_equal "accounts", mapping.path
27
- assert_equal "/publisher/accounts", mapping.fullpath
28
- end
29
-
30
- test 'allows path to be given' do
31
- assert_equal "admin_area", Devise.mappings[:admin].path
32
- end
33
-
34
- test 'allows to skip all routes' do
35
- assert_equal [], Devise.mappings[:skip_admin].used_routes
36
- end
37
-
38
- test 'sign_out_via defaults to :get' do
39
- assert_equal :get, Devise.mappings[:user].sign_out_via
40
- end
41
-
42
- test 'allows custom sign_out_via to be given' do
43
- assert_equal :delete, Devise.mappings[:sign_out_via_delete].sign_out_via
44
- assert_equal :post, Devise.mappings[:sign_out_via_post].sign_out_via
45
- assert_equal [:delete, :post], Devise.mappings[:sign_out_via_delete_or_post].sign_out_via
46
- end
47
-
48
- test 'allows custom singular to be given' do
49
- assert_equal "accounts", Devise.mappings[:manager].path
50
- end
51
-
52
- test 'has strategies depending on the model declaration' do
53
- assert_equal [:rememberable, :database_authenticatable], Devise.mappings[:user].strategies
54
- assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies
55
- end
56
-
57
- test 'has no input strategies depending on the model declaration' do
58
- assert_equal [:rememberable], Devise.mappings[:user].no_input_strategies
59
- assert_equal [], Devise.mappings[:admin].no_input_strategies
60
- end
61
-
62
- test 'find scope for a given object' do
63
- assert_equal :user, Devise::Mapping.find_scope!(User)
64
- assert_equal :user, Devise::Mapping.find_scope!(:user)
65
- assert_equal :user, Devise::Mapping.find_scope!(User.new)
66
- end
67
-
68
- test 'find scope works with single table inheritance' do
69
- assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))
70
- assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
71
- end
72
-
73
- test 'find scope raises an error if cannot be found' do
74
- assert_raise RuntimeError do
75
- Devise::Mapping.find_scope!(String)
76
- end
77
- end
78
-
79
- test 'return default path names' do
80
- mapping = Devise.mappings[:user]
81
- assert_equal 'sign_in', mapping.path_names[:sign_in]
82
- assert_equal 'sign_out', mapping.path_names[:sign_out]
83
- assert_equal 'password', mapping.path_names[:password]
84
- assert_equal 'confirmation', mapping.path_names[:confirmation]
85
- assert_equal 'sign_up', mapping.path_names[:sign_up]
86
- assert_equal 'unlock', mapping.path_names[:unlock]
87
- end
88
-
89
- test 'allow custom path names to be given' do
90
- mapping = Devise.mappings[:manager]
91
- assert_equal 'login', mapping.path_names[:sign_in]
92
- assert_equal 'logout', mapping.path_names[:sign_out]
93
- assert_equal 'secret', mapping.path_names[:password]
94
- assert_equal 'verification', mapping.path_names[:confirmation]
95
- assert_equal 'register', mapping.path_names[:sign_up]
96
- assert_equal 'unblock', mapping.path_names[:unlock]
97
- end
98
-
99
- test 'magic predicates' do
100
- mapping = Devise.mappings[:user]
101
- assert mapping.authenticatable?
102
- assert mapping.confirmable?
103
- assert mapping.recoverable?
104
- assert mapping.rememberable?
105
- assert mapping.registerable?
106
-
107
- mapping = Devise.mappings[:admin]
108
- assert mapping.authenticatable?
109
- assert mapping.recoverable?
110
- assert mapping.lockable?
111
- assert_not mapping.omniauthable?
112
- end
113
-
114
- test 'find mapping by path' do
115
- assert_raise RuntimeError do
116
- Devise::Mapping.find_by_path!('/accounts/facebook/callback')
117
- end
118
-
119
- assert_nothing_raised do
120
- Devise::Mapping.find_by_path!('/:locale/accounts/login')
121
- end
122
-
123
- assert_nothing_raised do
124
- Devise::Mapping.find_by_path!('/accounts/facebook/callback', :path)
125
- end
126
- end
127
- end
@@ -1,13 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AuthenticatableTest < ActiveSupport::TestCase
4
- test 'required_fields should be an empty array' do
5
- assert_equal Devise::Models::Validatable.required_fields(User), []
6
- end
7
-
8
- test 'find_first_by_auth_conditions allows custom filtering parameters' do
9
- user = User.create!(:email => "example@example.com", :password => "123456")
10
- assert_equal User.find_first_by_auth_conditions({ :email => "example@example.com" }), user
11
- assert_nil User.find_first_by_auth_conditions({ :email => "example@example.com" }, :id => user.id.to_s.next)
12
- end
13
- end
@@ -1,454 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ConfirmableTest < ActiveSupport::TestCase
4
-
5
- def setup
6
- setup_mailer
7
- end
8
-
9
- test 'should generate confirmation token after creating a record' do
10
- assert_nil new_user.confirmation_token
11
- assert_not_nil create_user.confirmation_token
12
- end
13
-
14
- test 'should never generate the same confirmation token for different users' do
15
- confirmation_tokens = []
16
- 3.times do
17
- token = create_user.confirmation_token
18
- assert !confirmation_tokens.include?(token)
19
- confirmation_tokens << token
20
- end
21
- end
22
-
23
- test 'should confirm a user by updating confirmed at' do
24
- user = create_user
25
- assert_nil user.confirmed_at
26
- assert user.confirm!
27
- assert_not_nil user.confirmed_at
28
- end
29
-
30
- test 'should clear confirmation token while confirming a user' do
31
- user = create_user
32
- assert_present user.confirmation_token
33
- user.confirm!
34
- assert_nil user.confirmation_token
35
- end
36
-
37
- test 'should verify whether a user is confirmed or not' do
38
- assert_not new_user.confirmed?
39
- user = create_user
40
- assert_not user.confirmed?
41
- user.confirm!
42
- assert user.confirmed?
43
- end
44
-
45
- test 'should not confirm a user already confirmed' do
46
- user = create_user
47
- assert user.confirm!
48
- assert_blank user.errors[:email]
49
-
50
- assert_not user.confirm!
51
- assert_equal "was already confirmed, please try signing in", user.errors[:email].join
52
- end
53
-
54
- test 'should find and confirm a user automatically based on the raw token' do
55
- user = create_user
56
- raw = user.raw_confirmation_token
57
- confirmed_user = User.confirm_by_token(raw)
58
- assert_equal confirmed_user, user
59
- assert user.reload.confirmed?
60
- end
61
-
62
- test 'should return a new record with errors when a invalid token is given' do
63
- confirmed_user = User.confirm_by_token('invalid_confirmation_token')
64
- assert_not confirmed_user.persisted?
65
- assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
66
- end
67
-
68
- test 'should return a new record with errors when a blank token is given' do
69
- confirmed_user = User.confirm_by_token('')
70
- assert_not confirmed_user.persisted?
71
- assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
72
- end
73
-
74
- test 'should generate errors for a user email if user is already confirmed' do
75
- user = create_user
76
- user.confirmed_at = Time.now
77
- user.save
78
- confirmed_user = User.confirm_by_token(user.raw_confirmation_token)
79
- assert confirmed_user.confirmed?
80
- assert_equal "was already confirmed, please try signing in", confirmed_user.errors[:email].join
81
- end
82
-
83
- test 'should send confirmation instructions by email' do
84
- assert_email_sent "mynewuser@example.com" do
85
- create_user :email => "mynewuser@example.com"
86
- end
87
- end
88
-
89
- test 'should not send confirmation when trying to save an invalid user' do
90
- assert_email_not_sent do
91
- user = new_user
92
- user.stubs(:valid?).returns(false)
93
- user.save
94
- end
95
- end
96
-
97
- test 'should not generate a new token neither send e-mail if skip_confirmation! is invoked' do
98
- user = new_user
99
- user.skip_confirmation!
100
-
101
- assert_email_not_sent do
102
- user.save!
103
- assert_nil user.confirmation_token
104
- assert_not_nil user.confirmed_at
105
- end
106
- end
107
-
108
- test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do
109
- user = new_user
110
- user.skip_confirmation_notification!
111
-
112
- assert_email_not_sent do
113
- user.save!
114
- assert !user.confirmed?
115
- end
116
- end
117
-
118
- test 'should not send confirmation when no email is provided' do
119
- assert_email_not_sent do
120
- user = new_user
121
- user.email = ''
122
- user.save(:validate => false)
123
- end
124
- end
125
-
126
- test 'should find a user to send confirmation instructions' do
127
- user = create_user
128
- confirmation_user = User.send_confirmation_instructions(:email => user.email)
129
- assert_equal confirmation_user, user
130
- end
131
-
132
- test 'should return a new user if no email was found' do
133
- confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
134
- assert_not confirmation_user.persisted?
135
- end
136
-
137
- test 'should add error to new user email if no email was found' do
138
- confirmation_user = User.send_confirmation_instructions(:email => "invalid@example.com")
139
- assert confirmation_user.errors[:email]
140
- assert_equal "not found", confirmation_user.errors[:email].join
141
- end
142
-
143
- test 'should send email instructions for the user confirm its email' do
144
- user = create_user
145
- assert_email_sent user.email do
146
- User.send_confirmation_instructions(:email => user.email)
147
- end
148
- end
149
-
150
- test 'should always have confirmation token when email is sent' do
151
- user = new_user
152
- user.instance_eval { def confirmation_required?; false end }
153
- user.save
154
- user.send_confirmation_instructions
155
- assert_not_nil user.reload.confirmation_token
156
- end
157
-
158
- test 'should not resend email instructions if the user change his email' do
159
- user = create_user
160
- user.email = 'new_test@example.com'
161
- assert_email_not_sent do
162
- user.save!
163
- end
164
- end
165
-
166
- test 'should not reset confirmation status or token when updating email' do
167
- user = create_user
168
- user.confirm!
169
- user.email = 'new_test@example.com'
170
- user.save!
171
-
172
- user.reload
173
- assert user.confirmed?
174
- assert_nil user.confirmation_token
175
- end
176
-
177
- test 'should not be able to send instructions if the user is already confirmed' do
178
- user = create_user
179
- user.confirm!
180
- assert_not user.resend_confirmation_instructions
181
- assert user.confirmed?
182
- assert_equal 'was already confirmed, please try signing in', user.errors[:email].join
183
- end
184
-
185
- test 'confirm time should fallback to devise confirm in default configuration' do
186
- swap Devise, :allow_unconfirmed_access_for => 1.day do
187
- user = new_user
188
- user.confirmation_sent_at = 2.days.ago
189
- assert_not user.active_for_authentication?
190
-
191
- Devise.allow_unconfirmed_access_for = 3.days
192
- assert user.active_for_authentication?
193
- end
194
- end
195
-
196
- test 'should be active when confirmation sent at is not overpast' do
197
- swap Devise, :allow_unconfirmed_access_for => 5.days do
198
- Devise.allow_unconfirmed_access_for = 5.days
199
- user = create_user
200
-
201
- user.confirmation_sent_at = 4.days.ago
202
- assert user.active_for_authentication?
203
-
204
- user.confirmation_sent_at = 5.days.ago
205
- assert_not user.active_for_authentication?
206
- end
207
- end
208
-
209
- test 'should be active when already confirmed' do
210
- user = create_user
211
- assert_not user.confirmed?
212
- assert_not user.active_for_authentication?
213
-
214
- user.confirm!
215
- assert user.confirmed?
216
- assert user.active_for_authentication?
217
- end
218
-
219
- test 'should not be active when confirm in is zero' do
220
- Devise.allow_unconfirmed_access_for = 0.days
221
- user = create_user
222
- user.confirmation_sent_at = Date.today
223
- assert_not user.active_for_authentication?
224
- end
225
-
226
- test 'should be active when we set allow_unconfirmed_access_for to nil' do
227
- Devise.allow_unconfirmed_access_for = nil
228
- user = create_user
229
- user.confirmation_sent_at = Date.today
230
- assert user.active_for_authentication?
231
- end
232
-
233
- test 'should not be active without confirmation' do
234
- user = create_user
235
- user.confirmation_sent_at = nil
236
- user.save
237
- assert_not user.reload.active_for_authentication?
238
- end
239
-
240
- test 'should be active without confirmation when confirmation is not required' do
241
- user = create_user
242
- user.instance_eval { def confirmation_required?; false end }
243
- user.confirmation_sent_at = nil
244
- user.save
245
- assert user.reload.active_for_authentication?
246
- end
247
-
248
- test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do
249
- swap Devise, :authentication_keys => [:username, :email] do
250
- user = create_user
251
- confirm_user = User.send_confirmation_instructions(:email => user.email, :username => user.username)
252
- assert_equal confirm_user, user
253
- end
254
- end
255
-
256
- test 'should require all confirmation_keys' do
257
- swap Devise, :confirmation_keys => [:username, :email] do
258
- user = create_user
259
- confirm_user = User.send_confirmation_instructions(:email => user.email)
260
- assert_not confirm_user.persisted?
261
- assert_equal "can't be blank", confirm_user.errors[:username].join
262
- end
263
- end
264
-
265
- def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)
266
- user = create_user
267
- user.update_attribute(:confirmation_sent_at, confirmation_sent_at)
268
- confirmed_user = User.confirm_by_token(user.raw_confirmation_token)
269
- assert_equal confirmed_user, user
270
- user.reload.confirmed?
271
- end
272
-
273
- test 'should accept confirmation email token even after 5 years when no expiration is set' do
274
- assert confirm_user_by_token_with_confirmation_sent_at(5.years.ago)
275
- end
276
-
277
- test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do
278
- swap Devise, :confirm_within => 3.days do
279
- assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago)
280
- end
281
- end
282
-
283
- test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do
284
- swap Devise, :confirm_within => 3.days do
285
- assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)
286
- end
287
- end
288
-
289
- test 'always generate a new token on resend' do
290
- user = create_user
291
- old = user.confirmation_token
292
- user = User.find(user.id)
293
- user.resend_confirmation_instructions
294
- assert_not_equal user.confirmation_token, old
295
- end
296
-
297
- test 'should call after_confirmation if confirmed' do
298
- user = create_user
299
- user.define_singleton_method :after_confirmation do
300
- self.username = self.username.to_s + 'updated'
301
- end
302
- old = user.username
303
- assert user.confirm!
304
- assert_not_equal user.username, old
305
- end
306
-
307
- test 'should not call after_confirmation if not confirmed' do
308
- user = create_user
309
- assert user.confirm!
310
- user.define_singleton_method :after_confirmation do
311
- self.username = self.username.to_s + 'updated'
312
- end
313
- old = user.username
314
- assert_not user.confirm!
315
- assert_equal user.username, old
316
- end
317
- end
318
-
319
- class ReconfirmableTest < ActiveSupport::TestCase
320
- test 'should not worry about validations on confirm even with reconfirmable' do
321
- admin = create_admin
322
- admin.reset_password_token = "a"
323
- assert admin.confirm!
324
- end
325
-
326
- test 'should generate confirmation token after changing email' do
327
- admin = create_admin
328
- assert admin.confirm!
329
- assert_nil admin.confirmation_token
330
- assert admin.update_attributes(:email => 'new_test@example.com')
331
- assert_not_nil admin.confirmation_token
332
- end
333
-
334
- test 'should not generate confirmation token if skipping reconfirmation after changing email' do
335
- admin = create_admin
336
- assert admin.confirm!
337
- admin.skip_reconfirmation!
338
- assert admin.update_attributes(:email => 'new_test@example.com')
339
- assert_nil admin.confirmation_token
340
- end
341
-
342
- test 'should skip sending reconfirmation email when email is changed and skip_confirmation_notification! is invoked' do
343
- admin = create_admin
344
- admin.skip_confirmation_notification!
345
-
346
- assert_email_not_sent do
347
- admin.update_attributes(:email => 'new_test@example.com')
348
- end
349
- end
350
-
351
- test 'should regenerate confirmation token after changing email' do
352
- admin = create_admin
353
- assert admin.confirm!
354
- assert admin.update_attributes(:email => 'old_test@example.com')
355
- token = admin.confirmation_token
356
- assert admin.update_attributes(:email => 'new_test@example.com')
357
- assert_not_equal token, admin.confirmation_token
358
- end
359
-
360
- test 'should send confirmation instructions by email after changing email' do
361
- admin = create_admin
362
- assert admin.confirm!
363
- assert_email_sent "new_test@example.com" do
364
- assert admin.update_attributes(:email => 'new_test@example.com')
365
- end
366
- assert_match "new_test@example.com", ActionMailer::Base.deliveries.last.body.encoded
367
- end
368
-
369
- test 'should not send confirmation by email after changing password' do
370
- admin = create_admin
371
- assert admin.confirm!
372
- assert_email_not_sent do
373
- assert admin.update_attributes(:password => 'newpass', :password_confirmation => 'newpass')
374
- end
375
- end
376
-
377
- test 'should not send confirmation by email after changing to a blank email' do
378
- admin = create_admin
379
- assert admin.confirm!
380
- assert_email_not_sent do
381
- admin.email = ''
382
- admin.save(:validate => false)
383
- end
384
- end
385
-
386
- test 'should stay confirmed when email is changed' do
387
- admin = create_admin
388
- assert admin.confirm!
389
- assert admin.update_attributes(:email => 'new_test@example.com')
390
- assert admin.confirmed?
391
- end
392
-
393
- test 'should update email only when it is confirmed' do
394
- admin = create_admin
395
- assert admin.confirm!
396
- assert admin.update_attributes(:email => 'new_test@example.com')
397
- assert_not_equal 'new_test@example.com', admin.email
398
- assert admin.confirm!
399
- assert_equal 'new_test@example.com', admin.email
400
- end
401
-
402
- test 'should not allow admin to get past confirmation email by resubmitting their new address' do
403
- admin = create_admin
404
- assert admin.confirm!
405
- assert admin.update_attributes(:email => 'new_test@example.com')
406
- assert_not_equal 'new_test@example.com', admin.email
407
- assert admin.update_attributes(:email => 'new_test@example.com')
408
- assert_not_equal 'new_test@example.com', admin.email
409
- end
410
-
411
- test 'should find a admin by send confirmation instructions with unconfirmed_email' do
412
- admin = create_admin
413
- assert admin.confirm!
414
- assert admin.update_attributes(:email => 'new_test@example.com')
415
- confirmation_admin = Admin.send_confirmation_instructions(:email => admin.unconfirmed_email)
416
- assert_equal confirmation_admin, admin
417
- end
418
-
419
- test 'should return a new admin if no email or unconfirmed_email was found' do
420
- confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
421
- assert_not confirmation_admin.persisted?
422
- end
423
-
424
- test 'should add error to new admin email if no email or unconfirmed_email was found' do
425
- confirmation_admin = Admin.send_confirmation_instructions(:email => "invalid@email.com")
426
- assert confirmation_admin.errors[:email]
427
- assert_equal "not found", confirmation_admin.errors[:email].join
428
- end
429
-
430
- test 'should find admin with email in unconfirmed_emails' do
431
- admin = create_admin
432
- admin.unconfirmed_email = "new_test@email.com"
433
- assert admin.save
434
- admin = Admin.find_by_unconfirmed_email_with_errors(:email => "new_test@email.com")
435
- assert admin.persisted?
436
- end
437
-
438
- test 'required_fields should contain the fields that Devise uses' do
439
- assert_same_content Devise::Models::Confirmable.required_fields(User), [
440
- :confirmation_sent_at,
441
- :confirmation_token,
442
- :confirmed_at
443
- ]
444
- end
445
-
446
- test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do
447
- assert_same_content Devise::Models::Confirmable.required_fields(Admin), [
448
- :confirmation_sent_at,
449
- :confirmation_token,
450
- :confirmed_at,
451
- :unconfirmed_email
452
- ]
453
- end
454
- end