access_tokens_vacuum_spec.rb 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. require 'rails_helper'
  2. RSpec.describe Vacuum::AccessTokensVacuum do
  3. subject { described_class.new }
  4. describe '#perform' do
  5. let!(:revoked_access_token) { Fabricate(:access_token, revoked_at: 1.minute.ago) }
  6. let!(:expired_access_token) { Fabricate(:access_token, expires_in: 59.minutes.to_i, created_at: 1.hour.ago) }
  7. let!(:active_access_token) { Fabricate(:access_token) }
  8. let!(:revoked_access_grant) { Fabricate(:access_grant, revoked_at: 1.minute.ago) }
  9. let!(:expired_access_grant) { Fabricate(:access_grant, expires_in: 59.minutes.to_i, created_at: 1.hour.ago) }
  10. let!(:active_access_grant) { Fabricate(:access_grant) }
  11. before do
  12. subject.perform
  13. end
  14. it 'deletes revoked access tokens' do
  15. expect { revoked_access_token.reload }.to raise_error ActiveRecord::RecordNotFound
  16. end
  17. it 'deletes expired access tokens' do
  18. expect { expired_access_token.reload }.to raise_error ActiveRecord::RecordNotFound
  19. end
  20. it 'deletes revoked access grants' do
  21. expect { revoked_access_grant.reload }.to raise_error ActiveRecord::RecordNotFound
  22. end
  23. it 'deletes expired access grants' do
  24. expect { expired_access_grant.reload }.to raise_error ActiveRecord::RecordNotFound
  25. end
  26. it 'does not delete active access tokens' do
  27. expect { active_access_token.reload }.to_not raise_error
  28. end
  29. it 'does not delete active access grants' do
  30. expect { active_access_grant.reload }.to_not raise_error
  31. end
  32. end
  33. end