applications_vacuum_spec.rb 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Vacuum::ApplicationsVacuum do
  4. subject { described_class.new }
  5. describe '#perform' do
  6. let!(:app_with_token) { Fabricate(:application, created_at: 1.month.ago) }
  7. let!(:app_with_grant) { Fabricate(:application, created_at: 1.month.ago) }
  8. let!(:app_with_signup) { Fabricate(:application, created_at: 1.month.ago) }
  9. let!(:app_with_owner) { Fabricate(:application, created_at: 1.month.ago, owner: Fabricate(:user)) }
  10. let!(:unused_app) { Fabricate(:application, created_at: 1.month.ago) }
  11. let!(:recent_app) { Fabricate(:application, created_at: 1.hour.ago) }
  12. let!(:active_access_token) { Fabricate(:access_token, application: app_with_token) }
  13. let!(:active_access_grant) { Fabricate(:access_grant, application: app_with_grant) }
  14. let!(:user) { Fabricate(:user, created_by_application: app_with_signup) }
  15. before do
  16. subject.perform
  17. end
  18. it 'does not delete applications with valid access tokens' do
  19. expect { app_with_token.reload }.to_not raise_error
  20. end
  21. it 'does not delete applications with valid access grants' do
  22. expect { app_with_grant.reload }.to_not raise_error
  23. end
  24. it 'does not delete applications that were used to create users' do
  25. expect { app_with_signup.reload }.to_not raise_error
  26. end
  27. it 'does not delete owned applications' do
  28. expect { app_with_owner.reload }.to_not raise_error
  29. end
  30. it 'does not delete applications registered less than a day ago' do
  31. expect { recent_app.reload }.to_not raise_error
  32. end
  33. it 'deletes unused applications' do
  34. expect { unused_app.reload }.to raise_error ActiveRecord::RecordNotFound
  35. end
  36. end
  37. end