access_tokens_vacuum_spec.rb 1.3 KB

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