forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve spec coverage for collection of
workers/
classes (mastodon#…
- Loading branch information
1 parent
48a52c9
commit 761d2e5
Showing
16 changed files
with
460 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
Fabricator(:account_deletion_request) do | ||
account | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
Fabricator(:import) do | ||
account | ||
type :following | ||
data { attachment_fixture('imports.txt') } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe AccountRefreshWorker do | ||
let(:worker) { described_class.new } | ||
let(:service) { instance_double(ResolveAccountService, call: true) } | ||
|
||
describe '#perform' do | ||
before do | ||
allow(ResolveAccountService).to receive(:new).and_return(service) | ||
end | ||
|
||
context 'when account does not exist' do | ||
it 'returns immediately without processing' do | ||
worker.perform(123_123_123) | ||
|
||
expect(service).to_not have_received(:call) | ||
end | ||
end | ||
|
||
context 'when account exists' do | ||
context 'when account does not need refreshing' do | ||
let(:account) { Fabricate(:account, last_webfingered_at: recent_webfinger_at) } | ||
|
||
it 'returns immediately without processing' do | ||
worker.perform(account.id) | ||
|
||
expect(service).to_not have_received(:call) | ||
end | ||
end | ||
|
||
context 'when account needs refreshing' do | ||
let(:account) { Fabricate(:account, last_webfingered_at: outdated_webfinger_at) } | ||
|
||
it 'schedules an account update' do | ||
worker.perform(account.id) | ||
|
||
expect(service).to have_received(:call) | ||
end | ||
end | ||
|
||
def recent_webfinger_at | ||
(Account::BACKGROUND_REFRESH_INTERVAL - 3.days).ago | ||
end | ||
|
||
def outdated_webfinger_at | ||
(Account::BACKGROUND_REFRESH_INTERVAL + 3.days).ago | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe ActivityPub::PostUpgradeWorker do | ||
let(:worker) { described_class.new } | ||
|
||
describe '#perform' do | ||
let(:domain) { 'host.example' } | ||
|
||
it 'updates relevant values' do | ||
account = Fabricate(:account, domain: domain, last_webfingered_at: 1.day.ago, protocol: :ostatus) | ||
worker.perform(domain) | ||
|
||
expect(account.reload.last_webfingered_at).to be_nil | ||
end | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
spec/workers/activitypub/synchronize_featured_tags_collection_worker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe ActivityPub::SynchronizeFeaturedTagsCollectionWorker do | ||
let(:worker) { described_class.new } | ||
let(:service) { instance_double(ActivityPub::FetchFeaturedTagsCollectionService, call: true) } | ||
|
||
describe '#perform' do | ||
before do | ||
allow(ActivityPub::FetchFeaturedTagsCollectionService).to receive(:new).and_return(service) | ||
end | ||
|
||
let(:account) { Fabricate(:account) } | ||
let(:url) { 'https://host.example' } | ||
|
||
it 'sends the account and url to the service' do | ||
worker.perform(account.id, url) | ||
|
||
expect(service).to have_received(:call).with(account, url) | ||
end | ||
|
||
it 'returns true for non-existent record' do | ||
result = worker.perform(123_123_123, url) | ||
|
||
expect(result).to be(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe Admin::SuspensionWorker do | ||
let(:worker) { described_class.new } | ||
let(:service) { instance_double(SuspendAccountService, call: true) } | ||
|
||
describe '#perform' do | ||
before do | ||
allow(SuspendAccountService).to receive(:new).and_return(service) | ||
end | ||
|
||
let(:account) { Fabricate(:account) } | ||
|
||
it 'sends the account to the service' do | ||
worker.perform(account.id) | ||
|
||
expect(service).to have_received(:call).with(account) | ||
end | ||
|
||
it 'returns true for non-existent record' do | ||
result = worker.perform(123_123_123) | ||
|
||
expect(result).to be(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe AfterAccountDomainBlockWorker do | ||
let(:worker) { described_class.new } | ||
let(:service) { instance_double(AfterBlockDomainFromAccountService, call: true) } | ||
|
||
describe '#perform' do | ||
before do | ||
allow(AfterBlockDomainFromAccountService).to receive(:new).and_return(service) | ||
end | ||
|
||
let(:account) { Fabricate(:account) } | ||
let(:domain) { 'host.example' } | ||
|
||
it 'sends the account and domain to the service' do | ||
worker.perform(account.id, domain) | ||
|
||
expect(service).to have_received(:call).with(account, domain) | ||
end | ||
|
||
it 'returns true for non-existent record' do | ||
result = worker.perform(123_123_123, domain) | ||
|
||
expect(result).to be(true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe BackupWorker do | ||
let(:worker) { described_class.new } | ||
let(:service) { instance_double(BackupService, call: true) } | ||
|
||
describe '#perform' do | ||
before do | ||
allow(BackupService).to receive(:new).and_return(service) | ||
end | ||
|
||
let(:backup) { Fabricate(:backup) } | ||
let!(:other_backup) { Fabricate(:backup, user: backup.user) } | ||
|
||
it 'sends the backup to the service and removes other backups' do | ||
expect do | ||
worker.perform(backup.id) | ||
end.to change(UserMailer.deliveries, :size).by(1) | ||
|
||
expect(service).to have_received(:call).with(backup) | ||
expect { other_backup.reload }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
|
||
context 'when sidekiq retries are exhausted' do | ||
it 'destroys the backup' do | ||
described_class.within_sidekiq_retries_exhausted_block({ 'args' => [backup.id] }) do | ||
worker.perform(backup.id) | ||
end | ||
|
||
expect { backup.reload }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe DeleteMuteWorker do | ||
let(:worker) { described_class.new } | ||
let(:service) { instance_double(UnmuteService, call: true) } | ||
|
||
describe '#perform' do | ||
before do | ||
allow(UnmuteService).to receive(:new).and_return(service) | ||
end | ||
|
||
context 'with an expired mute' do | ||
let(:mute) { Fabricate(:mute, expires_at: 1.day.ago) } | ||
|
||
it 'sends the mute to the service' do | ||
worker.perform(mute.id) | ||
|
||
expect(service).to have_received(:call).with(mute.account, mute.target_account) | ||
end | ||
end | ||
|
||
context 'with an unexpired mute' do | ||
let(:mute) { Fabricate(:mute, expires_at: 1.day.from_now) } | ||
|
||
it 'does not send the mute to the service' do | ||
worker.perform(mute.id) | ||
|
||
expect(service).to_not have_received(:call) | ||
end | ||
end | ||
|
||
context 'with a non-existent mute' do | ||
it 'does not send the mute to the service' do | ||
worker.perform(123_123_123) | ||
|
||
expect(service).to_not have_received(:call) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe ImportWorker do | ||
let(:worker) { described_class.new } | ||
let(:service) { instance_double(ImportService, call: true) } | ||
|
||
describe '#perform' do | ||
before do | ||
allow(ImportService).to receive(:new).and_return(service) | ||
end | ||
|
||
let(:import) { Fabricate(:import) } | ||
|
||
it 'sends the import to the service' do | ||
worker.perform(import.id) | ||
|
||
expect(service).to have_received(:call).with(import) | ||
expect { import.reload }.to raise_error(ActiveRecord::RecordNotFound) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
describe PublishAnnouncementReactionWorker do | ||
let(:worker) { described_class.new } | ||
|
||
describe '#perform' do | ||
before { Fabricate(:account, user: Fabricate(:user, current_sign_in_at: 1.hour.ago)) } | ||
|
||
let(:announcement) { Fabricate(:announcement) } | ||
let(:name) { 'name value' } | ||
|
||
it 'sends the announcement and name to the service when subscribed' do | ||
allow(redis).to receive(:exists?).and_return(true) | ||
allow(redis).to receive(:publish) | ||
|
||
worker.perform(announcement.id, name) | ||
|
||
expect(redis).to have_received(:publish) | ||
end | ||
|
||
it 'does not send the announcement and name to the service when not subscribed' do | ||
allow(redis).to receive(:exists?).and_return(false) | ||
allow(redis).to receive(:publish) | ||
|
||
worker.perform(announcement.id, name) | ||
|
||
expect(redis).to_not have_received(:publish) | ||
end | ||
|
||
it 'returns true for non-existent record' do | ||
result = worker.perform(123_123_123, name) | ||
|
||
expect(result).to be(true) | ||
end | ||
end | ||
end |
Oops, something went wrong.