devise 1.1.pre4 → 1.1.rc0

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.
Files changed (122) hide show
  1. data/CHANGELOG.rdoc +31 -2
  2. data/Gemfile +15 -6
  3. data/README.rdoc +12 -16
  4. data/Rakefile +2 -2
  5. data/TODO +2 -1
  6. data/app/controllers/devise/confirmations_controller.rb +1 -1
  7. data/app/controllers/devise/passwords_controller.rb +2 -3
  8. data/app/controllers/devise/registrations_controller.rb +5 -5
  9. data/app/controllers/devise/sessions_controller.rb +5 -27
  10. data/app/controllers/devise/unlocks_controller.rb +9 -1
  11. data/app/models/devise/mailer.rb +17 -11
  12. data/app/views/devise/confirmations/new.html.erb +1 -1
  13. data/app/views/devise/passwords/edit.html.erb +1 -1
  14. data/app/views/devise/passwords/new.html.erb +1 -1
  15. data/app/views/devise/registrations/edit.html.erb +2 -2
  16. data/app/views/devise/registrations/new.html.erb +2 -2
  17. data/app/views/devise/sessions/new.html.erb +2 -2
  18. data/app/views/devise/shared/_links.erb +5 -5
  19. data/app/views/devise/unlocks/new.html.erb +1 -1
  20. data/config/locales/en.yml +4 -9
  21. data/lib/devise.rb +83 -42
  22. data/lib/devise/controllers/helpers.rb +6 -18
  23. data/lib/devise/controllers/internal_helpers.rb +11 -12
  24. data/lib/devise/controllers/scoped_views.rb +2 -2
  25. data/lib/devise/controllers/url_helpers.rb +1 -1
  26. data/lib/devise/failure_app.rb +56 -16
  27. data/lib/devise/hooks/activatable.rb +18 -6
  28. data/lib/devise/hooks/rememberable.rb +36 -27
  29. data/lib/devise/hooks/timeoutable.rb +1 -1
  30. data/lib/devise/hooks/trackable.rb +4 -2
  31. data/lib/devise/mapping.rb +19 -14
  32. data/lib/devise/models.rb +12 -3
  33. data/lib/devise/models/authenticatable.rb +19 -95
  34. data/lib/devise/models/confirmable.rb +14 -20
  35. data/lib/devise/models/database_authenticatable.rb +99 -0
  36. data/lib/devise/models/lockable.rb +53 -39
  37. data/lib/devise/models/recoverable.rb +3 -3
  38. data/lib/devise/models/rememberable.rb +5 -10
  39. data/lib/devise/models/token_authenticatable.rb +18 -25
  40. data/lib/devise/models/validatable.rb +14 -9
  41. data/lib/devise/modules.rb +7 -8
  42. data/lib/devise/orm/active_record.rb +1 -1
  43. data/lib/devise/orm/data_mapper.rb +20 -7
  44. data/lib/devise/orm/mongoid.rb +40 -0
  45. data/lib/devise/rails.rb +26 -3
  46. data/lib/devise/rails/routes.rb +18 -16
  47. data/lib/devise/rails/warden_compat.rb +2 -2
  48. data/lib/devise/schema.rb +45 -18
  49. data/lib/devise/strategies/authenticatable.rb +92 -21
  50. data/lib/devise/strategies/base.rb +6 -3
  51. data/lib/devise/strategies/database_authenticatable.rb +20 -0
  52. data/lib/devise/strategies/rememberable.rb +10 -6
  53. data/lib/devise/strategies/token_authenticatable.rb +28 -19
  54. data/lib/devise/test_helpers.rb +5 -1
  55. data/lib/devise/version.rb +1 -1
  56. data/lib/generators/devise/devise_generator.rb +15 -5
  57. data/lib/generators/devise/templates/migration.rb +2 -2
  58. data/lib/generators/devise_install/templates/devise.rb +37 -16
  59. data/lib/generators/devise_views/devise_views_generator.rb +51 -4
  60. data/test/controllers/helpers_test.rb +16 -8
  61. data/test/controllers/internal_helpers_test.rb +6 -1
  62. data/test/controllers/url_helpers_test.rb +10 -10
  63. data/test/devise_test.rb +13 -17
  64. data/test/encryptors_test.rb +2 -0
  65. data/test/failure_app_test.rb +72 -23
  66. data/test/integration/confirmable_test.rb +4 -4
  67. data/test/integration/{authenticatable_test.rb → database_authenticatable_test.rb} +35 -17
  68. data/test/integration/http_authenticatable_test.rb +3 -3
  69. data/test/integration/lockable_test.rb +28 -8
  70. data/test/integration/recoverable_test.rb +3 -3
  71. data/test/integration/registerable_test.rb +6 -4
  72. data/test/integration/rememberable_test.rb +11 -4
  73. data/test/integration/timeoutable_test.rb +4 -4
  74. data/test/integration/token_authenticatable_test.rb +46 -10
  75. data/test/integration/trackable_test.rb +2 -2
  76. data/test/mailers/confirmation_instructions_test.rb +5 -5
  77. data/test/mailers/reset_password_instructions_test.rb +5 -5
  78. data/test/mailers/unlock_instructions_test.rb +5 -5
  79. data/test/mapping_test.rb +15 -14
  80. data/test/models/confirmable_test.rb +9 -32
  81. data/test/models/{authenticatable_test.rb → database_authenticatable_test.rb} +2 -34
  82. data/test/models/lockable_test.rb +48 -66
  83. data/test/models/recoverable_test.rb +8 -8
  84. data/test/models/rememberable_test.rb +6 -28
  85. data/test/models/timeoutable_test.rb +1 -1
  86. data/test/models/token_authenticatable_test.rb +1 -8
  87. data/test/models/trackable_test.rb +1 -1
  88. data/test/models/validatable_test.rb +2 -2
  89. data/test/models_test.rb +16 -2
  90. data/test/orm/active_record.rb +1 -22
  91. data/test/orm/data_mapper.rb +1 -0
  92. data/test/orm/mongoid.rb +10 -0
  93. data/test/rails_app/app/active_record/admin.rb +1 -5
  94. data/test/rails_app/app/controllers/application_controller.rb +2 -0
  95. data/test/rails_app/app/controllers/sessions_controller.rb +1 -1
  96. data/test/rails_app/app/data_mapper/admin.rb +13 -0
  97. data/test/rails_app/app/data_mapper/user.rb +24 -0
  98. data/test/rails_app/app/mongoid/admin.rb +15 -0
  99. data/test/rails_app/app/mongoid/user.rb +21 -0
  100. data/test/rails_app/config/application.rb +10 -5
  101. data/test/rails_app/config/boot.rb +5 -1
  102. data/test/rails_app/config/initializers/devise.rb +1 -1
  103. data/test/rails_app/config/routes.rb +4 -1
  104. data/test/rails_app/db/migrate/20100401102949_create_tables.rb +27 -0
  105. data/test/rails_app/db/schema.rb +86 -0
  106. data/test/routes_test.rb +3 -3
  107. data/test/support/assertions.rb +2 -0
  108. data/test/support/helpers.rb +2 -0
  109. data/test/support/integration.rb +4 -7
  110. data/test/support/webrat/integrations/rails.rb +2 -1
  111. data/test/test_helper.rb +5 -2
  112. data/test/test_helpers_test.rb +4 -4
  113. metadata +36 -21
  114. data/lib/devise/models/http_authenticatable.rb +0 -19
  115. data/lib/devise/orm/mongo_mapper.rb +0 -49
  116. data/lib/devise/strategies/http_authenticatable.rb +0 -47
  117. data/test/models/http_authenticatable_test.rb +0 -19
  118. data/test/orm/mongo_mapper.rb +0 -12
  119. data/test/rails_app/app/mongo_mapper/admin.rb +0 -10
  120. data/test/rails_app/app/mongo_mapper/user.rb +0 -11
  121. data/test/rails_app/config/initializers/cookie_verification_secret.rb +0 -7
  122. data/test/rails_app/config/initializers/session_store.rb +0 -15
@@ -1,8 +1,11 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  module Devise
4
- def self.clean_warden_config!
5
- @warden_config = nil
4
+ def self.yield_and_restore
5
+ c, b = @@warden_config, @@warden_config_block
6
+ yield
7
+ ensure
8
+ @@warden_config, @@warden_config_block = c, b
6
9
  end
7
10
  end
8
11
 
@@ -20,28 +23,21 @@ class DeviseTest < ActiveSupport::TestCase
20
23
  end
21
24
  end
22
25
 
23
- test 'warden manager configuration' do
24
- config = Warden::Config.new
25
- Devise.configure_warden(config)
26
-
27
- assert_equal Devise::FailureApp, config.failure_app
28
- assert_equal [:rememberable, :token_authenticatable, :http_authenticatable, :authenticatable], config.default_strategies
29
- assert_equal :user, config.default_scope
30
- assert config.silence_missing_strategies?
26
+ test 'stores warden configuration' do
27
+ assert_equal Devise::FailureApp, Devise.warden_config.failure_app
28
+ assert_equal :user, Devise.warden_config.default_scope
31
29
  end
32
30
 
33
31
  test 'warden manager user configuration through a block' do
34
- begin
32
+ Devise.yield_and_restore do
35
33
  @executed = false
36
34
  Devise.warden do |config|
37
35
  @executed = true
38
36
  assert_kind_of Warden::Config, config
39
37
  end
40
38
 
41
- Devise.configure_warden(Warden::Config.new)
39
+ Devise.configure_warden!
42
40
  assert @executed
43
- ensure
44
- Devise.clean_warden_config!
45
41
  end
46
42
  end
47
43
 
@@ -52,8 +48,8 @@ class DeviseTest < ActiveSupport::TestCase
52
48
  assert_not defined?(Devise::Models::Coconut)
53
49
  Devise::ALL.delete(:coconut)
54
50
 
55
- assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => true) }
56
- assert_equal 1, Devise::STRATEGIES.select { |v| v == :banana }.size
51
+ assert_nothing_raised(Exception) { Devise.add_module(:banana, :strategy => :fruits) }
52
+ assert_equal :fruits, Devise::STRATEGIES[:banana]
57
53
  Devise::ALL.delete(:banana)
58
54
  Devise::STRATEGIES.delete(:banana)
59
55
 
@@ -1,3 +1,5 @@
1
+ require 'test_helper'
2
+
1
3
  class Encryptors < ActiveSupport::TestCase
2
4
  test 'should match a password created by authlogic' do
3
5
  authlogic = "b623c3bc9c775b0eb8edb218a382453396fec4146422853e66ecc4b6bc32d7162ee42074dcb5f180a770dc38b5df15812f09bbf497a4a1b95fe5e7d2b8eb7eb4"
@@ -1,7 +1,10 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
  require 'ostruct'
3
3
 
4
4
  class FailureTest < ActiveSupport::TestCase
5
+ def self.context(name, &block)
6
+ instance_eval(&block)
7
+ end
5
8
 
6
9
  def call_failure(env_params={})
7
10
  env = {
@@ -9,38 +12,84 @@ class FailureTest < ActiveSupport::TestCase
9
12
  'REQUEST_URI' => 'http://test.host/',
10
13
  'HTTP_HOST' => 'test.host',
11
14
  'REQUEST_METHOD' => 'GET',
12
- 'rack.session' => {}
15
+ 'rack.session' => {},
16
+ 'rack.input' => "",
17
+ 'warden' => OpenStruct.new(:message => nil)
13
18
  }.merge!(env_params)
14
- Devise::FailureApp.call(env)
19
+
20
+ @response = Devise::FailureApp.call(env).to_a
21
+ @request = ActionDispatch::Request.new(env)
15
22
  end
16
23
 
17
- test 'return 302 status' do
18
- assert_equal 302, call_failure.first
24
+ def call_failure_with_http(env_params={})
25
+ env = { "HTTP_AUTHORIZATION" => "Basic #{ActiveSupport::Base64.encode64("foo:bar")}" }
26
+ call_failure(env_params.merge!(env))
19
27
  end
20
28
 
21
- test 'return to the default redirect location' do
22
- assert_equal 'http://test.host/users/sign_in?unauthenticated=true', call_failure.second['Location']
23
- end
29
+ context 'When redirecting' do
30
+ test 'return 302 status' do
31
+ call_failure
32
+ assert_equal 302, @response.first
33
+ end
24
34
 
25
- test 'uses the proxy failure message' do
26
- warden = OpenStruct.new(:message => :test)
27
- location = call_failure('warden' => warden).second['Location']
28
- assert_equal 'http://test.host/users/sign_in?test=true', location
29
- end
35
+ test 'return to the default redirect location' do
36
+ call_failure
37
+ assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]
38
+ assert_equal 'http://test.host/users/sign_in', @response.second['Location']
39
+ end
40
+
41
+ test 'uses the proxy failure message as symbol' do
42
+ call_failure('warden' => OpenStruct.new(:message => :test))
43
+ assert_equal 'test', @request.flash[:alert]
44
+ assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
45
+ end
30
46
 
31
- test 'uses the given message' do
32
- warden = OpenStruct.new(:message => 'Hello world')
33
- location = call_failure('warden' => warden).second['Location']
34
- assert_equal 'http://test.host/users/sign_in?message=Hello+world', location
47
+ test 'uses the proxy failure message as string' do
48
+ call_failure('warden' => OpenStruct.new(:message => 'Hello world'))
49
+ assert_equal 'Hello world', @request.flash[:alert]
50
+ assert_equal 'http://test.host/users/sign_in', @response.second["Location"]
51
+ end
52
+
53
+ test 'set content type to default text/html' do
54
+ call_failure
55
+ assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']
56
+ end
57
+
58
+ test 'setup a default message' do
59
+ call_failure
60
+ assert_match /You are being/, @response.last.body
61
+ assert_match /redirected/, @response.last.body
62
+ assert_match /users\/sign_in/, @response.last.body
63
+ end
35
64
  end
36
65
 
37
- test 'set content type to default text/html' do
38
- assert_equal 'text/html; charset=utf-8', call_failure.second['Content-Type']
66
+ context 'For HTTP request' do
67
+ test 'return 401 status' do
68
+ call_failure_with_http
69
+ assert_equal 401, @response.first
70
+ end
71
+
72
+ test 'return WWW-authenticate headers' do
73
+ call_failure_with_http
74
+ assert_equal 'Basic realm="Application"', @response.second["WWW-Authenticate"]
75
+ end
76
+
77
+ test 'uses the proxy failure message as response body' do
78
+ call_failure_with_http('warden' => OpenStruct.new(:message => :invalid))
79
+ assert_equal 'Invalid email or password.', @response.third.body
80
+ end
39
81
  end
40
82
 
41
- test 'setup a default message' do
42
- assert_match /You are being/, call_failure.last.body
43
- assert_match /redirected/, call_failure.last.body
44
- assert_match /\?unauthenticated=true/, call_failure.last.body
83
+ context 'With recall' do
84
+ test 'calls the original controller' do
85
+ env = {
86
+ "action_dispatch.request.parameters" => { :controller => "devise/sessions" },
87
+ "warden.options" => { :recall => "new", :attempted_path => "/users/sign_in" },
88
+ "warden" => stub_everything
89
+ }
90
+ call_failure(env)
91
+ assert @response.third.body.include?('<h2>Sign in</h2>')
92
+ assert @response.third.body.include?('Invalid email or password.')
93
+ end
45
94
  end
46
95
  end
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class ConfirmationTest < ActionController::IntegrationTest
4
4
 
@@ -11,7 +11,7 @@ class ConfirmationTest < ActionController::IntegrationTest
11
11
  ActionMailer::Base.deliveries.clear
12
12
 
13
13
  visit new_user_session_path
14
- click_link 'Didn\'t receive confirmation instructions?'
14
+ click_link "Didn't receive confirmation instructions?"
15
15
 
16
16
  fill_in 'email', :with => user.email
17
17
  click_button 'Resend confirmation instructions'
@@ -88,9 +88,9 @@ class ConfirmationTest < ActionController::IntegrationTest
88
88
 
89
89
  test 'error message is configurable by resource name' do
90
90
  store_translations :en, :devise => {
91
- :sessions => { :admin => { :unconfirmed => "Not confirmed user" } }
91
+ :failure => { :user => { :unconfirmed => "Not confirmed user" } }
92
92
  } do
93
- get new_admin_session_path(:unconfirmed => true)
93
+ sign_in_as_user(:confirm => false)
94
94
  assert_contain 'Not confirmed user'
95
95
  end
96
96
  end
@@ -1,6 +1,6 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
- class AuthenticationSanityTest < ActionController::IntegrationTest
3
+ class DatabaseAuthenticationSanityTest < ActionController::IntegrationTest
4
4
  test 'home should be accessible without sign in' do
5
5
  visit '/'
6
6
  assert_response :success
@@ -50,7 +50,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
50
50
  test 'not signed in as admin should not be able to access admins actions' do
51
51
  get admins_path
52
52
 
53
- assert_redirected_to new_admin_session_path(:unauthenticated => true)
53
+ assert_redirected_to new_admin_session_path
54
54
  assert_not warden.authenticated?(:admin)
55
55
  end
56
56
 
@@ -60,7 +60,7 @@ class AuthenticationSanityTest < ActionController::IntegrationTest
60
60
  assert_not warden.authenticated?(:admin)
61
61
 
62
62
  get admins_path
63
- assert_redirected_to new_admin_session_path(:unauthenticated => true)
63
+ assert_redirected_to new_admin_session_path
64
64
  end
65
65
 
66
66
  test 'signed in as admin should be able to access admin actions' do
@@ -134,7 +134,7 @@ class AuthenticationTest < ActionController::IntegrationTest
134
134
  end
135
135
 
136
136
  test 'error message is configurable by resource name' do
137
- store_translations :en, :devise => { :sessions => { :admin => { :invalid => "Invalid credentials" } } } do
137
+ store_translations :en, :devise => { :failure => { :admin => { :invalid => "Invalid credentials" } } } do
138
138
  sign_in_as_admin do
139
139
  fill_in 'password', :with => 'abcdef'
140
140
  end
@@ -146,7 +146,7 @@ class AuthenticationTest < ActionController::IntegrationTest
146
146
  test 'redirect from warden shows sign in or sign up message' do
147
147
  get admins_path
148
148
 
149
- warden_path = new_admin_session_path(:unauthenticated => true)
149
+ warden_path = new_admin_session_path
150
150
  assert_redirected_to warden_path
151
151
 
152
152
  get warden_path
@@ -157,35 +157,35 @@ class AuthenticationTest < ActionController::IntegrationTest
157
157
  sign_in_as_user
158
158
 
159
159
  assert_template 'home/index'
160
- assert_nil session[:"user.return_to"]
160
+ assert_nil session[:"user_return_to"]
161
161
  end
162
162
 
163
163
  test 'redirect to requested url after sign in' do
164
164
  get users_path
165
- assert_redirected_to new_user_session_path(:unauthenticated => true)
166
- assert_equal users_path, session[:"user.return_to"]
165
+ assert_redirected_to new_user_session_path
166
+ assert_equal users_path, session[:"user_return_to"]
167
167
 
168
168
  follow_redirect!
169
169
  sign_in_as_user :visit => false
170
170
 
171
171
  assert_template 'users/index'
172
- assert_nil session[:"user.return_to"]
172
+ assert_nil session[:"user_return_to"]
173
173
  end
174
174
 
175
175
  test 'redirect to last requested url overwriting the stored return_to option' do
176
176
  get expire_user_path(create_user)
177
- assert_redirected_to new_user_session_path(:unauthenticated => true)
178
- assert_equal expire_user_path(create_user), session[:"user.return_to"]
177
+ assert_redirected_to new_user_session_path
178
+ assert_equal expire_user_path(create_user), session[:"user_return_to"]
179
179
 
180
180
  get users_path
181
- assert_redirected_to new_user_session_path(:unauthenticated => true)
182
- assert_equal users_path, session[:"user.return_to"]
181
+ assert_redirected_to new_user_session_path
182
+ assert_equal users_path, session[:"user_return_to"]
183
183
 
184
184
  follow_redirect!
185
185
  sign_in_as_user :visit => false
186
186
 
187
187
  assert_template 'users/index'
188
- assert_nil session[:"user.return_to"]
188
+ assert_nil session[:"user_return_to"]
189
189
  end
190
190
 
191
191
  test 'redirect to configured home path for a given scope after sign in' do
@@ -199,7 +199,7 @@ class AuthenticationTest < ActionController::IntegrationTest
199
199
 
200
200
  User.destroy_all
201
201
  get '/users'
202
- assert_redirected_to '/users/sign_in?unauthenticated=true'
202
+ assert_redirected_to new_user_session_path
203
203
  end
204
204
 
205
205
  test 'allows session to be set by a given scope' do
@@ -226,7 +226,7 @@ class AuthenticationTest < ActionController::IntegrationTest
226
226
  end
227
227
 
228
228
  assert_match /Special user view/, response.body
229
- assert !Devise::PasswordsController.scoped_views
229
+ assert !Devise::PasswordsController.scoped_views?
230
230
  ensure
231
231
  Devise::SessionsController.send :remove_instance_variable, :@scoped_views
232
232
  end
@@ -265,6 +265,24 @@ class AuthenticationTest < ActionController::IntegrationTest
265
265
  assert_contain 'Welcome to "sessions/new" view!'
266
266
  end
267
267
 
268
+ # Custom strategy invoking custom!
269
+ test 'custom strategy invoking custom on sign up bevahes as expected' do
270
+ Warden::Strategies.add(:custom) do
271
+ def authenticate!
272
+ custom!([401, {"Content-Type" => "text/html"}, ["Custom strategy"]])
273
+ end
274
+ end
275
+
276
+ begin
277
+ Devise.warden_config.default_strategies(:scope => :user).unshift(:custom)
278
+ sign_in_as_user
279
+ assert_equal 401, status
280
+ assert_contain 'Custom strategy'
281
+ ensure
282
+ Devise.warden_config.default_strategies(:scope => :user).shift
283
+ end
284
+ end
285
+
268
286
  # Access
269
287
  test 'render 404 on roles without permission' do
270
288
  get '/admin_area/password/new', {}, "action_dispatch.show_exceptions" => true
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class HttpAuthenticationTest < ActionController::IntegrationTest
4
4
 
@@ -19,8 +19,8 @@ class HttpAuthenticationTest < ActionController::IntegrationTest
19
19
  test 'uses the request format as response content type' do
20
20
  sign_in_as_new_user_with_http("unknown", "123456", :xml)
21
21
  assert_equal 401, status
22
- assert_equal "application/xml", headers["Content-Type"]
23
- assert response.body.include?("<error>HTTP Basic: Access denied.</error>")
22
+ assert_equal "application/xml; charset=utf-8", headers["Content-Type"]
23
+ assert response.body.include?("<error>Invalid email or password.</error>")
24
24
  end
25
25
 
26
26
  test 'returns a custom response with www-authenticate and chosen realm' do
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class LockTest < ActionController::IntegrationTest
4
4
 
@@ -11,7 +11,7 @@ class LockTest < ActionController::IntegrationTest
11
11
  ActionMailer::Base.deliveries.clear
12
12
 
13
13
  visit new_user_session_path
14
- click_link 'Didn\'t receive unlock instructions?'
14
+ click_link "Didn't receive unlock instructions?"
15
15
 
16
16
  fill_in 'email', :with => user.email
17
17
  click_button 'Resend unlock instructions'
@@ -26,7 +26,7 @@ class LockTest < ActionController::IntegrationTest
26
26
  ActionMailer::Base.deliveries.clear
27
27
 
28
28
  visit new_user_session_path
29
- click_link 'Didn\'t receive unlock instructions?'
29
+ click_link "Didn't receive unlock instructions?"
30
30
 
31
31
  fill_in 'email', :with => user.email
32
32
  click_button 'Resend unlock instructions'
@@ -36,6 +36,15 @@ class LockTest < ActionController::IntegrationTest
36
36
  assert_equal 0, ActionMailer::Base.deliveries.size
37
37
  end
38
38
 
39
+ test 'unlocked pages should not be available if email strategy is disabled' do
40
+ visit new_user_unlock_path
41
+ swap Devise, :unlock_strategy => :time do
42
+ assert_raise AbstractController::ActionNotFound do
43
+ visit new_user_unlock_path
44
+ end
45
+ end
46
+ end
47
+
39
48
  test 'user with invalid unlock token should not be able to unlock an account' do
40
49
  visit_user_unlock_with_token('invalid_token')
41
50
 
@@ -47,20 +56,19 @@ class LockTest < ActionController::IntegrationTest
47
56
 
48
57
  test "locked user should be able to unlock account" do
49
58
  user = create_user(:locked => true)
50
- assert user.locked?
59
+ assert user.access_locked?
51
60
 
52
61
  visit_user_unlock_with_token(user.unlock_token)
53
62
 
54
63
  assert_template 'home/index'
55
64
  assert_contain 'Your account was successfully unlocked.'
56
65
 
57
- assert_not user.reload.locked?
66
+ assert_not user.reload.access_locked?
58
67
  end
59
68
 
60
69
  test "sign in user automatically after unlocking it's account" do
61
70
  user = create_user(:locked => true)
62
71
  visit_user_unlock_with_token(user.unlock_token)
63
-
64
72
  assert warden.authenticated?(:user)
65
73
  end
66
74
 
@@ -71,11 +79,23 @@ class LockTest < ActionController::IntegrationTest
71
79
  assert_not warden.authenticated?(:user)
72
80
  end
73
81
 
82
+ test "user should not send a new e-mail if already locked" do
83
+ user = create_user(:locked => true)
84
+ user.failed_attempts = User.maximum_attempts + 1
85
+ user.save!
86
+
87
+ ActionMailer::Base.deliveries.clear
88
+
89
+ sign_in_as_user(:password => "invalid")
90
+ assert_contain 'Your account is locked.'
91
+ assert ActionMailer::Base.deliveries.empty?
92
+ end
93
+
74
94
  test 'error message is configurable by resource name' do
75
95
  store_translations :en, :devise => {
76
- :sessions => { :admin => { :locked => "You are locked!" } }
96
+ :failure => { :user => { :locked => "You are locked!" } }
77
97
  } do
78
- get new_admin_session_path(:locked => true)
98
+ user = sign_in_as_user(:locked => true)
79
99
  assert_contain 'You are locked!'
80
100
  end
81
101
  end
@@ -1,10 +1,10 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class PasswordTest < ActionController::IntegrationTest
4
4
 
5
5
  def visit_new_password_path
6
6
  visit new_user_session_path
7
- click_link 'Forgot password?'
7
+ click_link 'Forgot your password?'
8
8
  end
9
9
 
10
10
  def request_forgot_password(&block)
@@ -134,7 +134,7 @@ class PasswordTest < ActionController::IntegrationTest
134
134
  request_forgot_password
135
135
  reset_password :reset_password_token => user.reload.reset_password_token
136
136
 
137
- assert_current_path new_user_session_path(:unconfirmed => true)
137
+ assert_equal new_user_session_path, @request.path
138
138
  assert !warden.authenticated?(:user)
139
139
  end
140
140