devise 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


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

Files changed (187) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +18 -3
  3. data/CHANGELOG.md +82 -9
  4. data/CONTRIBUTING.md +2 -2
  5. data/Gemfile +7 -9
  6. data/Gemfile.lock +102 -96
  7. data/MIT-LICENSE +1 -1
  8. data/README.md +94 -42
  9. data/Rakefile +1 -1
  10. data/app/controllers/devise/confirmations_controller.rb +5 -3
  11. data/app/controllers/devise/omniauth_callbacks_controller.rb +2 -2
  12. data/app/controllers/devise/passwords_controller.rb +5 -3
  13. data/app/controllers/devise/registrations_controller.rb +26 -10
  14. data/app/controllers/devise/sessions_controller.rb +39 -14
  15. data/app/controllers/devise/unlocks_controller.rb +4 -2
  16. data/app/controllers/devise_controller.rb +6 -6
  17. data/app/helpers/devise_helper.rb +2 -2
  18. data/app/views/devise/confirmations/new.html.erb +2 -2
  19. data/app/views/devise/mailer/confirmation_instructions.html.erb +1 -1
  20. data/app/views/devise/mailer/reset_password_instructions.html.erb +1 -1
  21. data/app/views/devise/mailer/unlock_instructions.html.erb +1 -1
  22. data/app/views/devise/passwords/edit.html.erb +3 -3
  23. data/app/views/devise/passwords/new.html.erb +2 -2
  24. data/app/views/devise/registrations/edit.html.erb +6 -6
  25. data/app/views/devise/registrations/new.html.erb +5 -5
  26. data/app/views/devise/sessions/new.html.erb +5 -5
  27. data/app/views/devise/shared/_links.erb +1 -1
  28. data/app/views/devise/unlocks/new.html.erb +2 -2
  29. data/config/locales/en.yml +17 -16
  30. data/devise.gemspec +2 -2
  31. data/gemfiles/{Gemfile.rails-3.2.x → Gemfile.rails-3.2-stable} +8 -10
  32. data/gemfiles/Gemfile.rails-3.2-stable.lock +166 -0
  33. data/gemfiles/Gemfile.rails-4.0-stable +29 -0
  34. data/gemfiles/Gemfile.rails-4.0-stable.lock +162 -0
  35. data/gemfiles/Gemfile.rails-head +32 -0
  36. data/gemfiles/Gemfile.rails-head.lock +190 -0
  37. data/lib/devise/controllers/helpers.rb +84 -29
  38. data/lib/devise/controllers/rememberable.rb +3 -3
  39. data/lib/devise/controllers/scoped_views.rb +1 -1
  40. data/lib/devise/controllers/sign_in_out.rb +9 -10
  41. data/lib/devise/controllers/store_location.rb +56 -0
  42. data/lib/devise/controllers/url_helpers.rb +3 -1
  43. data/lib/devise/failure_app.rb +12 -10
  44. data/lib/devise/hooks/activatable.rb +5 -6
  45. data/lib/devise/hooks/csrf_cleaner.rb +3 -1
  46. data/lib/devise/hooks/lockable.rb +1 -1
  47. data/lib/devise/hooks/proxy.rb +2 -2
  48. data/lib/devise/hooks/rememberable.rb +2 -2
  49. data/lib/devise/hooks/timeoutable.rb +10 -3
  50. data/lib/devise/hooks/trackable.rb +1 -1
  51. data/lib/devise/mailers/helpers.rb +8 -8
  52. data/lib/devise/mapping.rb +4 -1
  53. data/lib/devise/models/authenticatable.rb +5 -5
  54. data/lib/devise/models/confirmable.rb +14 -14
  55. data/lib/devise/models/database_authenticatable.rb +18 -5
  56. data/lib/devise/models/lockable.rb +14 -11
  57. data/lib/devise/models/omniauthable.rb +1 -1
  58. data/lib/devise/models/recoverable.rb +23 -7
  59. data/lib/devise/models/rememberable.rb +6 -6
  60. data/lib/devise/models/timeoutable.rb +2 -2
  61. data/lib/devise/models/trackable.rb +5 -2
  62. data/lib/devise/models/validatable.rb +6 -6
  63. data/lib/devise/modules.rb +10 -10
  64. data/lib/devise/omniauth/url_helpers.rb +2 -2
  65. data/lib/devise/orm/active_record.rb +1 -1
  66. data/lib/devise/orm/mongoid.rb +1 -1
  67. data/lib/devise/rails/routes.rb +107 -78
  68. data/lib/devise/rails.rb +7 -1
  69. data/lib/devise/strategies/authenticatable.rb +11 -4
  70. data/lib/devise/strategies/base.rb +1 -1
  71. data/lib/devise/strategies/database_authenticatable.rb +7 -4
  72. data/lib/devise/test_helpers.rb +2 -2
  73. data/lib/devise/time_inflector.rb +2 -2
  74. data/lib/devise/version.rb +1 -1
  75. data/lib/devise.rb +15 -10
  76. data/lib/generators/active_record/devise_generator.rb +27 -10
  77. data/lib/generators/active_record/templates/migration.rb +4 -4
  78. data/lib/generators/active_record/templates/migration_existing.rb +4 -4
  79. data/lib/generators/devise/devise_generator.rb +5 -3
  80. data/lib/generators/devise/install_generator.rb +5 -0
  81. data/lib/generators/devise/views_generator.rb +31 -18
  82. data/lib/generators/mongoid/devise_generator.rb +20 -19
  83. data/lib/generators/templates/README +4 -4
  84. data/lib/generators/templates/devise.rb +20 -11
  85. data/lib/generators/templates/markerb/confirmation_instructions.markerb +1 -1
  86. data/lib/generators/templates/markerb/reset_password_instructions.markerb +1 -1
  87. data/lib/generators/templates/markerb/unlock_instructions.markerb +1 -1
  88. data/lib/generators/templates/simple_form_for/confirmations/new.html.erb +2 -2
  89. data/lib/generators/templates/simple_form_for/passwords/edit.html.erb +4 -4
  90. data/lib/generators/templates/simple_form_for/passwords/new.html.erb +2 -2
  91. data/lib/generators/templates/simple_form_for/registrations/edit.html.erb +6 -6
  92. data/lib/generators/templates/simple_form_for/registrations/new.html.erb +4 -4
  93. data/lib/generators/templates/simple_form_for/sessions/new.html.erb +4 -4
  94. data/lib/generators/templates/simple_form_for/unlocks/new.html.erb +2 -2
  95. data/script/cached-bundle +49 -0
  96. data/script/s3-put +71 -0
  97. data/test/controllers/custom_registrations_controller_test.rb +35 -0
  98. data/test/controllers/helpers_test.rb +89 -31
  99. data/test/controllers/internal_helpers_test.rb +11 -8
  100. data/test/controllers/passwords_controller_test.rb +1 -1
  101. data/test/controllers/sessions_controller_test.rb +29 -25
  102. data/test/controllers/url_helpers_test.rb +4 -4
  103. data/test/delegator_test.rb +1 -1
  104. data/test/devise_test.rb +21 -8
  105. data/test/failure_app_test.rb +61 -25
  106. data/test/generators/active_record_generator_test.rb +10 -4
  107. data/test/generators/devise_generator_test.rb +2 -2
  108. data/test/generators/mongoid_generator_test.rb +3 -3
  109. data/test/generators/views_generator_test.rb +30 -1
  110. data/test/helpers/devise_helper_test.rb +14 -13
  111. data/test/integration/authenticatable_test.rb +61 -45
  112. data/test/integration/confirmable_test.rb +95 -55
  113. data/test/integration/database_authenticatable_test.rb +16 -16
  114. data/test/integration/http_authenticatable_test.rb +12 -12
  115. data/test/integration/lockable_test.rb +43 -43
  116. data/test/integration/omniauthable_test.rb +3 -3
  117. data/test/integration/recoverable_test.rb +53 -53
  118. data/test/integration/registerable_test.rb +90 -80
  119. data/test/integration/rememberable_test.rb +15 -15
  120. data/test/integration/timeoutable_test.rb +27 -16
  121. data/test/integration/trackable_test.rb +4 -4
  122. data/test/mailers/confirmation_instructions_test.rb +7 -7
  123. data/test/mailers/reset_password_instructions_test.rb +6 -6
  124. data/test/mailers/unlock_instructions_test.rb +5 -5
  125. data/test/mapping_test.rb +3 -3
  126. data/test/models/authenticatable_test.rb +3 -3
  127. data/test/models/confirmable_test.rb +32 -32
  128. data/test/models/database_authenticatable_test.rb +32 -27
  129. data/test/models/lockable_test.rb +57 -33
  130. data/test/models/recoverable_test.rb +34 -22
  131. data/test/models/rememberable_test.rb +29 -14
  132. data/test/models/serializable_test.rb +8 -8
  133. data/test/models/timeoutable_test.rb +1 -1
  134. data/test/models/trackable_test.rb +28 -0
  135. data/test/models/validatable_test.rb +13 -13
  136. data/test/omniauth/config_test.rb +4 -4
  137. data/test/omniauth/url_helpers_test.rb +3 -3
  138. data/test/orm/mongoid.rb +1 -1
  139. data/test/parameter_sanitizer_test.rb +1 -1
  140. data/test/rails_app/app/active_record/shim.rb +1 -1
  141. data/test/rails_app/app/active_record/user_on_engine.rb +7 -0
  142. data/test/rails_app/app/active_record/user_on_main_app.rb +7 -0
  143. data/test/rails_app/app/controllers/admins/sessions_controller.rb +1 -1
  144. data/test/rails_app/app/controllers/admins_controller.rb +1 -1
  145. data/test/rails_app/app/controllers/application_controller.rb +5 -2
  146. data/test/rails_app/app/controllers/application_with_fake_engine.rb +30 -0
  147. data/test/rails_app/app/controllers/custom/registrations_controller.rb +21 -0
  148. data/test/rails_app/app/controllers/home_controller.rb +1 -1
  149. data/test/rails_app/app/controllers/publisher/registrations_controller.rb +1 -1
  150. data/test/rails_app/app/controllers/publisher/sessions_controller.rb +1 -1
  151. data/test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb +4 -4
  152. data/test/rails_app/app/controllers/users_controller.rb +6 -6
  153. data/test/rails_app/app/mailers/users/mailer.rb +4 -4
  154. data/test/rails_app/app/mongoid/admin.rb +11 -11
  155. data/test/rails_app/app/mongoid/shim.rb +2 -2
  156. data/test/rails_app/app/mongoid/user.rb +19 -19
  157. data/test/rails_app/app/mongoid/user_on_engine.rb +39 -0
  158. data/test/rails_app/app/mongoid/user_on_main_app.rb +39 -0
  159. data/test/rails_app/app/views/admins/sessions/new.html.erb +1 -1
  160. data/test/rails_app/app/views/home/admin_dashboard.html.erb +1 -1
  161. data/test/rails_app/app/views/home/index.html.erb +1 -1
  162. data/test/rails_app/app/views/home/join.html.erb +1 -1
  163. data/test/rails_app/app/views/home/user_dashboard.html.erb +1 -1
  164. data/test/rails_app/app/views/layouts/application.html.erb +1 -1
  165. data/test/rails_app/config/application.rb +2 -2
  166. data/test/rails_app/config/boot.rb +7 -1
  167. data/test/rails_app/config/environments/development.rb +0 -4
  168. data/test/rails_app/config/environments/production.rb +0 -4
  169. data/test/rails_app/config/initializers/devise.rb +7 -5
  170. data/test/rails_app/config/initializers/secret_token.rb +1 -1
  171. data/test/rails_app/config/routes.rb +60 -42
  172. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +7 -7
  173. data/test/rails_app/db/schema.rb +21 -17
  174. data/test/rails_app/lib/shared_admin.rb +4 -4
  175. data/test/rails_app/lib/shared_user.rb +1 -1
  176. data/test/rails_app/lib/shared_user_without_omniauth.rb +13 -0
  177. data/test/routes_test.rb +72 -58
  178. data/test/support/action_controller/record_identifier.rb +10 -0
  179. data/test/support/assertions.rb +2 -3
  180. data/test/support/helpers.rb +4 -4
  181. data/test/support/integration.rb +14 -14
  182. data/test/support/mongoid.yml +6 -0
  183. data/test/test_helper.rb +2 -7
  184. data/test/test_helpers_test.rb +25 -35
  185. data/test/test_models.rb +12 -5
  186. metadata +53 -38
  187. data/gemfiles/Gemfile.rails-3.2.x.lock +0 -159
data/script/s3-put ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env bash
2
+ # Usage: s3-put <FILE> <S3_BUCKET>[:<PATH>] [<CONTENT_TYPE>]
3
+ #
4
+ # Uploads a file to the Amazon S3 service.
5
+ # Outputs the URL for the newly uploaded file.
6
+ #
7
+ # Requirements:
8
+ # - AMAZON_ACCESS_KEY_ID
9
+ # - AMAZON_SECRET_ACCESS_KEY
10
+ # - openssl
11
+ # - curl
12
+ #
13
+ # Author: Mislav Marohnić
14
+
15
+ set -e
16
+
17
+ authorization() {
18
+ local signature="$(string_to_sign | hmac_sha1 | base64)"
19
+ echo "AWS ${AMAZON_ACCESS_KEY_ID?}:${signature}"
20
+ }
21
+
22
+ hmac_sha1() {
23
+ openssl dgst -binary -sha1 -hmac "${AMAZON_SECRET_ACCESS_KEY?}"
24
+ }
25
+
26
+ base64() {
27
+ openssl enc -base64
28
+ }
29
+
30
+ bin_md5() {
31
+ openssl dgst -binary -md5
32
+ }
33
+
34
+ string_to_sign() {
35
+ echo "$http_method"
36
+ echo "$content_md5"
37
+ echo "$content_type"
38
+ echo "$date"
39
+ echo "x-amz-acl:$acl"
40
+ printf "/$bucket/$remote_path"
41
+ }
42
+
43
+ date_string() {
44
+ LC_TIME=C date "+%a, %d %h %Y %T %z"
45
+ }
46
+
47
+ file="$1"
48
+ bucket="${2%%:*}"
49
+ remote_path="${2#*:}"
50
+ content_type="$3"
51
+
52
+ if [ -z "$remote_path" ] || [ "$remote_path" = "$bucket" ]; then
53
+ remote_path="${file##*/}"
54
+ fi
55
+
56
+ http_method=PUT
57
+ acl="public-read"
58
+ content_md5="$(bin_md5 < "$file" | base64)"
59
+ date="$(date_string)"
60
+
61
+ url="https://$bucket.s3.amazonaws.com/$remote_path"
62
+
63
+ curl -qsSf -T "$file" \
64
+ -H "Authorization: $(authorization)" \
65
+ -H "x-amz-acl: $acl" \
66
+ -H "Date: $date" \
67
+ -H "Content-MD5: $content_md5" \
68
+ -H "Content-Type: $content_type" \
69
+ "$url"
70
+
71
+ echo "$url"
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class CustomRegistrationsControllerTest < ActionController::TestCase
4
+ tests Custom::RegistrationsController
5
+
6
+ include Devise::TestHelpers
7
+
8
+ setup do
9
+ request.env["devise.mapping"] = Devise.mappings[:user]
10
+ @password = 'password'
11
+ @user = create_user(password: @password, password_confirmation: @password).tap(&:confirm!)
12
+ end
13
+
14
+ test "yield resource to block on create success" do
15
+ post :create, { user: { email: "user@example.org", password: "password", password_confirmation: "password" } }
16
+ assert @controller.create_block_called?, "create failed to yield resource to provided block"
17
+ end
18
+
19
+ test "yield resource to block on create failure" do
20
+ post :create, { user: { } }
21
+ assert @controller.create_block_called?, "create failed to yield resource to provided block"
22
+ end
23
+
24
+ test "yield resource to block on update success" do
25
+ sign_in @user
26
+ put :update, { user: { current_password: @password } }
27
+ assert @controller.update_block_called?, "update failed to yield resource to provided block"
28
+ end
29
+
30
+ test "yield resource to block on update failure" do
31
+ sign_in @user
32
+ put :update, { user: { } }
33
+ assert @controller.update_block_called?, "update failed to yield resource to provided block"
34
+ end
35
+ end
@@ -14,81 +14,110 @@ class ControllerAuthenticatableTest < ActionController::TestCase
14
14
  end
15
15
 
16
16
  test 'proxy signed_in?(scope) to authenticate?' do
17
- @mock_warden.expects(:authenticate?).with(:scope => :my_scope)
17
+ @mock_warden.expects(:authenticate?).with(scope: :my_scope)
18
18
  @controller.signed_in?(:my_scope)
19
19
  end
20
20
 
21
21
  test 'proxy signed_in?(nil) to authenticate?' do
22
22
  Devise.mappings.keys.each do |scope| # :user, :admin, :manager
23
- @mock_warden.expects(:authenticate?).with(:scope => scope)
23
+ @mock_warden.expects(:authenticate?).with(scope: scope)
24
24
  end
25
25
  @controller.signed_in?
26
26
  end
27
27
 
28
+ test 'proxy [group]_signed_in? to authenticate? with each scope' do
29
+ [:user, :admin].each do |scope|
30
+ @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
31
+ end
32
+ @controller.commenter_signed_in?
33
+ end
34
+
28
35
  test 'proxy current_user to authenticate with user scope' do
29
- @mock_warden.expects(:authenticate).with(:scope => :user)
36
+ @mock_warden.expects(:authenticate).with(scope: :user)
30
37
  @controller.current_user
31
38
  end
32
39
 
33
40
  test 'proxy current_admin to authenticate with admin scope' do
34
- @mock_warden.expects(:authenticate).with(:scope => :admin)
41
+ @mock_warden.expects(:authenticate).with(scope: :admin)
35
42
  @controller.current_admin
36
43
  end
37
44
 
45
+ test 'proxy current_[group] to authenticate with each scope' do
46
+ [:user, :admin].each do |scope|
47
+ @mock_warden.expects(:authenticate).with(scope: scope).returns(nil)
48
+ end
49
+ @controller.current_commenter
50
+ end
51
+
52
+ test 'proxy current_[plural_group] to authenticate with each scope' do
53
+ [:user, :admin].each do |scope|
54
+ @mock_warden.expects(:authenticate).with(scope: scope)
55
+ end
56
+ @controller.current_commenters
57
+ end
58
+
38
59
  test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do
39
- @mock_warden.expects(:authenticate).with(:scope => :publisher_account)
60
+ @mock_warden.expects(:authenticate).with(scope: :publisher_account)
40
61
  @controller.current_publisher_account
41
62
  end
42
63
 
43
64
  test 'proxy authenticate_user! to authenticate with user scope' do
44
- @mock_warden.expects(:authenticate!).with(:scope => :user)
65
+ @mock_warden.expects(:authenticate!).with(scope: :user)
45
66
  @controller.authenticate_user!
46
67
  end
47
68
 
48
69
  test 'proxy authenticate_user! options to authenticate with user scope' do
49
- @mock_warden.expects(:authenticate!).with(:scope => :user, :recall => "foo")
50
- @controller.authenticate_user!(:recall => "foo")
70
+ @mock_warden.expects(:authenticate!).with(scope: :user, recall: "foo")
71
+ @controller.authenticate_user!(recall: "foo")
51
72
  end
52
73
 
53
74
  test 'proxy authenticate_admin! to authenticate with admin scope' do
54
- @mock_warden.expects(:authenticate!).with(:scope => :admin)
75
+ @mock_warden.expects(:authenticate!).with(scope: :admin)
55
76
  @controller.authenticate_admin!
56
77
  end
57
78
 
79
+ test 'proxy authenticate_[group]! to authenticate!? with each scope' do
80
+ [:user, :admin].each do |scope|
81
+ @mock_warden.expects(:authenticate!).with(scope: scope)
82
+ @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)
83
+ end
84
+ @controller.authenticate_commenter!
85
+ end
86
+
58
87
  test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do
59
- @mock_warden.expects(:authenticate!).with(:scope => :publisher_account)
88
+ @mock_warden.expects(:authenticate!).with(scope: :publisher_account)
60
89
  @controller.authenticate_publisher_account!
61
90
  end
62
91
 
63
92
  test 'proxy user_signed_in? to authenticate with user scope' do
64
- @mock_warden.expects(:authenticate).with(:scope => :user).returns("user")
93
+ @mock_warden.expects(:authenticate).with(scope: :user).returns("user")
65
94
  assert @controller.user_signed_in?
66
95
  end
67
96
 
68
97
  test 'proxy admin_signed_in? to authenticatewith admin scope' do
69
- @mock_warden.expects(:authenticate).with(:scope => :admin)
98
+ @mock_warden.expects(:authenticate).with(scope: :admin)
70
99
  assert_not @controller.admin_signed_in?
71
100
  end
72
101
 
73
102
  test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do
74
- @mock_warden.expects(:authenticate).with(:scope => :publisher_account)
103
+ @mock_warden.expects(:authenticate).with(scope: :publisher_account)
75
104
  @controller.publisher_account_signed_in?
76
105
  end
77
106
 
78
107
  test 'proxy user_session to session scope in warden' do
79
- @mock_warden.expects(:authenticate).with(:scope => :user).returns(true)
108
+ @mock_warden.expects(:authenticate).with(scope: :user).returns(true)
80
109
  @mock_warden.expects(:session).with(:user).returns({})
81
110
  @controller.user_session
82
111
  end
83
112
 
84
113
  test 'proxy admin_session to session scope in warden' do
85
- @mock_warden.expects(:authenticate).with(:scope => :admin).returns(true)
114
+ @mock_warden.expects(:authenticate).with(scope: :admin).returns(true)
86
115
  @mock_warden.expects(:session).with(:admin).returns({})
87
116
  @controller.admin_session
88
117
  end
89
118
 
90
119
  test 'proxy publisher_account_session from namespaced scope to session scope in warden' do
91
- @mock_warden.expects(:authenticate).with(:scope => :publisher_account).returns(true)
120
+ @mock_warden.expects(:authenticate).with(scope: :publisher_account).returns(true)
92
121
  @mock_warden.expects(:session).with(:publisher_account).returns({})
93
122
  @controller.publisher_account_session
94
123
  end
@@ -96,14 +125,14 @@ class ControllerAuthenticatableTest < ActionController::TestCase
96
125
  test 'sign in proxy to set_user on warden' do
97
126
  user = User.new
98
127
  @mock_warden.expects(:user).returns(nil)
99
- @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
128
+ @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
100
129
  @controller.sign_in(:user, user)
101
130
  end
102
131
 
103
132
  test 'sign in accepts a resource as argument' do
104
133
  user = User.new
105
134
  @mock_warden.expects(:user).returns(nil)
106
- @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
135
+ @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
107
136
  @controller.sign_in(user)
108
137
  end
109
138
 
@@ -117,15 +146,15 @@ class ControllerAuthenticatableTest < ActionController::TestCase
117
146
  test 'sign in again when the user is already in only if force is given' do
118
147
  user = User.new
119
148
  @mock_warden.expects(:user).returns(user)
120
- @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
121
- @controller.sign_in(user, :force => true)
149
+ @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
150
+ @controller.sign_in(user, force: true)
122
151
  end
123
152
 
124
153
  test 'sign in accepts bypass as option' do
125
154
  user = User.new
126
155
  @mock_warden.expects(:session_serializer).returns(serializer = mock())
127
156
  serializer.expects(:store).with(user, :user)
128
- @controller.sign_in(user, :bypass => true)
157
+ @controller.sign_in(user, bypass: true)
129
158
  end
130
159
 
131
160
  test 'sign out clears up any signed in user from all scopes' do
@@ -141,18 +170,18 @@ class ControllerAuthenticatableTest < ActionController::TestCase
141
170
 
142
171
  test 'sign out logs out and clears up any signed in user by scope' do
143
172
  user = User.new
144
- @mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(user)
173
+ @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(user)
145
174
  @mock_warden.expects(:logout).with(:user).returns(true)
146
- @mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
175
+ @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
147
176
  @controller.instance_variable_set(:@current_user, user)
148
177
  @controller.sign_out(:user)
149
178
  assert_equal nil, @controller.instance_variable_get(:@current_user)
150
179
  end
151
180
 
152
181
  test 'sign out accepts a resource as argument' do
153
- @mock_warden.expects(:user).with(:scope => :user, :run_callbacks => false).returns(true)
182
+ @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(true)
154
183
  @mock_warden.expects(:logout).with(:user).returns(true)
155
- @mock_warden.expects(:clear_strategies_cache!).with(:scope => :user).returns(true)
184
+ @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)
156
185
  @controller.sign_out(User.new)
157
186
  end
158
187
 
@@ -187,6 +216,35 @@ class ControllerAuthenticatableTest < ActionController::TestCase
187
216
  assert_nil @controller.session[:"user_return_to"]
188
217
  end
189
218
 
219
+ test 'store location for stores a location to redirect back to' do
220
+ assert_nil @controller.stored_location_for(:user)
221
+ @controller.store_location_for(:user, "/foo.bar")
222
+ assert_equal "/foo.bar", @controller.stored_location_for(:user)
223
+ end
224
+
225
+ test 'store bad location for stores a location to redirect back to' do
226
+ assert_nil @controller.stored_location_for(:user)
227
+ @controller.store_location_for(:user, "/foo.bar\">Carry")
228
+ assert_nil @controller.stored_location_for(:user)
229
+ end
230
+
231
+ test 'store location for accepts a resource as argument' do
232
+ @controller.store_location_for(User.new, "/foo.bar")
233
+ assert_equal "/foo.bar", @controller.stored_location_for(User.new)
234
+ end
235
+
236
+ test 'store location for stores paths' do
237
+ @controller.store_location_for(:user, "//host/foo.bar")
238
+ assert_equal "/foo.bar", @controller.stored_location_for(:user)
239
+ @controller.store_location_for(:user, "///foo.bar")
240
+ assert_equal "/foo.bar", @controller.stored_location_for(:user)
241
+ end
242
+
243
+ test 'store location for stores query string' do
244
+ @controller.store_location_for(:user, "/foo?bar=baz")
245
+ assert_equal "/foo?bar=baz", @controller.stored_location_for(:user)
246
+ end
247
+
190
248
  test 'after sign in path defaults to root path if none by was specified for the given scope' do
191
249
  assert_equal root_path, @controller.after_sign_in_path_for(:user)
192
250
  end
@@ -204,7 +262,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
204
262
  user = User.new
205
263
  @controller.session[:user_return_to] = "/foo.bar"
206
264
  @mock_warden.expects(:user).with(:user).returns(nil)
207
- @mock_warden.expects(:set_user).with(user, :scope => :user).returns(true)
265
+ @mock_warden.expects(:set_user).with(user, scope: :user).returns(true)
208
266
  @controller.expects(:redirect_to).with("/foo.bar")
209
267
  @controller.sign_in_and_redirect(user)
210
268
  end
@@ -212,7 +270,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
212
270
  test 'sign in and redirect uses the configured after sign in path' do
213
271
  admin = Admin.new
214
272
  @mock_warden.expects(:user).with(:admin).returns(nil)
215
- @mock_warden.expects(:set_user).with(admin, :scope => :admin).returns(true)
273
+ @mock_warden.expects(:set_user).with(admin, scope: :admin).returns(true)
216
274
  @controller.expects(:redirect_to).with(admin_root_path)
217
275
  @controller.sign_in_and_redirect(admin)
218
276
  end
@@ -226,10 +284,10 @@ class ControllerAuthenticatableTest < ActionController::TestCase
226
284
  end
227
285
 
228
286
  test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do
229
- swap Devise, :sign_out_all_scopes => false do
230
- @mock_warden.expects(:user).with(:scope => :admin, :run_callbacks => false).returns(true)
287
+ swap Devise, sign_out_all_scopes: false do
288
+ @mock_warden.expects(:user).with(scope: :admin, run_callbacks: false).returns(true)
231
289
  @mock_warden.expects(:logout).with(:admin).returns(true)
232
- @mock_warden.expects(:clear_strategies_cache!).with(:scope => :admin).returns(true)
290
+ @mock_warden.expects(:clear_strategies_cache!).with(scope: :admin).returns(true)
233
291
  @controller.expects(:redirect_to).with(admin_root_path)
234
292
  @controller.instance_eval "def after_sign_out_path_for(resource); admin_root_path; end"
235
293
  @controller.sign_out_and_redirect(:admin)
@@ -237,7 +295,7 @@ class ControllerAuthenticatableTest < ActionController::TestCase
237
295
  end
238
296
 
239
297
  test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do
240
- swap Devise, :sign_out_all_scopes => true do
298
+ swap Devise, sign_out_all_scopes: true do
241
299
  @mock_warden.expects(:user).times(Devise.mappings.size)
242
300
  @mock_warden.expects(:logout).with().returns(true)
243
301
  @mock_warden.expects(:clear_strategies_cache!).with().returns(true)
@@ -51,11 +51,11 @@ class HelpersTest < ActionController::TestCase
51
51
  end
52
52
 
53
53
  test 'resources methods are not controller actions' do
54
- assert @controller.class.action_methods.empty?
54
+ assert @controller.class.action_methods.delete_if { |m| m.include? 'commenter' }.empty?
55
55
  end
56
56
 
57
57
  test 'require no authentication tests current mapping' do
58
- @mock_warden.expects(:authenticate?).with(:rememberable, :scope => :user).returns(true)
58
+ @mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
59
59
  @mock_warden.expects(:user).with(:user).returns(User.new)
60
60
  @controller.expects(:redirect_to).with(root_path)
61
61
  @controller.send :require_no_authentication
@@ -71,7 +71,7 @@ class HelpersTest < ActionController::TestCase
71
71
  end
72
72
 
73
73
  test 'require no authentication sets a flash message' do
74
- @mock_warden.expects(:authenticate?).with(:rememberable, :scope => :user).returns(true)
74
+ @mock_warden.expects(:authenticate?).with(:rememberable, scope: :user).returns(true)
75
75
  @mock_warden.expects(:user).with(:user).returns(User.new)
76
76
  @controller.expects(:redirect_to).with(root_path)
77
77
  @controller.send :require_no_authentication
@@ -79,7 +79,7 @@ class HelpersTest < ActionController::TestCase
79
79
  end
80
80
 
81
81
  test 'signed in resource returns signed in resource for current scope' do
82
- @mock_warden.expects(:authenticate).with(:scope => :user).returns(User.new)
82
+ @mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)
83
83
  assert_kind_of User, @controller.signed_in_resource
84
84
  end
85
85
 
@@ -100,21 +100,24 @@ class HelpersTest < ActionController::TestCase
100
100
  end
101
101
 
102
102
  test 'uses custom i18n options' do
103
- @controller.stubs(:devise_i18n_options).returns(:default => "devise custom options")
103
+ @controller.stubs(:devise_i18n_options).returns(default: "devise custom options")
104
104
  @controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions
105
105
  assert_equal 'devise custom options', flash[:notice]
106
106
  end
107
107
 
108
108
  test 'allows custom i18n options to override resource_name' do
109
109
  I18n.expects(:t).with("custom_resource_name.confirmed", anything)
110
- @controller.stubs(:devise_i18n_options).returns(:resource_name => "custom_resource_name")
110
+ @controller.stubs(:devise_i18n_options).returns(resource_name: "custom_resource_name")
111
111
  @controller.send :set_flash_message, :notice, :confirmed
112
112
  end
113
113
 
114
114
  test 'navigational_formats not returning a wild card' do
115
115
  MyController.send(:public, :navigational_formats)
116
- Devise.navigational_formats = [:"*/*", :html]
117
- assert_not @controller.navigational_formats.include?(:"*/*")
116
+
117
+ swap Devise, navigational_formats: ['*/*', :html] do
118
+ assert_not @controller.navigational_formats.include?("*/*")
119
+ end
120
+
118
121
  MyController.send(:protected, :navigational_formats)
119
122
  end
120
123
  end
@@ -12,7 +12,7 @@ class PasswordsControllerTest < ActionController::TestCase
12
12
 
13
13
  def put_update_with_params
14
14
  put :update, "user" => {
15
- "reset_password_token" => @raw, "password" => "123456", "password_confirmation" => "123456"
15
+ "reset_password_token" => @raw, "password" => "1234567", "password_confirmation" => "1234567"
16
16
  }
17
17
  end
18
18
 
@@ -5,21 +5,25 @@ class SessionsControllerTest < ActionController::TestCase
5
5
  include Devise::TestHelpers
6
6
 
7
7
  test "#create doesn't raise unpermitted params when sign in fails" do
8
- ActiveSupport::Notifications.subscribe /unpermitted_parameters/ do |name, start, finish, id, payload|
9
- flunk "Unpermitted params: #{payload}"
8
+ begin
9
+ subscriber = ActiveSupport::Notifications.subscribe /unpermitted_parameters/ do |name, start, finish, id, payload|
10
+ flunk "Unpermitted params: #{payload}"
11
+ end
12
+ request.env["devise.mapping"] = Devise.mappings[:user]
13
+ request.session["user_return_to"] = 'foo.bar'
14
+ create_user
15
+ post :create, user: {
16
+ email: "wrong@email.com",
17
+ password: "wrongpassword"
18
+ }
19
+ assert_equal 200, @response.status
20
+ ensure
21
+ ActiveSupport::Notifications.unsubscribe(subscriber)
10
22
  end
11
- request.env["devise.mapping"] = Devise.mappings[:user]
12
- request.session["user_return_to"] = 'foo.bar'
13
- create_user
14
- post :create, :user => {
15
- :email => "wrong@email.com",
16
- :password => "wrongpassword"
17
- }
18
- assert_equal 200, @response.status
19
23
  end
20
24
 
21
25
  test "#create works even with scoped views" do
22
- swap Devise, :scoped_views => true do
26
+ swap Devise, scoped_views: true do
23
27
  request.env["devise.mapping"] = Devise.mappings[:user]
24
28
  post :create
25
29
  assert_equal 200, @response.status
@@ -33,9 +37,9 @@ class SessionsControllerTest < ActionController::TestCase
33
37
 
34
38
  user = create_user
35
39
  user.confirm!
36
- post :create, :user => {
37
- :email => user.email,
38
- :password => user.password
40
+ post :create, user: {
41
+ email: user.email,
42
+ password: user.password
39
43
  }
40
44
 
41
45
  assert_nil request.session["user_return_to"]
@@ -47,9 +51,9 @@ class SessionsControllerTest < ActionController::TestCase
47
51
 
48
52
  user = create_user
49
53
  user.confirm!
50
- post :create, :format => 'json', :user => {
51
- :email => user.email,
52
- :password => user.password
54
+ post :create, format: 'json', user: {
55
+ email: user.email,
56
+ password: user.password
53
57
  }
54
58
 
55
59
  assert_equal 'foo.bar', request.session["user_return_to"]
@@ -57,9 +61,9 @@ class SessionsControllerTest < ActionController::TestCase
57
61
 
58
62
  test "#create doesn't raise exception after Warden authentication fails when TestHelpers included" do
59
63
  request.env["devise.mapping"] = Devise.mappings[:user]
60
- post :create, :user => {
61
- :email => "nosuchuser@example.com",
62
- :password => "wevdude"
64
+ post :create, user: {
65
+ email: "nosuchuser@example.com",
66
+ password: "wevdude"
63
67
  }
64
68
  assert_equal 200, @response.status
65
69
  assert_template "devise/sessions/new"
@@ -69,12 +73,12 @@ class SessionsControllerTest < ActionController::TestCase
69
73
  request.env["devise.mapping"] = Devise.mappings[:user]
70
74
  user = create_user
71
75
  user.confirm!
72
- post :create, :format => 'json', :user => {
73
- :email => user.email,
74
- :password => user.password
76
+ post :create, format: 'json', user: {
77
+ email: user.email,
78
+ password: user.password
75
79
  }
76
80
 
77
- delete :destroy, :format => 'json'
81
+ delete :destroy, format: 'json'
78
82
  assert flash[:notice].blank?, "flash[:notice] should be blank, not #{flash[:notice].inspect}"
79
83
  assert_equal 204, @response.status
80
84
  end
@@ -88,7 +92,7 @@ class SessionsControllerTest < ActionController::TestCase
88
92
 
89
93
  begin
90
94
  assert_nothing_raised ActiveModel::MassAssignmentSecurity::Error do
91
- get :new, :user => { :email => "allez viens!" }
95
+ get :new, user: { email: "allez viens!" }
92
96
  end
93
97
  ensure
94
98
  ActiveRecord::Base.mass_assignment_sanitizer = :logger
@@ -14,10 +14,10 @@ class RoutesTest < ActionController::TestCase
14
14
  send(:"#{prepend_path}user_#{name}_url")
15
15
 
16
16
  # Default url params
17
- assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, :param => 123),
18
- send(:"#{prepend_path}user_#{name}_path", :param => 123)
19
- assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, :param => 123),
20
- send(:"#{prepend_path}user_#{name}_url", :param => 123)
17
+ assert_equal @controller.send(:"#{prepend_path}#{name}_path", :user, param: 123),
18
+ send(:"#{prepend_path}user_#{name}_path", param: 123)
19
+ assert_equal @controller.send(:"#{prepend_path}#{name}_url", :user, param: 123),
20
+ send(:"#{prepend_path}user_#{name}_url", param: 123)
21
21
 
22
22
  @request.path = nil
23
23
  # With an object
@@ -14,6 +14,6 @@ class DelegatorTest < ActiveSupport::TestCase
14
14
  end
15
15
 
16
16
  test 'failure_app returns associated failure app by scope in the given environment' do
17
- assert_kind_of Proc, delegator.failure_app({"warden.options" => {:scope => "manager"}})
17
+ assert_kind_of Proc, delegator.failure_app({"warden.options" => {scope: "manager"}})
18
18
  end
19
19
  end
data/test/devise_test.rb CHANGED
@@ -3,10 +3,10 @@ require 'test_helper'
3
3
  module Devise
4
4
  def self.yield_and_restore
5
5
  @@warden_configured = nil
6
- c, b = @@warden_config, @@warden_config_block
6
+ c, b = @@warden_config, @@warden_config_blocks
7
7
  yield
8
8
  ensure
9
- @@warden_config, @@warden_config_block = c, b
9
+ @@warden_config, @@warden_config_blocks = c, b
10
10
  end
11
11
  end
12
12
 
@@ -23,7 +23,7 @@ class DeviseTest < ActiveSupport::TestCase
23
23
  end
24
24
 
25
25
  test 'model options can be configured through Devise' do
26
- swap Devise, :allow_unconfirmed_access_for => 113, :pepper => "foo" do
26
+ swap Devise, allow_unconfirmed_access_for: 113, pepper: "foo" do
27
27
  assert_equal 113, Devise.allow_unconfirmed_access_for
28
28
  assert_equal "foo", Devise.pepper
29
29
  end
@@ -42,14 +42,27 @@ class DeviseTest < ActiveSupport::TestCase
42
42
 
43
43
  test 'warden manager user configuration through a block' do
44
44
  Devise.yield_and_restore do
45
- @executed = false
45
+ executed = false
46
46
  Devise.warden do |config|
47
- @executed = true
47
+ executed = true
48
48
  assert_kind_of Warden::Config, config
49
49
  end
50
50
 
51
51
  Devise.configure_warden!
52
- assert @executed
52
+ assert executed
53
+ end
54
+ end
55
+
56
+ test 'warden manager user configuration through multiple blocks' do
57
+ Devise.yield_and_restore do
58
+ executed = 0
59
+
60
+ 3.times do
61
+ Devise.warden { |config| executed += 1 }
62
+ end
63
+
64
+ Devise.configure_warden!
65
+ assert_equal 3, executed
53
66
  end
54
67
  end
55
68
 
@@ -60,12 +73,12 @@ class DeviseTest < ActiveSupport::TestCase
60
73
  assert_not defined?(Devise::Models::Coconut)
61
74
  Devise::ALL.delete(:coconut)
62
75
 
63
- assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) }
76
+ assert_nothing_raised(Exception) { Devise.add_module(:banana, strategy: :fruits) }
64
77
  assert_equal :fruits, Devise::STRATEGIES[:banana]
65
78
  Devise::ALL.delete(:banana)
66
79
  Devise::STRATEGIES.delete(:banana)
67
80
 
68
- assert_nothing_raised(Exception) { Devise.add_module(:kivi, :controller => :fruits) }
81
+ assert_nothing_raised(Exception) { Devise.add_module(:kivi, controller: :fruits) }
69
82
  assert_equal :fruits, Devise::CONTROLLERS[:kivi]
70
83
  Devise::ALL.delete(:kivi)
71
84
  Devise::CONTROLLERS.delete(:kivi)