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,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class RegistrationTest < ActionController::IntegrationTest
4
4
 
@@ -28,9 +28,9 @@ class RegistrationTest < ActionController::IntegrationTest
28
28
  fill_in 'password confirmation', :with => 'new_user123'
29
29
  click_button 'Sign up'
30
30
 
31
- assert_contain 'You have signed up successfully.'
31
+ assert_contain 'You have signed up successfully'
32
32
  assert_contain 'Sign in'
33
- assert_not_contain 'Confirm your account'
33
+ assert_not_contain 'You have to confirm your account before continuing'
34
34
 
35
35
  assert_not warden.authenticated?(:user)
36
36
 
@@ -73,7 +73,9 @@ class RegistrationTest < ActionController::IntegrationTest
73
73
 
74
74
  test 'a guest should not be able to change account' do
75
75
  get edit_user_registration_path
76
- assert_redirected_to new_user_session_path(:unauthenticated => true)
76
+ assert_redirected_to new_user_session_path
77
+ follow_redirect!
78
+ assert_contain 'You need to sign in or sign up before continuing.'
77
79
  end
78
80
 
79
81
  test 'a signed in user should not be able to access sign up' do
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class RememberMeTest < ActionController::IntegrationTest
4
4
 
@@ -6,10 +6,17 @@ class RememberMeTest < ActionController::IntegrationTest
6
6
  Devise.remember_for = 1
7
7
  user = create_user
8
8
  user.remember_me!
9
- cookies['remember_user_token'] = User.serialize_into_cookie(user) + add_to_token
9
+ raw_cookie = User.serialize_into_cookie(user).tap { |a| a.last << add_to_token }
10
+ cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)
10
11
  user
11
12
  end
12
13
 
14
+ def generate_signed_cookie(raw_cookie)
15
+ request = ActionDispatch::Request.new({})
16
+ request.cookie_jar.signed['raw_cookie'] = raw_cookie
17
+ request.cookie_jar['raw_cookie']
18
+ end
19
+
13
20
  test 'do not remember the user if he has not checked remember me option' do
14
21
  user = sign_in_as_user
15
22
  assert_nil user.reload.remember_token
@@ -40,7 +47,7 @@ class RememberMeTest < ActionController::IntegrationTest
40
47
  user = create_user_and_remember('add')
41
48
  get users_path
42
49
  assert_not warden.authenticated?(:user)
43
- assert_redirected_to new_user_session_path(:unauthenticated => true)
50
+ assert_redirected_to new_user_session_path
44
51
  end
45
52
 
46
53
  test 'do not remember with token expired' do
@@ -48,7 +55,7 @@ class RememberMeTest < ActionController::IntegrationTest
48
55
  swap Devise, :remember_for => 0 do
49
56
  get users_path
50
57
  assert_not warden.authenticated?(:user)
51
- assert_redirected_to new_user_session_path(:unauthenticated => true)
58
+ assert_redirected_to new_user_session_path
52
59
  end
53
60
  end
54
61
 
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class SessionTimeoutTest < ActionController::IntegrationTest
4
4
 
@@ -32,7 +32,7 @@ class SessionTimeoutTest < ActionController::IntegrationTest
32
32
  assert_not_nil last_request_at
33
33
 
34
34
  get users_path
35
- assert_redirected_to new_user_session_path(:timeout => true)
35
+ assert_redirected_to new_user_session_path
36
36
  assert_not warden.authenticated?(:user)
37
37
  end
38
38
 
@@ -47,14 +47,14 @@ class SessionTimeoutTest < ActionController::IntegrationTest
47
47
 
48
48
  get expire_user_path(user)
49
49
  get users_path
50
- assert_redirected_to new_user_session_path(:timeout => true)
50
+ assert_redirected_to new_user_session_path
51
51
  assert_not warden.authenticated?(:user)
52
52
  end
53
53
  end
54
54
 
55
55
  test 'error message with i18n' do
56
56
  store_translations :en, :devise => {
57
- :sessions => { :user => { :timeout => 'Session expired!' } }
57
+ :failure => { :user => { :timeout => 'Session expired!' } }
58
58
  } do
59
59
  user = sign_in_as_user
60
60
 
@@ -1,10 +1,21 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class TokenAuthenticationTest < ActionController::IntegrationTest
4
4
 
5
- test 'sign in should authenticate with valid authentication token and proper authentication token key' do
5
+ test 'authenticate with valid authentication token key and value through params' do
6
6
  swap Devise, :token_authentication_key => :secret_token do
7
- sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
7
+ sign_in_as_new_user_with_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 'authenticate with valid authentication token key and value through http' do
17
+ swap Devise, :token_authentication_key => :secret_token do
18
+ sign_in_as_new_user_with_token(:http_auth => true)
8
19
 
9
20
  assert_response :success
10
21
  assert_template 'users/index'
@@ -13,10 +24,30 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
13
24
  end
14
25
  end
15
26
 
16
- test 'signing in with valid authentication token - but improper authentication token key - return to sign in form with error message' do
27
+ test 'does authenticate with valid authentication token key and value through params if not configured' do
28
+ swap Devise, :token_authentication_key => :secret_token, :params_authenticatable => [:database] do
29
+ sign_in_as_new_user_with_token
30
+
31
+ assert_contain 'You need to sign in or sign up before continuing'
32
+ assert_contain 'Sign in'
33
+ assert_not warden.authenticated?(:user)
34
+ end
35
+ end
36
+
37
+ test 'does authenticate with valid authentication token key and value through http if not configured' do
38
+ swap Devise, :token_authentication_key => :secret_token, :http_authenticatable => [:database] do
39
+ sign_in_as_new_user_with_token(:http_auth => true)
40
+
41
+ assert_response 401
42
+ assert_contain 'Invalid email or password.'
43
+ assert_not warden.authenticated?(:user)
44
+ end
45
+ end
46
+
47
+ test 'does not authenticate with improper authentication token key' do
17
48
  swap Devise, :token_authentication_key => :donald_duck_token do
18
49
  sign_in_as_new_user_with_token(:auth_token_key => :secret_token)
19
- assert_current_path new_user_session_path(:unauthenticated => true)
50
+ assert_equal new_user_session_path, @request.path
20
51
 
21
52
  assert_contain 'You need to sign in or sign up before continuing'
22
53
  assert_contain 'Sign in'
@@ -24,12 +55,11 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
24
55
  end
25
56
  end
26
57
 
27
- test 'signing in with invalid authentication token should return to sign in form with error message' do
28
- store_translations :en, :devise => {:sessions => {:invalid_token => 'LOL, that was not a single character correct.'}} do
58
+ test 'does not authenticate with improper authentication token value' do
59
+ store_translations :en, :devise => {:failure => {:invalid_token => 'LOL, that was not a single character correct.'}} do
29
60
  sign_in_as_new_user_with_token(:auth_token => '*** INVALID TOKEN ***')
30
- assert_current_path new_user_session_path(:invalid_token => true)
61
+ assert_equal new_user_session_path, @request.path
31
62
 
32
- assert_response :success
33
63
  assert_contain 'LOL, that was not a single character correct.'
34
64
  assert_contain 'Sign in'
35
65
  assert_not warden.authenticated?(:user)
@@ -46,7 +76,13 @@ class TokenAuthenticationTest < ActionController::IntegrationTest
46
76
  user.authentication_token = VALID_AUTHENTICATION_TOKEN
47
77
  user.save
48
78
 
49
- visit users_path(options[:auth_token_key].to_sym => options[:auth_token])
79
+ if options[:http_auth]
80
+ header = "Basic #{ActiveSupport::Base64.encode64("#{VALID_AUTHENTICATION_TOKEN}:X")}"
81
+ get users_path, {}, "HTTP_AUTHORIZATION" => header
82
+ else
83
+ visit users_path(options[:auth_token_key].to_sym => options[:auth_token])
84
+ end
85
+
50
86
  user
51
87
  end
52
88
 
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class TrackableHooksTest < ActionController::IntegrationTest
4
4
 
@@ -39,7 +39,7 @@ class TrackableHooksTest < ActionController::IntegrationTest
39
39
 
40
40
  test "increase sign in count" do
41
41
  user = create_user
42
- assert_nil user.sign_in_count
42
+ assert_equal 0, user.sign_in_count
43
43
 
44
44
  sign_in_as_user
45
45
  user.reload
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class ConfirmationInstructionsTest < ActionMailer::TestCase
4
4
 
@@ -23,7 +23,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
23
23
  end
24
24
 
25
25
  test 'content type should be set to html' do
26
- assert_equal 'text/html', mail.content_type
26
+ assert mail.content_type.include?('text/html')
27
27
  end
28
28
 
29
29
  test 'send confirmation instructions to the user email' do
@@ -48,13 +48,13 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
48
48
  end
49
49
 
50
50
  test 'body should have user info' do
51
- assert_match /#{user.email}/, mail.body
51
+ assert_match /#{user.email}/, mail.body.encoded
52
52
  end
53
53
 
54
54
  test 'body should have link to confirm the account' do
55
55
  host = ActionMailer::Base.default_url_options[:host]
56
56
  confirmation_url_regexp = %r{<a href=\"http://#{host}/users/confirmation\?confirmation_token=#{user.confirmation_token}">}
57
- assert_match confirmation_url_regexp, mail.body
57
+ assert_match confirmation_url_regexp, mail.body.encoded
58
58
  end
59
59
 
60
60
  test 'renders a scoped if scoped_views is set to true' do
@@ -73,7 +73,7 @@ class ConfirmationInstructionsTest < ActionMailer::TestCase
73
73
  end
74
74
 
75
75
  test 'mailer sender accepts a proc' do
76
- swap Devise, :mailer_sender => lambda { "another@example.com" } do
76
+ swap Devise, :mailer_sender => proc { "another@example.com" } do
77
77
  assert_equal ['another@example.com'], mail.from
78
78
  end
79
79
  end
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class ResetPasswordInstructionsTest < ActionMailer::TestCase
4
4
 
@@ -27,7 +27,7 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
27
27
  end
28
28
 
29
29
  test 'content type should be set to html' do
30
- assert_equal 'text/html', mail.content_type
30
+ assert mail.content_type.include?('text/html')
31
31
  end
32
32
 
33
33
  test 'send confirmation instructions to the user email' do
@@ -51,17 +51,17 @@ class ResetPasswordInstructionsTest < ActionMailer::TestCase
51
51
  end
52
52
 
53
53
  test 'body should have user info' do
54
- assert_match /#{user.email}/, mail.body
54
+ assert_match(/#{user.email}/, mail.body.encoded)
55
55
  end
56
56
 
57
57
  test 'body should have link to confirm the account' do
58
58
  host = ActionMailer::Base.default_url_options[:host]
59
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
60
+ assert_match reset_url_regexp, mail.body.encoded
61
61
  end
62
62
 
63
63
  test 'mailer sender accepts a proc' do
64
- swap Devise, :mailer_sender => lambda { "another@example.com" } do
64
+ swap Devise, :mailer_sender => proc { "another@example.com" } do
65
65
  assert_equal ['another@example.com'], mail.from
66
66
  end
67
67
  end
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class UnlockInstructionsTest < ActionMailer::TestCase
4
4
 
@@ -10,7 +10,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
10
10
  def user
11
11
  @user ||= begin
12
12
  user = create_user
13
- user.lock!
13
+ user.lock_access!
14
14
  user
15
15
  end
16
16
  end
@@ -27,7 +27,7 @@ class UnlockInstructionsTest < ActionMailer::TestCase
27
27
  end
28
28
 
29
29
  test 'content type should be set to html' do
30
- assert_equal 'text/html', mail.content_type
30
+ assert mail.content_type.include?('text/html')
31
31
  end
32
32
 
33
33
  test 'send unlock instructions to the user email' do
@@ -51,12 +51,12 @@ class UnlockInstructionsTest < ActionMailer::TestCase
51
51
  end
52
52
 
53
53
  test 'body should have user info' do
54
- assert_match /#{user.email}/, mail.body
54
+ assert_match(/#{user.email}/, mail.body.encoded)
55
55
  end
56
56
 
57
57
  test 'body should have link to unlock the account' do
58
58
  host = ActionMailer::Base.default_url_options[:host]
59
59
  unlock_url_regexp = %r{<a href=\"http://#{host}/users/unlock\?unlock_token=#{user.unlock_token}">}
60
- assert_match unlock_url_regexp, mail.body
60
+ assert_match unlock_url_regexp, mail.body.encoded
61
61
  end
62
62
  end
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class MappingTest < ActiveSupport::TestCase
4
4
 
@@ -13,7 +13,7 @@ class MappingTest < ActiveSupport::TestCase
13
13
  assert_equal :admin_area, Devise.mappings[:admin].as
14
14
  end
15
15
 
16
- test 'allow custom scope to be given' do
16
+ test 'allows custom scope to be given' do
17
17
  assert_equal :accounts, Devise.mappings[:manager].as
18
18
  end
19
19
 
@@ -26,7 +26,12 @@ class MappingTest < ActiveSupport::TestCase
26
26
  allowed = Devise.mappings[:admin].allowed_controllers
27
27
  assert allowed.include?("sessions")
28
28
  assert_not allowed.include?("devise/confirmations")
29
- assert_not allowed.include?("devise/passwords")
29
+ assert_not allowed.include?("devise/unlocks")
30
+ end
31
+
32
+ test 'has strategies depending on the model declaration' do
33
+ assert_equal [:rememberable, :token_authenticatable, :database_authenticatable], Devise.mappings[:user].strategies
34
+ assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies
30
35
  end
31
36
 
32
37
  test 'find mapping by path' do
@@ -38,22 +43,17 @@ class MappingTest < ActiveSupport::TestCase
38
43
  assert_equal Devise.mappings[:admin], Devise::Mapping.find_by_path("/admin_area/session")
39
44
  end
40
45
 
41
- test 'find mapping by class' do
42
- assert_nil Devise::Mapping.find_by_class(String)
43
- assert_equal Devise.mappings[:user], Devise::Mapping.find_by_class(User)
44
- end
45
-
46
- test 'find mapping by class works with single table inheritance' do
47
- klass = Class.new(User)
48
- assert_equal Devise.mappings[:user], Devise::Mapping.find_by_class(klass)
49
- end
50
-
51
46
  test 'find scope for a given object' do
52
47
  assert_equal :user, Devise::Mapping.find_scope!(User)
53
48
  assert_equal :user, Devise::Mapping.find_scope!(:user)
54
49
  assert_equal :user, Devise::Mapping.find_scope!(User.new)
55
50
  end
56
51
 
52
+ test 'find scope works with single table inheritance' do
53
+ assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))
54
+ assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)
55
+ end
56
+
57
57
  test 'find scope raises an error if cannot be found' do
58
58
  assert_raise RuntimeError do
59
59
  Devise::Mapping.find_scope!(String)
@@ -110,8 +110,9 @@ class MappingTest < ActiveSupport::TestCase
110
110
 
111
111
  mapping = Devise.mappings[:admin]
112
112
  assert mapping.authenticatable?
113
+ assert mapping.recoverable?
113
114
  assert_not mapping.confirmable?
114
- assert_not mapping.recoverable?
115
+ assert_not mapping.lockable?
115
116
  assert_not mapping.rememberable?
116
117
  end
117
118
  end
@@ -1,4 +1,4 @@
1
- require 'test/test_helper'
1
+ require 'test_helper'
2
2
 
3
3
  class ConfirmableTest < ActiveSupport::TestCase
4
4
 
@@ -11,15 +11,6 @@ class ConfirmableTest < ActiveSupport::TestCase
11
11
  assert_not_nil create_user.confirmation_token
12
12
  end
13
13
 
14
- test 'should regenerate confirmation token each time' do
15
- user = create_user
16
- 3.times do
17
- token = user.confirmation_token
18
- user.resend_confirmation!
19
- assert_not_equal token, user.confirmation_token
20
- end
21
- end
22
-
23
14
  test 'should never generate the same confirmation token for different users' do
24
15
  confirmation_tokens = []
25
16
  3.times do
@@ -62,20 +53,20 @@ class ConfirmableTest < ActiveSupport::TestCase
62
53
 
63
54
  test 'should find and confirm an user automatically' do
64
55
  user = create_user
65
- confirmed_user = User.confirm!(:confirmation_token => user.confirmation_token)
56
+ confirmed_user = User.confirm_by_token(user.confirmation_token)
66
57
  assert_equal confirmed_user, user
67
58
  assert user.reload.confirmed?
68
59
  end
69
60
 
70
61
  test 'should return a new record with errors when a invalid token is given' do
71
- confirmed_user = User.confirm!(:confirmation_token => 'invalid_confirmation_token')
72
- assert confirmed_user.new_record?
62
+ confirmed_user = User.confirm_by_token('invalid_confirmation_token')
63
+ assert_not confirmed_user.persisted?
73
64
  assert_equal "is invalid", confirmed_user.errors[:confirmation_token].join
74
65
  end
75
66
 
76
67
  test 'should return a new record with errors when a blank token is given' do
77
- confirmed_user = User.confirm!(:confirmation_token => '')
78
- assert confirmed_user.new_record?
68
+ confirmed_user = User.confirm_by_token('')
69
+ assert_not confirmed_user.persisted?
79
70
  assert_equal "can't be blank", confirmed_user.errors[:confirmation_token].join
80
71
  end
81
72
 
@@ -83,18 +74,11 @@ class ConfirmableTest < ActiveSupport::TestCase
83
74
  user = create_user
84
75
  user.confirmed_at = Time.now
85
76
  user.save
86
- confirmed_user = User.confirm!(:confirmation_token => user.confirmation_token)
77
+ confirmed_user = User.confirm_by_token(user.confirmation_token)
87
78
  assert confirmed_user.confirmed?
88
79
  assert_equal "was already confirmed", confirmed_user.errors[:email].join
89
80
  end
90
81
 
91
- test 'should authenticate a confirmed user' do
92
- user = create_user
93
- user.confirm!
94
- authenticated_user = User.authenticate(:email => user.email, :password => user.password)
95
- assert_equal authenticated_user, user
96
- end
97
-
98
82
  test 'should send confirmation instructions by email' do
99
83
  assert_email_sent do
100
84
  create_user
@@ -128,7 +112,7 @@ class ConfirmableTest < ActiveSupport::TestCase
128
112
 
129
113
  test 'should return a new user if no email was found' do
130
114
  confirmation_user = User.send_confirmation_instructions(:email => "invalid@email.com")
131
- assert confirmation_user.new_record?
115
+ assert_not confirmation_user.persisted?
132
116
  end
133
117
 
134
118
  test 'should add error to new user email if no email was found' do
@@ -137,13 +121,6 @@ class ConfirmableTest < ActiveSupport::TestCase
137
121
  assert_equal "not found", confirmation_user.errors[:email].join
138
122
  end
139
123
 
140
- test 'should generate a confirmation token before send the confirmation instructions email' do
141
- user = create_user
142
- token = user.confirmation_token
143
- confirmation_user = User.send_confirmation_instructions(:email => user.email)
144
- assert_not_equal token, user.reload.confirmation_token
145
- end
146
-
147
124
  test 'should send email instructions for the user confirm it\'s email' do
148
125
  user = create_user
149
126
  assert_email_sent do
@@ -173,7 +150,7 @@ class ConfirmableTest < ActiveSupport::TestCase
173
150
  test 'should not be able to send instructions if the user is already confirmed' do
174
151
  user = create_user
175
152
  user.confirm!
176
- assert_not user.resend_confirmation!
153
+ assert_not user.resend_confirmation_token
177
154
  assert user.confirmed?
178
155
  assert_equal 'was already confirmed', user.errors[:email].join
179
156
  end