diff options
author | Claire <claire.github-309c@sitedethib.com> | 2022-10-02 17:33:37 +0200 |
---|---|---|
committer | Claire <claire.github-309c@sitedethib.com> | 2022-10-02 18:46:22 +0200 |
commit | 221580a3afb62b8da047b4feddbb58261ca07fbc (patch) | |
tree | bb070ba3e04a4cea5a7f55257ebe3cf71b2df280 /spec/lib/vacuum | |
parent | 9d7c323abdda66423751f3a25faf960674af8a49 (diff) | |
parent | c55219efa811b3c6347774bec1b174d325e5f300 (diff) |
Merge branch 'main' into glitch-soc/merge-upstream
Conflicts: - `app/controllers/home_controller.rb`: Upstream made it so `/web` is available to non-logged-in users and `/` redirects to `/web` instead of `/about`. Kept our version since glitch-soc's WebUI doesn't have what's needed yet and I think /about is still a much better landing page anyway. - `app/models/form/admin_settings.rb`: Upstream added new settings, and glitch-soc had an extra setting. Not really a conflict. Added upstream's new settings. - `app/serializers/initial_state_serializer.rb`: Upstream added a new `server` initial state object. Not really a conflict. Merged upstream's changes. - `app/views/admin/settings/edit.html.haml`: Upstream added new settings. Not really a conflict. Merged upstream's changes. - `app/workers/scheduler/feed_cleanup_scheduler.rb`: Upstream refactored that part and removed the file. Ported our relevant changes into `app/lib/vacuum/feeds_vacuum.rb` - `config/settings.yml`: Upstream added new settings. Not a real conflict. Added upstream's new settings.
Diffstat (limited to 'spec/lib/vacuum')
-rw-r--r-- | spec/lib/vacuum/access_tokens_vacuum_spec.rb | 33 | ||||
-rw-r--r-- | spec/lib/vacuum/backups_vacuum_spec.rb | 24 | ||||
-rw-r--r-- | spec/lib/vacuum/feeds_vacuum_spec.rb | 30 | ||||
-rw-r--r-- | spec/lib/vacuum/media_attachments_vacuum_spec.rb | 47 | ||||
-rw-r--r-- | spec/lib/vacuum/preview_cards_vacuum_spec.rb | 36 | ||||
-rw-r--r-- | spec/lib/vacuum/statuses_vacuum_spec.rb | 36 | ||||
-rw-r--r-- | spec/lib/vacuum/system_keys_vacuum_spec.rb | 22 |
7 files changed, 228 insertions, 0 deletions
diff --git a/spec/lib/vacuum/access_tokens_vacuum_spec.rb b/spec/lib/vacuum/access_tokens_vacuum_spec.rb new file mode 100644 index 000000000..0244c3449 --- /dev/null +++ b/spec/lib/vacuum/access_tokens_vacuum_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe Vacuum::AccessTokensVacuum do + subject { described_class.new } + + describe '#perform' do + let!(:revoked_access_token) { Fabricate(:access_token, revoked_at: 1.minute.ago) } + let!(:active_access_token) { Fabricate(:access_token) } + + let!(:revoked_access_grant) { Fabricate(:access_grant, revoked_at: 1.minute.ago) } + let!(:active_access_grant) { Fabricate(:access_grant) } + + before do + subject.perform + end + + it 'deletes revoked access tokens' do + expect { revoked_access_token.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it 'deletes revoked access grants' do + expect { revoked_access_grant.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it 'does not delete active access tokens' do + expect { active_access_token.reload }.to_not raise_error + end + + it 'does not delete active access grants' do + expect { active_access_grant.reload }.to_not raise_error + end + end +end diff --git a/spec/lib/vacuum/backups_vacuum_spec.rb b/spec/lib/vacuum/backups_vacuum_spec.rb new file mode 100644 index 000000000..4e2de083f --- /dev/null +++ b/spec/lib/vacuum/backups_vacuum_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' + +RSpec.describe Vacuum::BackupsVacuum do + let(:retention_period) { 7.days } + + subject { described_class.new(retention_period) } + + describe '#perform' do + let!(:expired_backup) { Fabricate(:backup, created_at: (retention_period + 1.day).ago) } + let!(:current_backup) { Fabricate(:backup) } + + before do + subject.perform + end + + it 'deletes backups past the retention period' do + expect { expired_backup.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it 'does not delete backups within the retention period' do + expect { current_backup.reload }.to_not raise_error + end + end +end diff --git a/spec/lib/vacuum/feeds_vacuum_spec.rb b/spec/lib/vacuum/feeds_vacuum_spec.rb new file mode 100644 index 000000000..0aec26740 --- /dev/null +++ b/spec/lib/vacuum/feeds_vacuum_spec.rb @@ -0,0 +1,30 @@ +require 'rails_helper' + +RSpec.describe Vacuum::FeedsVacuum do + subject { described_class.new } + + describe '#perform' do + let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) } + let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) } + + before do + redis.zadd(feed_key_for(inactive_user), 1, 1) + redis.zadd(feed_key_for(active_user), 1, 1) + redis.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2) + redis.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3) + + subject.perform + end + + it 'clears feeds of inactive users and lists' do + expect(redis.zcard(feed_key_for(inactive_user))).to eq 0 + expect(redis.zcard(feed_key_for(active_user))).to eq 1 + expect(redis.exists?(feed_key_for(inactive_user, 'reblogs'))).to be false + expect(redis.exists?(feed_key_for(inactive_user, 'reblogs:2'))).to be false + end + end + + def feed_key_for(user, subtype = nil) + FeedManager.instance.key(:home, user.account_id, subtype) + end +end diff --git a/spec/lib/vacuum/media_attachments_vacuum_spec.rb b/spec/lib/vacuum/media_attachments_vacuum_spec.rb new file mode 100644 index 000000000..be8458d9b --- /dev/null +++ b/spec/lib/vacuum/media_attachments_vacuum_spec.rb @@ -0,0 +1,47 @@ +require 'rails_helper' + +RSpec.describe Vacuum::MediaAttachmentsVacuum do + let(:retention_period) { 7.days } + + subject { described_class.new(retention_period) } + + let(:remote_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) } + let(:local_status) { Fabricate(:status) } + + describe '#perform' do + let!(:old_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) } + let!(:old_local_media) { Fabricate(:media_attachment, status: local_status, created_at: (retention_period + 1.day).ago, updated_at: (retention_period + 1.day).ago) } + let!(:new_remote_media) { Fabricate(:media_attachment, remote_url: 'https://example.com/foo.png', status: remote_status) } + let!(:new_local_media) { Fabricate(:media_attachment, status: local_status) } + let!(:old_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 10.days.ago) } + let!(:new_unattached_media) { Fabricate(:media_attachment, account_id: nil, created_at: 1.hour.ago) } + + before do + subject.perform + end + + it 'deletes cache of remote media attachments past the retention period' do + expect(old_remote_media.reload.file).to be_blank + end + + it 'does not touch local media attachments past the retention period' do + expect(old_local_media.reload.file).to_not be_blank + end + + it 'does not delete cache of remote media attachments within the retention period' do + expect(new_remote_media.reload.file).to_not be_blank + end + + it 'does not touch local media attachments within the retention period' do + expect(new_local_media.reload.file).to_not be_blank + end + + it 'deletes unattached media attachments past TTL' do + expect { old_unattached_media.reload }.to raise_error(ActiveRecord::RecordNotFound) + end + + it 'does not delete unattached media attachments within TTL' do + expect(new_unattached_media.reload).to be_persisted + end + end +end diff --git a/spec/lib/vacuum/preview_cards_vacuum_spec.rb b/spec/lib/vacuum/preview_cards_vacuum_spec.rb new file mode 100644 index 000000000..4a4a599fa --- /dev/null +++ b/spec/lib/vacuum/preview_cards_vacuum_spec.rb @@ -0,0 +1,36 @@ +require 'rails_helper' + +RSpec.describe Vacuum::PreviewCardsVacuum do + let(:retention_period) { 7.days } + + subject { described_class.new(retention_period) } + + describe '#perform' do + let!(:orphaned_preview_card) { Fabricate(:preview_card, created_at: 2.days.ago) } + let!(:old_preview_card) { Fabricate(:preview_card, updated_at: (retention_period + 1.day).ago) } + let!(:new_preview_card) { Fabricate(:preview_card) } + + before do + old_preview_card.statuses << Fabricate(:status) + new_preview_card.statuses << Fabricate(:status) + + subject.perform + end + + it 'deletes cache of preview cards last updated before the retention period' do + expect(old_preview_card.reload.image).to be_blank + end + + it 'does not delete cache of preview cards last updated within the retention period' do + expect(new_preview_card.reload.image).to_not be_blank + end + + it 'does not delete attached preview cards' do + expect(new_preview_card.reload).to be_persisted + end + + it 'deletes preview cards not attached to any status' do + expect { orphaned_preview_card.reload }.to raise_error ActiveRecord::RecordNotFound + end + end +end diff --git a/spec/lib/vacuum/statuses_vacuum_spec.rb b/spec/lib/vacuum/statuses_vacuum_spec.rb new file mode 100644 index 000000000..83f3c5c9f --- /dev/null +++ b/spec/lib/vacuum/statuses_vacuum_spec.rb @@ -0,0 +1,36 @@ +require 'rails_helper' + +RSpec.describe Vacuum::StatusesVacuum do + let(:retention_period) { 7.days } + + let(:remote_account) { Fabricate(:account, domain: 'example.com') } + + subject { described_class.new(retention_period) } + + describe '#perform' do + let!(:remote_status_old) { Fabricate(:status, account: remote_account, created_at: (retention_period + 2.days).ago) } + let!(:remote_status_recent) { Fabricate(:status, account: remote_account, created_at: (retention_period - 2.days).ago) } + let!(:local_status_old) { Fabricate(:status, created_at: (retention_period + 2.days).ago) } + let!(:local_status_recent) { Fabricate(:status, created_at: (retention_period - 2.days).ago) } + + before do + subject.perform + end + + it 'deletes remote statuses past the retention period' do + expect { remote_status_old.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it 'does not delete local statuses past the retention period' do + expect { local_status_old.reload }.to_not raise_error + end + + it 'does not delete remote statuses within the retention period' do + expect { remote_status_recent.reload }.to_not raise_error + end + + it 'does not delete local statuses within the retention period' do + expect { local_status_recent.reload }.to_not raise_error + end + end +end diff --git a/spec/lib/vacuum/system_keys_vacuum_spec.rb b/spec/lib/vacuum/system_keys_vacuum_spec.rb new file mode 100644 index 000000000..565892f02 --- /dev/null +++ b/spec/lib/vacuum/system_keys_vacuum_spec.rb @@ -0,0 +1,22 @@ +require 'rails_helper' + +RSpec.describe Vacuum::SystemKeysVacuum do + subject { described_class.new } + + describe '#perform' do + let!(:expired_system_key) { Fabricate(:system_key, created_at: (SystemKey::ROTATION_PERIOD * 4).ago) } + let!(:current_system_key) { Fabricate(:system_key) } + + before do + subject.perform + end + + it 'deletes the expired key' do + expect { expired_system_key.reload }.to raise_error ActiveRecord::RecordNotFound + end + + it 'does not delete the current key' do + expect { current_system_key.reload }.to_not raise_error + end + end +end |