about summary refs log tree commit diff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/fabricators/access_grant_fabricator.rb6
-rw-r--r--spec/fabricators/preview_card_fabricator.rb1
-rw-r--r--spec/lib/vacuum/access_tokens_vacuum_spec.rb33
-rw-r--r--spec/lib/vacuum/backups_vacuum_spec.rb24
-rw-r--r--spec/lib/vacuum/feeds_vacuum_spec.rb30
-rw-r--r--spec/lib/vacuum/media_attachments_vacuum_spec.rb47
-rw-r--r--spec/lib/vacuum/preview_cards_vacuum_spec.rb36
-rw-r--r--spec/lib/vacuum/statuses_vacuum_spec.rb36
-rw-r--r--spec/lib/vacuum/system_keys_vacuum_spec.rb22
-rw-r--r--spec/workers/scheduler/feed_cleanup_scheduler_spec.rb26
-rw-r--r--spec/workers/scheduler/media_cleanup_scheduler_spec.rb15
11 files changed, 235 insertions, 41 deletions
diff --git a/spec/fabricators/access_grant_fabricator.rb b/spec/fabricators/access_grant_fabricator.rb
new file mode 100644
index 000000000..ae1945f2b
--- /dev/null
+++ b/spec/fabricators/access_grant_fabricator.rb
@@ -0,0 +1,6 @@
+Fabricator :access_grant, from: 'Doorkeeper::AccessGrant' do
+  application
+  resource_owner_id { Fabricate(:user).id }
+  expires_in 3_600
+  redirect_uri { Doorkeeper.configuration.native_redirect_uri }
+end
diff --git a/spec/fabricators/preview_card_fabricator.rb b/spec/fabricators/preview_card_fabricator.rb
index f119c117d..99b5edc43 100644
--- a/spec/fabricators/preview_card_fabricator.rb
+++ b/spec/fabricators/preview_card_fabricator.rb
@@ -3,4 +3,5 @@ Fabricator(:preview_card) do
   title { Faker::Lorem.sentence }
   description { Faker::Lorem.paragraph }
   type 'link'
+  image { attachment_fixture('attachment.jpg') }
 end
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
diff --git a/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb b/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb
deleted file mode 100644
index 82d794594..000000000
--- a/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require 'rails_helper'
-
-describe Scheduler::FeedCleanupScheduler do
-  subject { described_class.new }
-
-  let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) }
-  let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
-
-  it 'clears feeds of inactives' 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
-
-    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
-
-  def feed_key_for(user, subtype = nil)
-    FeedManager.instance.key(:home, user.account_id, subtype)
-  end
-end
diff --git a/spec/workers/scheduler/media_cleanup_scheduler_spec.rb b/spec/workers/scheduler/media_cleanup_scheduler_spec.rb
deleted file mode 100644
index 8a0da67e1..000000000
--- a/spec/workers/scheduler/media_cleanup_scheduler_spec.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-require 'rails_helper'
-
-describe Scheduler::MediaCleanupScheduler do
-  subject { described_class.new }
-
-  let!(:old_media) { Fabricate(:media_attachment, account_id: nil, created_at: 10.days.ago) }
-  let!(:new_media) { Fabricate(:media_attachment, account_id: nil, created_at: 1.hour.ago) }
-
-  it 'removes old media records' do
-    subject.perform
-
-    expect { old_media.reload }.to raise_error(ActiveRecord::RecordNotFound)
-    expect(new_media.reload).to be_persisted
-  end
-end