devise_ennder 1.0.1.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (255) hide show
  1. data/CHANGELOG.rdoc +397 -0
  2. data/INSTALL +94 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +272 -0
  5. data/Rakefile +53 -0
  6. data/TODO +2 -0
  7. data/app/controllers/confirmations_controller.rb +33 -0
  8. data/app/controllers/passwords_controller.rb +41 -0
  9. data/app/controllers/registrations_controller.rb +62 -0
  10. data/app/controllers/sessions_controller.rb +42 -0
  11. data/app/controllers/unlocks_controller.rb +41 -0
  12. data/app/models/devise_mailer.rb +68 -0
  13. data/app/models/user.rb +9 -0
  14. data/app/views/confirmations/new.html.erb +14 -0
  15. data/app/views/devise_mailer/confirmation_instructions.html.erb +6 -0
  16. data/app/views/devise_mailer/reset_password_instructions.html.erb +8 -0
  17. data/app/views/devise_mailer/unlock_instructions.html.erb +7 -0
  18. data/app/views/passwords/edit.html.erb +16 -0
  19. data/app/views/passwords/new.html.erb +12 -0
  20. data/app/views/registrations/edit.html.erb +25 -0
  21. data/app/views/registrations/new.html.erb +17 -0
  22. data/app/views/sessions/new.html.erb +17 -0
  23. data/app/views/shared/_devise_links.erb +19 -0
  24. data/app/views/shared/_user_nav.html.erb +15 -0
  25. data/app/views/unlocks/new.html.erb +12 -0
  26. data/config/locales/devise.en.yml +62 -0
  27. data/config/locales/devise.fr.yml +60 -0
  28. data/config/locales/en.yml +6 -0
  29. data/config/locales/fr.yml +18 -0
  30. data/config/routes.rb +4 -0
  31. data/db/migrate/20100506013336_devise_create_users.rb +23 -0
  32. data/lib/devise/controllers/helpers.rb +212 -0
  33. data/lib/devise/controllers/internal_helpers.rb +129 -0
  34. data/lib/devise/controllers/url_helpers.rb +41 -0
  35. data/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  36. data/lib/devise/encryptors/base.rb +20 -0
  37. data/lib/devise/encryptors/bcrypt.rb +21 -0
  38. data/lib/devise/encryptors/clearance_sha1.rb +19 -0
  39. data/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  40. data/lib/devise/encryptors/sha1.rb +27 -0
  41. data/lib/devise/encryptors/sha512.rb +27 -0
  42. data/lib/devise/failure_app.rb +70 -0
  43. data/lib/devise/hooks/activatable.rb +15 -0
  44. data/lib/devise/hooks/rememberable.rb +33 -0
  45. data/lib/devise/hooks/timeoutable.rb +18 -0
  46. data/lib/devise/hooks/trackable.rb +18 -0
  47. data/lib/devise/locales/en.yml +35 -0
  48. data/lib/devise/mapping.rb +130 -0
  49. data/lib/devise/models/activatable.rb +16 -0
  50. data/lib/devise/models/confirmable.rb +167 -0
  51. data/lib/devise/models/database_authenticatable.rb +144 -0
  52. data/lib/devise/models/http_authenticatable.rb +23 -0
  53. data/lib/devise/models/lockable.rb +150 -0
  54. data/lib/devise/models/recoverable.rb +80 -0
  55. data/lib/devise/models/registerable.rb +8 -0
  56. data/lib/devise/models/rememberable.rb +92 -0
  57. data/lib/devise/models/timeoutable.rb +28 -0
  58. data/lib/devise/models/token_authenticatable.rb +89 -0
  59. data/lib/devise/models/trackable.rb +16 -0
  60. data/lib/devise/models/validatable.rb +39 -0
  61. data/lib/devise/models.rb +117 -0
  62. data/lib/devise/orm/active_record.rb +41 -0
  63. data/lib/devise/orm/data_mapper.rb +83 -0
  64. data/lib/devise/orm/mongo_mapper.rb +52 -0
  65. data/lib/devise/rails/routes.rb +133 -0
  66. data/lib/devise/rails/warden_compat.rb +60 -0
  67. data/lib/devise/rails.rb +14 -0
  68. data/lib/devise/schema.rb +73 -0
  69. data/lib/devise/strategies/base.rb +16 -0
  70. data/lib/devise/strategies/database_authenticatable.rb +36 -0
  71. data/lib/devise/strategies/http_authenticatable.rb +59 -0
  72. data/lib/devise/strategies/rememberable.rb +37 -0
  73. data/lib/devise/strategies/token_authenticatable.rb +37 -0
  74. data/lib/devise/test_helpers.rb +90 -0
  75. data/lib/devise/version.rb +3 -0
  76. data/lib/devise.rb +269 -0
  77. data/lib/devise_ennder.rb +3 -0
  78. data/lib/tasks/devise_ennder_tasks.rake +11 -0
  79. data/test/controllers/helpers_test.rb +184 -0
  80. data/test/controllers/internal_helpers_test.rb +55 -0
  81. data/test/controllers/url_helpers_test.rb +47 -0
  82. data/test/devise_test.rb +74 -0
  83. data/test/encryptors_test.rb +31 -0
  84. data/test/failure_app_test.rb +44 -0
  85. data/test/integration/authenticatable_test.rb +332 -0
  86. data/test/integration/confirmable_test.rb +97 -0
  87. data/test/integration/http_authenticatable_test.rb +52 -0
  88. data/test/integration/lockable_test.rb +102 -0
  89. data/test/integration/rack_middleware_test.rb +47 -0
  90. data/test/integration/recoverable_test.rb +141 -0
  91. data/test/integration/registerable_test.rb +144 -0
  92. data/test/integration/rememberable_test.rb +72 -0
  93. data/test/integration/timeoutable_test.rb +68 -0
  94. data/test/integration/token_authenticatable_test.rb +55 -0
  95. data/test/integration/trackable_test.rb +64 -0
  96. data/test/mailers/confirmation_instructions_test.rb +86 -0
  97. data/test/mailers/reset_password_instructions_test.rb +68 -0
  98. data/test/mailers/unlock_instructions_test.rb +62 -0
  99. data/test/mapping_test.rb +158 -0
  100. data/test/models/authenticatable_test.rb +180 -0
  101. data/test/models/confirmable_test.rb +228 -0
  102. data/test/models/lockable_test.rb +202 -0
  103. data/test/models/recoverable_test.rb +138 -0
  104. data/test/models/rememberable_test.rb +135 -0
  105. data/test/models/timeoutable_test.rb +28 -0
  106. data/test/models/token_authenticatable_test.rb +51 -0
  107. data/test/models/trackable_test.rb +5 -0
  108. data/test/models/validatable_test.rb +106 -0
  109. data/test/models_test.rb +70 -0
  110. data/test/orm/active_record.rb +31 -0
  111. data/test/orm/mongo_mapper.rb +20 -0
  112. data/test/rails_app/app/active_record/admin.rb +7 -0
  113. data/test/rails_app/app/active_record/user.rb +7 -0
  114. data/test/rails_app/app/controllers/admins_controller.rb +6 -0
  115. data/test/rails_app/app/controllers/application_controller.rb +12 -0
  116. data/test/rails_app/app/controllers/home_controller.rb +4 -0
  117. data/test/rails_app/app/controllers/users_controller.rb +16 -0
  118. data/test/rails_app/app/helpers/application_helper.rb +3 -0
  119. data/test/rails_app/app/mongo_mapper/admin.rb +13 -0
  120. data/test/rails_app/app/mongo_mapper/user.rb +14 -0
  121. data/test/rails_app/config/boot.rb +110 -0
  122. data/test/rails_app/config/environment.rb +42 -0
  123. data/test/rails_app/config/environments/development.rb +17 -0
  124. data/test/rails_app/config/environments/production.rb +28 -0
  125. data/test/rails_app/config/environments/test.rb +28 -0
  126. data/test/rails_app/config/initializers/devise.rb +82 -0
  127. data/test/rails_app/config/initializers/inflections.rb +2 -0
  128. data/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  129. data/test/rails_app/config/initializers/session_store.rb +15 -0
  130. data/test/rails_app/config/routes.rb +25 -0
  131. data/test/rails_app/vendor/plugins/devise/app/controllers/confirmations_controller.rb +33 -0
  132. data/test/rails_app/vendor/plugins/devise/app/controllers/passwords_controller.rb +41 -0
  133. data/test/rails_app/vendor/plugins/devise/app/controllers/registrations_controller.rb +53 -0
  134. data/test/rails_app/vendor/plugins/devise/app/controllers/sessions_controller.rb +42 -0
  135. data/test/rails_app/vendor/plugins/devise/app/controllers/unlocks_controller.rb +41 -0
  136. data/test/rails_app/vendor/plugins/devise/app/models/devise_mailer.rb +68 -0
  137. data/test/rails_app/vendor/plugins/devise/generators/devise/devise_generator.rb +15 -0
  138. data/test/rails_app/vendor/plugins/devise/generators/devise/lib/route_devise.rb +32 -0
  139. data/test/rails_app/vendor/plugins/devise/generators/devise/templates/migration.rb +23 -0
  140. data/test/rails_app/vendor/plugins/devise/generators/devise/templates/model.rb +9 -0
  141. data/test/rails_app/vendor/plugins/devise/generators/devise_install/devise_install_generator.rb +15 -0
  142. data/test/rails_app/vendor/plugins/devise/generators/devise_install/templates/devise.rb +105 -0
  143. data/test/rails_app/vendor/plugins/devise/generators/devise_views/devise_views_generator.rb +21 -0
  144. data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/helpers.rb +212 -0
  145. data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/internal_helpers.rb +129 -0
  146. data/test/rails_app/vendor/plugins/devise/lib/devise/controllers/url_helpers.rb +41 -0
  147. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/authlogic_sha512.rb +21 -0
  148. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/base.rb +20 -0
  149. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/bcrypt.rb +21 -0
  150. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/clearance_sha1.rb +19 -0
  151. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/restful_authentication_sha1.rb +22 -0
  152. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha1.rb +27 -0
  153. data/test/rails_app/vendor/plugins/devise/lib/devise/encryptors/sha512.rb +27 -0
  154. data/test/rails_app/vendor/plugins/devise/lib/devise/failure_app.rb +70 -0
  155. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/activatable.rb +15 -0
  156. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/rememberable.rb +33 -0
  157. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/timeoutable.rb +18 -0
  158. data/test/rails_app/vendor/plugins/devise/lib/devise/hooks/trackable.rb +18 -0
  159. data/test/rails_app/vendor/plugins/devise/lib/devise/mapping.rb +130 -0
  160. data/test/rails_app/vendor/plugins/devise/lib/devise/models/activatable.rb +16 -0
  161. data/test/rails_app/vendor/plugins/devise/lib/devise/models/confirmable.rb +167 -0
  162. data/test/rails_app/vendor/plugins/devise/lib/devise/models/database_authenticatable.rb +144 -0
  163. data/test/rails_app/vendor/plugins/devise/lib/devise/models/http_authenticatable.rb +23 -0
  164. data/test/rails_app/vendor/plugins/devise/lib/devise/models/lockable.rb +150 -0
  165. data/test/rails_app/vendor/plugins/devise/lib/devise/models/recoverable.rb +80 -0
  166. data/test/rails_app/vendor/plugins/devise/lib/devise/models/registerable.rb +8 -0
  167. data/test/rails_app/vendor/plugins/devise/lib/devise/models/rememberable.rb +92 -0
  168. data/test/rails_app/vendor/plugins/devise/lib/devise/models/timeoutable.rb +28 -0
  169. data/test/rails_app/vendor/plugins/devise/lib/devise/models/token_authenticatable.rb +89 -0
  170. data/test/rails_app/vendor/plugins/devise/lib/devise/models/trackable.rb +16 -0
  171. data/test/rails_app/vendor/plugins/devise/lib/devise/models/validatable.rb +39 -0
  172. data/test/rails_app/vendor/plugins/devise/lib/devise/models.rb +117 -0
  173. data/test/rails_app/vendor/plugins/devise/lib/devise/orm/active_record.rb +41 -0
  174. data/test/rails_app/vendor/plugins/devise/lib/devise/orm/data_mapper.rb +83 -0
  175. data/test/rails_app/vendor/plugins/devise/lib/devise/orm/mongo_mapper.rb +52 -0
  176. data/test/rails_app/vendor/plugins/devise/lib/devise/rails/routes.rb +133 -0
  177. data/test/rails_app/vendor/plugins/devise/lib/devise/rails/warden_compat.rb +60 -0
  178. data/test/rails_app/vendor/plugins/devise/lib/devise/rails.rb +14 -0
  179. data/test/rails_app/vendor/plugins/devise/lib/devise/schema.rb +73 -0
  180. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/base.rb +16 -0
  181. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/database_authenticatable.rb +36 -0
  182. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/http_authenticatable.rb +59 -0
  183. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb +37 -0
  184. data/test/rails_app/vendor/plugins/devise/lib/devise/strategies/token_authenticatable.rb +37 -0
  185. data/test/rails_app/vendor/plugins/devise/lib/devise/test_helpers.rb +90 -0
  186. data/test/rails_app/vendor/plugins/devise/lib/devise/version.rb +3 -0
  187. data/test/rails_app/vendor/plugins/devise/lib/devise.rb +266 -0
  188. data/test/rails_app/vendor/plugins/devise/rails/init.rb +2 -0
  189. data/test/rails_app/vendor/plugins/devise/test/controllers/helpers_test.rb +184 -0
  190. data/test/rails_app/vendor/plugins/devise/test/controllers/internal_helpers_test.rb +55 -0
  191. data/test/rails_app/vendor/plugins/devise/test/controllers/url_helpers_test.rb +47 -0
  192. data/test/rails_app/vendor/plugins/devise/test/devise_test.rb +74 -0
  193. data/test/rails_app/vendor/plugins/devise/test/encryptors_test.rb +31 -0
  194. data/test/rails_app/vendor/plugins/devise/test/failure_app_test.rb +44 -0
  195. data/test/rails_app/vendor/plugins/devise/test/integration/authenticatable_test.rb +332 -0
  196. data/test/rails_app/vendor/plugins/devise/test/integration/confirmable_test.rb +97 -0
  197. data/test/rails_app/vendor/plugins/devise/test/integration/http_authenticatable_test.rb +52 -0
  198. data/test/rails_app/vendor/plugins/devise/test/integration/lockable_test.rb +102 -0
  199. data/test/rails_app/vendor/plugins/devise/test/integration/rack_middleware_test.rb +47 -0
  200. data/test/rails_app/vendor/plugins/devise/test/integration/recoverable_test.rb +141 -0
  201. data/test/rails_app/vendor/plugins/devise/test/integration/registerable_test.rb +144 -0
  202. data/test/rails_app/vendor/plugins/devise/test/integration/rememberable_test.rb +72 -0
  203. data/test/rails_app/vendor/plugins/devise/test/integration/timeoutable_test.rb +68 -0
  204. data/test/rails_app/vendor/plugins/devise/test/integration/token_authenticatable_test.rb +55 -0
  205. data/test/rails_app/vendor/plugins/devise/test/integration/trackable_test.rb +64 -0
  206. data/test/rails_app/vendor/plugins/devise/test/mailers/confirmation_instructions_test.rb +86 -0
  207. data/test/rails_app/vendor/plugins/devise/test/mailers/reset_password_instructions_test.rb +68 -0
  208. data/test/rails_app/vendor/plugins/devise/test/mailers/unlock_instructions_test.rb +62 -0
  209. data/test/rails_app/vendor/plugins/devise/test/mapping_test.rb +158 -0
  210. data/test/rails_app/vendor/plugins/devise/test/models/authenticatable_test.rb +180 -0
  211. data/test/rails_app/vendor/plugins/devise/test/models/confirmable_test.rb +228 -0
  212. data/test/rails_app/vendor/plugins/devise/test/models/lockable_test.rb +202 -0
  213. data/test/rails_app/vendor/plugins/devise/test/models/recoverable_test.rb +138 -0
  214. data/test/rails_app/vendor/plugins/devise/test/models/rememberable_test.rb +135 -0
  215. data/test/rails_app/vendor/plugins/devise/test/models/timeoutable_test.rb +28 -0
  216. data/test/rails_app/vendor/plugins/devise/test/models/token_authenticatable_test.rb +51 -0
  217. data/test/rails_app/vendor/plugins/devise/test/models/trackable_test.rb +5 -0
  218. data/test/rails_app/vendor/plugins/devise/test/models/validatable_test.rb +106 -0
  219. data/test/rails_app/vendor/plugins/devise/test/models_test.rb +70 -0
  220. data/test/rails_app/vendor/plugins/devise/test/orm/active_record.rb +31 -0
  221. data/test/rails_app/vendor/plugins/devise/test/orm/mongo_mapper.rb +20 -0
  222. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/admin.rb +7 -0
  223. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/active_record/user.rb +7 -0
  224. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/admins_controller.rb +6 -0
  225. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/application_controller.rb +12 -0
  226. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/home_controller.rb +4 -0
  227. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/controllers/users_controller.rb +16 -0
  228. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/helpers/application_helper.rb +3 -0
  229. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/admin.rb +13 -0
  230. data/test/rails_app/vendor/plugins/devise/test/rails_app/app/mongo_mapper/user.rb +14 -0
  231. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/boot.rb +110 -0
  232. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environment.rb +42 -0
  233. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/development.rb +17 -0
  234. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/production.rb +28 -0
  235. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/environments/test.rb +28 -0
  236. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/devise.rb +82 -0
  237. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/inflections.rb +2 -0
  238. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/new_rails_defaults.rb +24 -0
  239. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/initializers/session_store.rb +15 -0
  240. data/test/rails_app/vendor/plugins/devise/test/rails_app/config/routes.rb +25 -0
  241. data/test/rails_app/vendor/plugins/devise/test/routes_test.rb +131 -0
  242. data/test/rails_app/vendor/plugins/devise/test/support/assertions_helper.rb +37 -0
  243. data/test/rails_app/vendor/plugins/devise/test/support/integration_tests_helper.rb +71 -0
  244. data/test/rails_app/vendor/plugins/devise/test/support/test_silencer.rb +5 -0
  245. data/test/rails_app/vendor/plugins/devise/test/support/tests_helper.rb +39 -0
  246. data/test/rails_app/vendor/plugins/devise/test/test_helper.rb +21 -0
  247. data/test/rails_app/vendor/plugins/devise/test/test_helpers_test.rb +57 -0
  248. data/test/routes_test.rb +131 -0
  249. data/test/support/assertions_helper.rb +37 -0
  250. data/test/support/integration_tests_helper.rb +71 -0
  251. data/test/support/test_silencer.rb +5 -0
  252. data/test/support/tests_helper.rb +39 -0
  253. data/test/test_helper.rb +21 -0
  254. data/test/test_helpers_test.rb +57 -0
  255. metadata +515 -0
@@ -0,0 +1,141 @@
1
+ require 'test/test_helper'
2
+
3
+ class PasswordTest < ActionController::IntegrationTest
4
+
5
+ def visit_new_password_path
6
+ visit new_user_session_path
7
+ click_link 'Forgot password?'
8
+ end
9
+
10
+ def request_forgot_password(&block)
11
+ visit_new_password_path
12
+
13
+ assert_response :success
14
+ assert_template 'passwords/new'
15
+ assert_not warden.authenticated?(:user)
16
+
17
+ fill_in 'email', :with => 'user@test.com'
18
+ yield if block_given?
19
+ click_button 'Send me reset password instructions'
20
+ end
21
+
22
+ def reset_password(options={}, &block)
23
+ unless options[:visit] == false
24
+ visit edit_user_password_path(:reset_password_token => options[:reset_password_token])
25
+ end
26
+ assert_response :success
27
+ assert_template 'passwords/edit'
28
+
29
+ fill_in 'Password', :with => '987654321'
30
+ fill_in 'Password confirmation', :with => '987654321'
31
+ yield if block_given?
32
+ click_button 'Change my password'
33
+ end
34
+
35
+ test 'authenticated user should not be able to visit forgot password page' do
36
+ sign_in_as_user
37
+ assert warden.authenticated?(:user)
38
+
39
+ get new_user_password_path
40
+
41
+ assert_response :redirect
42
+ assert_redirected_to root_path
43
+ end
44
+
45
+ test 'not authenticated user should be able to request a forgot password' do
46
+ create_user
47
+ request_forgot_password
48
+
49
+ assert_template 'sessions/new'
50
+ assert_contain 'You will receive an email with instructions about how to reset your password in a few minutes.'
51
+ end
52
+
53
+ test 'not authenticated user with invalid email should receive an error message' do
54
+ request_forgot_password do
55
+ fill_in 'email', :with => 'invalid.test@test.com'
56
+ end
57
+
58
+ assert_response :success
59
+ assert_template 'passwords/new'
60
+ assert_have_selector 'input[type=text][value=\'invalid.test@test.com\']'
61
+ assert_contain 'Email not found'
62
+ end
63
+
64
+ test 'authenticated user should not be able to visit edit password page' do
65
+ sign_in_as_user
66
+
67
+ get edit_user_password_path
68
+
69
+ assert_response :redirect
70
+ assert_redirected_to root_path
71
+ assert warden.authenticated?(:user)
72
+ end
73
+
74
+ test 'not authenticated user with invalid reset password token should not be able to change his password' do
75
+ user = create_user
76
+ reset_password :reset_password_token => 'invalid_reset_password'
77
+
78
+ assert_response :success
79
+ assert_template 'passwords/edit'
80
+ assert_have_selector '#errorExplanation'
81
+ assert_contain /Reset password token(.*)invalid/
82
+ assert_not user.reload.valid_password?('987654321')
83
+ end
84
+
85
+ test 'not authenticated user with valid reset password token but invalid password should not be able to change his password' do
86
+ user = create_user
87
+ request_forgot_password
88
+ reset_password :reset_password_token => user.reload.reset_password_token do
89
+ fill_in 'Password confirmation', :with => 'other_password'
90
+ end
91
+
92
+ assert_response :success
93
+ assert_template 'passwords/edit'
94
+ assert_have_selector '#errorExplanation'
95
+ assert_contain 'Password doesn\'t match confirmation'
96
+ assert_not user.reload.valid_password?('987654321')
97
+ end
98
+
99
+ test 'not authenticated user with valid data should be able to change his password' do
100
+ user = create_user
101
+ request_forgot_password
102
+ reset_password :reset_password_token => user.reload.reset_password_token
103
+
104
+ assert_template 'home/index'
105
+ assert_contain 'Your password was changed successfully.'
106
+ assert user.reload.valid_password?('987654321')
107
+ end
108
+
109
+ test 'after entering invalid data user should still be able to change his password' do
110
+ user = create_user
111
+ request_forgot_password
112
+ reset_password :reset_password_token => user.reload.reset_password_token do
113
+ fill_in 'Password confirmation', :with => 'other_password'
114
+ end
115
+ assert_response :success
116
+ assert_have_selector '#errorExplanation'
117
+ assert_not user.reload.valid_password?('987654321')
118
+
119
+ reset_password :reset_password_token => user.reload.reset_password_token, :visit => false
120
+ assert_contain 'Your password was changed successfully.'
121
+ assert user.reload.valid_password?('987654321')
122
+ end
123
+
124
+ test 'sign in user automatically after changing it\'s password' do
125
+ user = create_user
126
+ request_forgot_password
127
+ reset_password :reset_password_token => user.reload.reset_password_token
128
+
129
+ assert warden.authenticated?(:user)
130
+ end
131
+
132
+ test 'does not sign in user automatically after changing it\'s password if it\'s not active' do
133
+ user = create_user(:confirm => false)
134
+ request_forgot_password
135
+ reset_password :reset_password_token => user.reload.reset_password_token
136
+
137
+ assert_redirected_to new_user_session_path(:unconfirmed => true)
138
+ assert !warden.authenticated?(:user)
139
+ end
140
+
141
+ end
@@ -0,0 +1,144 @@
1
+ require 'test/test_helper'
2
+
3
+ class RegistrationTest < ActionController::IntegrationTest
4
+
5
+ test 'a guest admin should be able to sign in successfully' do
6
+ visit new_admin_session_path
7
+ click_link 'Sign up'
8
+
9
+ assert_template 'registrations/new'
10
+
11
+ fill_in 'email', :with => 'new_user@test.com'
12
+ fill_in 'password', :with => 'new_user123'
13
+ fill_in 'password confirmation', :with => 'new_user123'
14
+ click_button 'Sign up'
15
+
16
+ assert_contain 'You have signed up successfully.'
17
+ assert warden.authenticated?(:admin)
18
+
19
+ admin = Admin.last
20
+ assert_equal admin.email, 'new_user@test.com'
21
+ end
22
+
23
+ test 'a guest user should be able to sign up successfully and be blocked by confirmation' do
24
+ visit new_user_registration_path
25
+
26
+ fill_in 'email', :with => 'new_user@test.com'
27
+ fill_in 'password', :with => 'new_user123'
28
+ fill_in 'password confirmation', :with => 'new_user123'
29
+ click_button 'Sign up'
30
+
31
+ assert_equal "You have signed up successfully. If enabled, a confirmation was sent to your e-mail.", @controller.send(:flash)[:notice]
32
+
33
+ # For some reason flash is not being set correctly, so instead of getting the
34
+ # "signed_up" message we get the unconfirmed one. Seems to be an issue with
35
+ # the internal redirect by the hook and the tests.
36
+ # follow_redirect!
37
+ # assert_contain 'You have signed up successfully.'
38
+ # assert_not_contain 'confirm your account'
39
+
40
+ follow_redirect!
41
+ assert_contain 'Sign in'
42
+ assert_not warden.authenticated?(:user)
43
+
44
+ user = User.last
45
+ assert_equal user.email, 'new_user@test.com'
46
+ assert_not user.confirmed?
47
+ end
48
+
49
+ test 'a guest user cannot sign up with invalid information' do
50
+ visit new_user_registration_path
51
+
52
+ fill_in 'email', :with => 'invalid_email'
53
+ fill_in 'password', :with => 'new_user123'
54
+ fill_in 'password confirmation', :with => 'new_user321'
55
+ click_button 'Sign up'
56
+
57
+ assert_template 'registrations/new'
58
+ assert_have_selector '#errorExplanation'
59
+ assert_contain "Email is invalid"
60
+ assert_contain "Password doesn't match confirmation"
61
+ assert_nil User.first
62
+
63
+ assert_not warden.authenticated?(:user)
64
+ end
65
+
66
+ test 'a guest should not sign up with email/password that already exists' do
67
+ user = create_user
68
+ visit new_user_registration_path
69
+
70
+ fill_in 'email', :with => 'user@test.com'
71
+ fill_in 'password', :with => '123456'
72
+ fill_in 'password confirmation', :with => '123456'
73
+ click_button 'Sign up'
74
+
75
+ assert_template 'registrations/new'
76
+ assert_contain 'Email has already been taken'
77
+
78
+ assert_not warden.authenticated?(:user)
79
+ end
80
+
81
+ test 'a guest should not be able to change account' do
82
+ visit edit_user_registration_path
83
+ follow_redirect!
84
+ assert_template 'sessions/new'
85
+ end
86
+
87
+ test 'a signed in user should not be able to access sign up' do
88
+ sign_in_as_user
89
+ visit new_user_registration_path
90
+ assert_template 'home/index'
91
+ end
92
+
93
+ test 'a signed in user should be able to edit his account' do
94
+ sign_in_as_user
95
+ visit edit_user_registration_path
96
+
97
+ fill_in 'email', :with => 'user.new@email.com'
98
+ fill_in 'current password', :with => '123456'
99
+ click_button 'Update'
100
+
101
+ assert_template 'home/index'
102
+ assert_contain 'You updated your account successfully.'
103
+
104
+ assert_equal "user.new@email.com", User.first.email
105
+ end
106
+
107
+ test 'a signed in user should be able to edit his password' do
108
+ sign_in_as_user
109
+ visit edit_user_registration_path
110
+
111
+ fill_in 'password', :with => 'pas123'
112
+ fill_in 'password confirmation', :with => 'pas123'
113
+ fill_in 'current password', :with => '123456'
114
+ click_button 'Update'
115
+
116
+ assert_template 'home/index'
117
+ assert_contain 'You updated your account successfully.'
118
+
119
+ assert User.first.valid_password?('pas123')
120
+ end
121
+
122
+ test 'a signed in user should not be able to edit his password with invalid confirmation' do
123
+ sign_in_as_user
124
+ get edit_user_registration_path
125
+
126
+ fill_in 'password', :with => 'pas123'
127
+ fill_in 'password confirmation', :with => ''
128
+ fill_in 'current password', :with => '123456'
129
+ click_button 'Update'
130
+
131
+ assert_contain "Password doesn't match confirmation"
132
+ assert_not User.first.valid_password?('pas123')
133
+ end
134
+
135
+ test 'a signed in user should be able to cancel his account' do
136
+ sign_in_as_user
137
+ visit edit_user_registration_path
138
+
139
+ click_link "Cancel my account"
140
+ assert_contain "Bye! Your account was successfully cancelled. We hope to see you again soon."
141
+
142
+ assert User.all.empty?
143
+ end
144
+ end
@@ -0,0 +1,72 @@
1
+ require 'test/test_helper'
2
+
3
+ class RememberMeTest < ActionController::IntegrationTest
4
+
5
+ def create_user_and_remember(add_to_token='')
6
+ Devise.remember_for = 1
7
+ user = create_user
8
+ user.remember_me!
9
+ cookies['remember_user_token'] = User.serialize_into_cookie(user) + add_to_token
10
+ user
11
+ end
12
+
13
+ test 'do not remember the user if he has not checked remember me option' do
14
+ user = sign_in_as_user
15
+ assert_nil user.reload.remember_token
16
+ end
17
+
18
+ test 'generate remember token after sign in' do
19
+ user = sign_in_as_user :remember_me => true
20
+ assert_not_nil user.reload.remember_token
21
+ end
22
+
23
+ test 'remember the user before sign in' do
24
+ user = create_user_and_remember
25
+ get users_path
26
+ assert_response :success
27
+ assert warden.authenticated?(:user)
28
+ assert warden.user(:user) == user
29
+ end
30
+
31
+ test 'does not remember other scopes' do
32
+ user = create_user_and_remember
33
+ get root_path
34
+ assert_response :success
35
+ assert warden.authenticated?(:user)
36
+ assert_not warden.authenticated?(:admin)
37
+ end
38
+
39
+ test 'do not remember with invalid token' do
40
+ user = create_user_and_remember('add')
41
+ get users_path
42
+ assert_response :success
43
+ assert_not warden.authenticated?(:user)
44
+ end
45
+
46
+ test 'do not remember with token expired' do
47
+ user = create_user_and_remember
48
+ Devise.remember_for = 0
49
+ get users_path
50
+ assert_response :success
51
+ assert_not warden.authenticated?(:user)
52
+ end
53
+
54
+ test 'forget the user before sign out' do
55
+ user = create_user_and_remember
56
+ get users_path
57
+ assert warden.authenticated?(:user)
58
+ get destroy_user_session_path
59
+ assert_not warden.authenticated?(:user)
60
+ assert_nil user.reload.remember_token
61
+ end
62
+
63
+ test 'do not remember the user anymore after forget' do
64
+ user = create_user_and_remember
65
+ get users_path
66
+ assert warden.authenticated?(:user)
67
+ get destroy_user_session_path
68
+ get users_path
69
+ assert_not warden.authenticated?(:user)
70
+ assert_equal cookies['remember_user_token'], ''
71
+ end
72
+ end
@@ -0,0 +1,68 @@
1
+ require 'test/test_helper'
2
+
3
+ class SessionTimeoutTest < ActionController::IntegrationTest
4
+
5
+ def last_request_at
6
+ @controller.user_session['last_request_at']
7
+ end
8
+
9
+ test 'set last request at in user session after each request' do
10
+ sign_in_as_user
11
+ old_last_request = last_request_at
12
+ assert_not_nil last_request_at
13
+
14
+ get users_path
15
+ assert_not_nil last_request_at
16
+ assert_not_equal old_last_request, last_request_at
17
+ end
18
+
19
+ test 'not time out user session before default limit time' do
20
+ sign_in_as_user
21
+ assert_response :success
22
+ assert warden.authenticated?(:user)
23
+
24
+ get users_path
25
+ assert_response :success
26
+ assert warden.authenticated?(:user)
27
+ end
28
+
29
+ test 'time out user session after default limit time' do
30
+ user = sign_in_as_user
31
+ get expire_user_path(user)
32
+ assert_not_nil last_request_at
33
+
34
+ get users_path
35
+ assert_redirected_to new_user_session_path(:timeout => true)
36
+ assert_not warden.authenticated?(:user)
37
+ end
38
+
39
+ test 'user configured timeout limit' do
40
+ swap Devise, :timeout_in => 8.minutes do
41
+ user = sign_in_as_user
42
+
43
+ get users_path
44
+ assert_not_nil last_request_at
45
+ assert_response :success
46
+ assert warden.authenticated?(:user)
47
+
48
+ get expire_user_path(user)
49
+ get users_path
50
+ assert_redirected_to new_user_session_path(:timeout => true)
51
+ assert_not warden.authenticated?(:user)
52
+ end
53
+ end
54
+
55
+ test 'error message with i18n' do
56
+ store_translations :en, :devise => {
57
+ :sessions => { :user => { :timeout => 'Session expired!' } }
58
+ } do
59
+ user = sign_in_as_user
60
+
61
+ get expire_user_path(user)
62
+ get users_path
63
+ follow_redirect!
64
+ assert_contain 'Session expired!'
65
+ end
66
+ end
67
+
68
+ end
@@ -0,0 +1,55 @@
1
+ require 'test/test_helper'
2
+
3
+ class TokenAuthenticationTest < ActionController::IntegrationTest
4
+
5
+ test 'sign in should authenticate with valid authentication token and proper authentication token key' do
6
+ swap Devise, :token_authentication_key => :secret_token do
7
+ sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
8
+
9
+ assert_response :success
10
+ assert_template 'users/index'
11
+ assert_contain 'Welcome'
12
+ assert warden.authenticated?(:user)
13
+ end
14
+ end
15
+
16
+ test 'signing in with valid authentication token - but improper authentication token key - return to sign in form with error message' do
17
+ swap Devise, :token_authentication_key => :donald_duck_token do
18
+ sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
19
+ assert_redirected_to new_user_session_path(:unauthenticated => true)
20
+ follow_redirect!
21
+
22
+ assert_contain 'You need to sign in or sign up before continuing'
23
+ assert_contain 'Sign in'
24
+ assert_not warden.authenticated?(:user)
25
+ end
26
+ end
27
+
28
+ test 'signing in with invalid authentication token should return to sign in form with error message' do
29
+ store_translations :en, :devise => {:sessions => {:invalid_token => 'LOL, that was not a single character correct.'}} do
30
+ sign_in_as_new_user_with_token(:auth_token => '*** INVALID TOKEN ***')
31
+ assert_redirected_to new_user_session_path(:invalid_token => true)
32
+ follow_redirect!
33
+
34
+ assert_response :success
35
+ assert_contain 'LOL, that was not a single character correct.'
36
+ assert_contain 'Sign in'
37
+ assert_not warden.authenticated?(:user)
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ def sign_in_as_new_user_with_token(options = {})
44
+ options[:auth_token_key] ||= Devise.token_authentication_key
45
+ options[:auth_token] ||= VALID_AUTHENTICATION_TOKEN
46
+
47
+ user = create_user(options)
48
+ user.authentication_token = VALID_AUTHENTICATION_TOKEN
49
+ user.save
50
+
51
+ visit users_path(options[:auth_token_key].to_sym => options[:auth_token])
52
+ user
53
+ end
54
+
55
+ end
@@ -0,0 +1,64 @@
1
+ require 'test/test_helper'
2
+
3
+ class TrackableHooksTest < ActionController::IntegrationTest
4
+
5
+ test "current and last sign in timestamps are updated on each sign in" do
6
+ user = create_user
7
+ assert_nil user.current_sign_in_at
8
+ assert_nil user.last_sign_in_at
9
+
10
+ sign_in_as_user
11
+ user.reload
12
+
13
+ assert_kind_of Time, user.current_sign_in_at
14
+ assert_kind_of Time, user.last_sign_in_at
15
+
16
+ assert_equal user.current_sign_in_at, user.last_sign_in_at
17
+ assert user.current_sign_in_at >= user.created_at
18
+
19
+ visit destroy_user_session_path
20
+ new_time = 2.seconds.from_now
21
+ Time.stubs(:now).returns(new_time)
22
+
23
+ sign_in_as_user
24
+ user.reload
25
+ assert user.current_sign_in_at > user.last_sign_in_at
26
+ end
27
+
28
+ test "current and last sign in remote ip are updated on each sign in" do
29
+ user = create_user
30
+ assert_nil user.current_sign_in_ip
31
+ assert_nil user.last_sign_in_ip
32
+
33
+ sign_in_as_user
34
+ user.reload
35
+
36
+ assert_equal "127.0.0.1", user.current_sign_in_ip
37
+ assert_equal "127.0.0.1", user.last_sign_in_ip
38
+ end
39
+
40
+ test "increase sign in count" do
41
+ user = create_user
42
+ assert_equal 0, user.sign_in_count
43
+
44
+ sign_in_as_user
45
+ user.reload
46
+ assert_equal 1, user.sign_in_count
47
+
48
+ visit destroy_user_session_path
49
+ sign_in_as_user
50
+ user.reload
51
+ assert_equal 2, user.sign_in_count
52
+ end
53
+
54
+ test "does not update anything if user has signed out along the way" do
55
+ swap Devise, :confirm_within => 0 do
56
+ user = create_user(:confirm => false)
57
+ sign_in_as_user
58
+
59
+ user.reload
60
+ assert_nil user.current_sign_in_at
61
+ assert_nil user.last_sign_in_at
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,86 @@
1
+ require 'test/test_helper'
2
+
3
+ class ConfirmationInstructionsTest < ActionMailer::TestCase
4
+
5
+ def setup
6
+ setup_mailer
7
+ Devise.mailer_sender = 'test@example.com'
8
+ end
9
+
10
+ def user
11
+ @user ||= create_user
12
+ end
13
+
14
+ def mail
15
+ @mail ||= begin
16
+ user
17
+ ActionMailer::Base.deliveries.first
18
+ end
19
+ end
20
+
21
+ test 'email sent after creating the user' do
22
+ assert_not_nil mail
23
+ end
24
+
25
+ test 'content type should be set to html' do
26
+ assert_equal 'text/html', mail.content_type
27
+ end
28
+
29
+ test 'send confirmation instructions to the user email' do
30
+ mail
31
+ assert_equal [user.email], mail.to
32
+ end
33
+
34
+ test 'setup sender from configuration' do
35
+ assert_equal ['test@example.com'], mail.from
36
+ end
37
+
38
+ test 'setup subject from I18n' do
39
+ store_translations :en, :devise => { :mailer => { :confirmation_instructions => 'Account Confirmation' } } do
40
+ assert_equal 'Account Confirmation', mail.subject
41
+ end
42
+ end
43
+
44
+ test 'subject namespaced by model' do
45
+ store_translations :en, :devise => { :mailer => { :user => { :confirmation_instructions => 'User Account Confirmation' } } } do
46
+ assert_equal 'User Account Confirmation', mail.subject
47
+ end
48
+ end
49
+
50
+ test 'body should have user info' do
51
+ assert_match /#{user.email}/, mail.body
52
+ end
53
+
54
+ test 'body should have link to confirm the account' do
55
+ host = ActionMailer::Base.default_url_options[:host]
56
+ confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
57
+ assert_match confirmation_url_regexp, mail.body
58
+ end
59
+
60
+ test 'renders a scoped if scoped_views is set to true' do
61
+ swap Devise, :scoped_views => true do
62
+ assert_equal user.email, mail.body
63
+ end
64
+ end
65
+
66
+ test 'content type should be set to plain when manually configured' do
67
+ swap Devise, :mailer_content_type => "text/plain" do
68
+ assert_equal "text/plain", mail.content_type
69
+ end
70
+ end
71
+
72
+ test 'renders a scoped if scoped_views is set in the mailer class' do
73
+ begin
74
+ DeviseMailer.scoped_views = true
75
+ assert_equal user.email, mail.body
76
+ ensure
77
+ DeviseMailer.send :remove_instance_variable, :@scoped_views
78
+ end
79
+ end
80
+
81
+ test 'mailer sender accepts a proc' do
82
+ swap Devise, :mailer_sender => lambda { "another@example.com" } do
83
+ assert_equal ['another@example.com'], mail.from
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,68 @@
1
+ require 'test/test_helper'
2
+
3
+ class ResetPasswordInstructionsTest < ActionMailer::TestCase
4
+
5
+ def setup
6
+ setup_mailer
7
+ Devise.mailer_sender = 'test@example.com'
8
+ end
9
+
10
+ def user
11
+ @user ||= begin
12
+ user = create_user
13
+ user.send_reset_password_instructions
14
+ user
15
+ end
16
+ end
17
+
18
+ def mail
19
+ @mail ||= begin
20
+ user
21
+ ActionMailer::Base.deliveries.last
22
+ end
23
+ end
24
+
25
+ test 'email sent after reseting the user password' do
26
+ assert_not_nil mail
27
+ end
28
+
29
+ test 'content type should be set to html' do
30
+ assert_equal 'text/html', mail.content_type
31
+ end
32
+
33
+ test 'send confirmation instructions to the user email' do
34
+ assert_equal [user.email], mail.to
35
+ end
36
+
37
+ test 'setup sender from configuration' do
38
+ assert_equal ['test@example.com'], mail.from
39
+ end
40
+
41
+ test 'setup subject from I18n' do
42
+ store_translations :en, :devise => { :mailer => { :reset_password_instructions => 'Reset instructions' } } do
43
+ assert_equal 'Reset instructions', mail.subject
44
+ end
45
+ end
46
+
47
+ test 'subject namespaced by model' do
48
+ store_translations :en, :devise => { :mailer => { :user => { :reset_password_instructions => 'User Reset Instructions' } } } do
49
+ assert_equal 'User Reset Instructions', mail.subject
50
+ end
51
+ end
52
+
53
+ test 'body should have user info' do
54
+ assert_match /#{user.email}/, mail.body
55
+ end
56
+
57
+ test 'body should have link to confirm the account' do
58
+ host = ActionMailer::Base.default_url_options[:host]
59
+ reset_url_regexp = %r{<a href=\"http://#{host}/users/password/edit\?reset_password_token=#{user.reset_password_token}">}
60
+ assert_match reset_url_regexp, mail.body
61
+ end
62
+
63
+ test 'mailer sender accepts a proc' do
64
+ swap Devise, :mailer_sender => lambda { "another@example.com" } do
65
+ assert_equal ['another@example.com'], mail.from
66
+ end
67
+ end
68
+ end