Skip to content

Commit

Permalink
Change approach with testing of devise account lock/unlock
Browse files Browse the repository at this point in the history
  • Loading branch information
jayjay-w authored Feb 5, 2024
1 parent 9426c37 commit 2b3f9ab
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions test/controllers/sessions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,18 @@ def setup
end

test "should unlock locked user accounts after specified time" do
travel_to Time.zone.local(2023, 12, 12, 01, 04, 44)
u = create_user login: 'test', password: '12345678', password_confirmation: '12345678', email: '[email protected]'
maximum_attempts = Devise.maximum_attempts
Devise.unlock_in = 10.minutes


maximum_attempts.times do
post :create, params: { api_user: { email: '[email protected]', password: '12345679' } }
end
u.lock_access!

unlock_time = CheckConfig.get('devise_unlock_accounts_after', 5, :integer)
travel 30.minutes
post :create, params: { api_user: { email: '[email protected]', password: '12345678' } }

travel_to unlock_time.hours.from_now + 1.hour do
u.reload
assert !u.access_locked?
assert_nil u.locked_at
end
u.reload
assert !u.access_locked?
assert_nil u.locked_at
end


end

0 comments on commit 2b3f9ab

Please sign in to comment.