mirror of
https://github.com/mastodon/mastodon
synced 2025-04-12 00:56:38 +02:00
Add specs for model hooks
This commit is contained in:
parent
ddceb88367
commit
f106686f47
@ -85,7 +85,7 @@ class Account < ApplicationRecord
|
||||
include Account::Associations
|
||||
include Account::Avatar
|
||||
include Account::Counters
|
||||
include Account::FaspConcern if Mastodon::Feature.fasp_enabled?
|
||||
include Account::FaspConcern
|
||||
include Account::FinderConcern
|
||||
include Account::Header
|
||||
include Account::Interactions
|
||||
|
@ -12,6 +12,7 @@ module Account::FaspConcern
|
||||
private
|
||||
|
||||
def announce_new_account_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless discoverable?
|
||||
|
||||
uri = ActivityPub::TagManager.instance.uri_for(self)
|
||||
@ -19,6 +20,7 @@ module Account::FaspConcern
|
||||
end
|
||||
|
||||
def announce_updated_account_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless discoverable? || saved_change_to_discoverable?
|
||||
|
||||
uri = ActivityPub::TagManager.instance.uri_for(self)
|
||||
@ -26,6 +28,7 @@ module Account::FaspConcern
|
||||
end
|
||||
|
||||
def announce_deleted_account_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless discoverable?
|
||||
|
||||
uri = ActivityPub::TagManager.instance.uri_for(self)
|
||||
|
@ -10,6 +10,8 @@ module Favourite::FaspConcern
|
||||
private
|
||||
|
||||
def announce_trends_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
|
||||
Fasp::AnnounceTrendWorker.perform_async(status_id, 'favourite')
|
||||
end
|
||||
end
|
||||
|
@ -13,6 +13,7 @@ module Status::FaspConcern
|
||||
private
|
||||
|
||||
def announce_new_content_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless account_indexable? && public_visibility?
|
||||
|
||||
store_uri unless uri # TODO: solve this more elegantly
|
||||
@ -20,18 +21,21 @@ module Status::FaspConcern
|
||||
end
|
||||
|
||||
def announce_updated_content_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless account_indexable? && public_visibility_or_just_changed?
|
||||
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'update')
|
||||
end
|
||||
|
||||
def announce_deleted_content_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless account_indexable? && public_visibility?
|
||||
|
||||
Fasp::AnnounceContentLifecycleEventWorker.perform_async(uri, 'delete')
|
||||
end
|
||||
|
||||
def announce_trends_to_subscribed_fasp
|
||||
return unless Mastodon::Feature.fasp_enabled?
|
||||
return unless account_indexable?
|
||||
|
||||
candidate_id, trend_source =
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
class Favourite < ApplicationRecord
|
||||
include Paginable
|
||||
include Favourite::FaspConcern if Mastodon::Feature.fasp_enabled?
|
||||
include Favourite::FaspConcern
|
||||
|
||||
update_index('statuses', :status)
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Status < ApplicationRecord
|
||||
include Discard::Model
|
||||
include Paginable
|
||||
include RateLimitable
|
||||
include Status::FaspConcern if Mastodon::Feature.fasp_enabled?
|
||||
include Status::FaspConcern
|
||||
include Status::FetchRepliesConcern
|
||||
include Status::SafeReblogInsert
|
||||
include Status::SearchConcern
|
||||
|
83
spec/models/concerns/account/fasp_concern_spec.rb
Normal file
83
spec/models/concerns/account/fasp_concern_spec.rb
Normal file
@ -0,0 +1,83 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Account::FaspConcern, feature: :fasp do
|
||||
describe '#create' do
|
||||
let(:discoverable_attributes) do
|
||||
Fabricate.attributes_for(:account).except('user_id')
|
||||
end
|
||||
let(:undiscoverable_attributes) do
|
||||
discoverable_attributes.merge('discoverable' => false)
|
||||
end
|
||||
|
||||
context 'when account is discoverable' do
|
||||
it 'queues a job to notify provider' do
|
||||
Account.create(discoverable_attributes)
|
||||
|
||||
expect(Fasp::AnnounceAccountLifecycleEventWorker).to have_enqueued_sidekiq_job
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not discoverable' do
|
||||
it 'does not queue a job' do
|
||||
Account.create(undiscoverable_attributes)
|
||||
|
||||
expect(Fasp::AnnounceAccountLifecycleEventWorker).to_not have_enqueued_sidekiq_job
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before do
|
||||
# Create account and clear sidekiq queue so we only catch
|
||||
# jobs queued as part of the update
|
||||
account
|
||||
Sidekiq::Worker.clear_all
|
||||
end
|
||||
|
||||
context 'when account is discoverable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
it 'queues a job to notify provider' do
|
||||
expect { account.touch }.to enqueue_sidekiq_job(Fasp::AnnounceAccountLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account was discoverable before' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
it 'queues a job to notify provider' do
|
||||
expect do
|
||||
account.update(discoverable: false)
|
||||
end.to enqueue_sidekiq_job(Fasp::AnnounceAccountLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account has not been discoverable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com', discoverable: false) }
|
||||
|
||||
it 'does not queue a job' do
|
||||
expect { account.touch }.to_not enqueue_sidekiq_job(Fasp::AnnounceAccountLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
context 'when account is discoverable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
it 'queues a job to notify provider' do
|
||||
expect { account.destroy }.to enqueue_sidekiq_job(Fasp::AnnounceAccountLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not discoverable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com', discoverable: false) }
|
||||
|
||||
it 'does not queue a job' do
|
||||
expect { account.destroy }.to_not enqueue_sidekiq_job(Fasp::AnnounceAccountLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
spec/models/concerns/favourite/fasp_concern_spec.rb
Normal file
11
spec/models/concerns/favourite/fasp_concern_spec.rb
Normal file
@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Favourite::FaspConcern, feature: :fasp do
|
||||
describe '#create' do
|
||||
it 'queues a job to notify provider' do
|
||||
expect { Fabricate(:favourite) }.to enqueue_sidekiq_job(Fasp::AnnounceTrendWorker)
|
||||
end
|
||||
end
|
||||
end
|
133
spec/models/concerns/status/fasp_concern_spec.rb
Normal file
133
spec/models/concerns/status/fasp_concern_spec.rb
Normal file
@ -0,0 +1,133 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Status::FaspConcern, feature: :fasp do
|
||||
describe '#create' do
|
||||
context 'when account is indexable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
context 'when status is public' do
|
||||
it 'queues a job to notify provider of new status' do
|
||||
expect do
|
||||
Fabricate(:status, account:)
|
||||
end.to enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is not public' do
|
||||
it 'does not queue a job' do
|
||||
expect do
|
||||
Fabricate(:status, account:, visibility: :unlisted)
|
||||
end.to_not enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is in reply to another' do
|
||||
it 'queues a job to notify provider of possible trend' do
|
||||
parent = Fabricate(:status)
|
||||
expect do
|
||||
Fabricate(:status, account:, thread: parent)
|
||||
end.to enqueue_sidekiq_job(Fasp::AnnounceTrendWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status is a reblog of another' do
|
||||
it 'queues a job to notify provider of possible trend' do
|
||||
original = Fabricate(:status, account:)
|
||||
expect do
|
||||
Fabricate(:status, account:, reblog: original)
|
||||
end.to enqueue_sidekiq_job(Fasp::AnnounceTrendWorker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not indexable' do
|
||||
let(:account) { Fabricate(:account, indexable: false) }
|
||||
|
||||
it 'does not queue a job' do
|
||||
expect do
|
||||
Fabricate(:status, account:)
|
||||
end.to_not enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update' do
|
||||
before do
|
||||
# Create status and clear sidekiq queues to only catch
|
||||
# jobs queued due to the update
|
||||
status
|
||||
Sidekiq::Worker.clear_all
|
||||
end
|
||||
|
||||
context 'when account is indexable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
let(:status) { Fabricate(:status, account:, visibility:) }
|
||||
|
||||
context 'when status is public' do
|
||||
let(:visibility) { :public }
|
||||
|
||||
it 'queues a job to notify provider' do
|
||||
expect { status.touch }.to enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status just switched to non-public' do
|
||||
let(:visibility) { :public }
|
||||
|
||||
it 'queues a job to notify provider' do
|
||||
expect do
|
||||
status.update(visibility: :unlisted)
|
||||
end.to enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when status has not been public' do
|
||||
let(:visibility) { :unlisted }
|
||||
|
||||
it 'does not queue a job' do
|
||||
expect do
|
||||
status.touch
|
||||
end.to_not enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not indexable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com', indexable: false) }
|
||||
let(:status) { Fabricate(:status, account:) }
|
||||
|
||||
it 'does not queue a job' do
|
||||
expect { status.touch }.to_not enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#destroy' do
|
||||
let(:status) { Fabricate(:status, account:) }
|
||||
|
||||
before do
|
||||
# Create status and clear sidekiq queues to only catch
|
||||
# jobs queued due to the update
|
||||
status
|
||||
Sidekiq::Worker.clear_all
|
||||
end
|
||||
|
||||
context 'when account is indexable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com') }
|
||||
|
||||
it 'queues a job to notify provider' do
|
||||
expect { status.destroy }.to enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not indexable' do
|
||||
let(:account) { Fabricate(:account, domain: 'example.com', indexable: false) }
|
||||
|
||||
it 'does not queue a job' do
|
||||
expect { status.destroy }.to_not enqueue_sidekiq_job(Fasp::AnnounceContentLifecycleEventWorker)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user