test/test_password_archivable.rb in devise-security-0.13.0 vs test/test_password_archivable.rb in devise-security-0.14.0.rc1
- old
+ new
@@ -1,10 +1,11 @@
# frozen_string_literal: true
require 'test_helper'
class TestPasswordArchivable < ActiveSupport::TestCase
+
setup do
Devise.password_archiving_count = 2
end
teardown do
@@ -17,11 +18,11 @@
user.save!
end
test 'cannot use same password' do
user = User.create email: 'bob@microsoft.com', password: 'Password1', password_confirmation: 'Password1'
- assert_raises(ActiveRecord::RecordInvalid) { set_password(user, 'Password1') }
+ assert_raises(ORMInvalidRecordException) { set_password(user, 'Password1') }
end
test 'indirectly saving associated user does not cause deprecation warning' do
old_behavior = ActiveSupport::Deprecation.behavior
ActiveSupport::Deprecation.behavior = :raise
@@ -35,21 +36,19 @@
user = User.new(email: 'bob@microsoft.com', password: nil, password_confirmation: nil)
set_password(user, 'Password1')
assert_equal 0, OldPassword.count
end
- test 'cannot use archived passwords' do
+ test 'cannot reuse archived passwords' do
assert_equal 2, Devise.password_archiving_count
user = User.create! email: 'bob@microsoft.com', password: 'Password1', password_confirmation: 'Password1'
assert_equal 0, OldPassword.count
-
set_password(user, 'Password2')
assert_equal 1, OldPassword.count
- assert_raises(ActiveRecord::RecordInvalid) { set_password(user, 'Password1') }
-
+ assert_raises(ORMInvalidRecordException) { set_password(user, 'Password1') }
set_password(user, 'Password3')
assert_equal 2, OldPassword.count
# rotate first password out of archive
assert set_password(user, 'Password4')
@@ -68,10 +67,10 @@
user = User.create email: 'bob@microsoft.com', password: 'Password1', password_confirmation: 'Password1'
assert set_password(user, 'Password2')
- assert_raises(ActiveRecord::RecordInvalid) { set_password(user, 'Password2') }
+ assert_raises(ORMInvalidRecordException) { set_password(user, 'Password2') }
- assert_raises(ActiveRecord::RecordInvalid) { set_password(user, 'Password1') }
+ assert_raises(ORMInvalidRecordException) { set_password(user, 'Password1') }
end
end