Reduce factory usage across spec/services
area (#32098)
This commit is contained in:
parent
4fe7f213a6
commit
e4e07b1c34
21 changed files with 567 additions and 641 deletions
|
@ -16,20 +16,25 @@ RSpec.describe ProcessMentionsService do
|
|||
before do
|
||||
account.block!(individually_blocked_account)
|
||||
account.domain_blocks.create!(domain: domain_blocked_account.domain)
|
||||
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
it 'creates a mention to the non-blocked account' do
|
||||
expect(non_blocked_account.mentions.where(status: status).count).to eq 1
|
||||
it 'creates a mention to the non-blocked account but not the individually or domain blocked accounts' do
|
||||
expect { subject.call(status) }
|
||||
.to create_mention_for_non_blocked
|
||||
.and skip_mention_for_individual
|
||||
.and skip_mention_for_domain_blocked
|
||||
end
|
||||
|
||||
it 'does not create a mention to the individually blocked account' do
|
||||
expect(individually_blocked_account.mentions.where(status: status).count).to eq 0
|
||||
def create_mention_for_non_blocked
|
||||
change { non_blocked_account.mentions.where(status: status).count }.to(1)
|
||||
end
|
||||
|
||||
it 'does not create a mention to the domain-blocked account' do
|
||||
expect(domain_blocked_account.mentions.where(status: status).count).to eq 0
|
||||
def skip_mention_for_individual
|
||||
not_change { individually_blocked_account.mentions.where(status: status).count }.from(0)
|
||||
end
|
||||
|
||||
def skip_mention_for_domain_blocked
|
||||
not_change { domain_blocked_account.mentions.where(status: status).count }.from(0)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -40,11 +45,9 @@ RSpec.describe ProcessMentionsService do
|
|||
context 'with a valid remote user' do
|
||||
let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
|
||||
before do
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
it 'creates a mention' do
|
||||
subject.call(status)
|
||||
|
||||
expect(remote_user.mentions.where(status: status).count).to eq 1
|
||||
end
|
||||
end
|
||||
|
@ -53,11 +56,9 @@ RSpec.describe ProcessMentionsService do
|
|||
let!(:remote_user) { Fabricate(:account, username: 'remote_user', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox') }
|
||||
let(:status) { Fabricate(:status, account: account, text: "Hello @#{remote_user.acct} @#{remote_user.acct} @#{remote_user.acct}", visibility: :public) }
|
||||
|
||||
before do
|
||||
subject.call(status, save_records: false)
|
||||
end
|
||||
|
||||
it 'creates exactly one mention' do
|
||||
subject.call(status, save_records: false)
|
||||
|
||||
expect(status.mentions.size).to eq 1
|
||||
end
|
||||
end
|
||||
|
@ -66,11 +67,9 @@ RSpec.describe ProcessMentionsService do
|
|||
let!(:remote_user) { Fabricate(:account, username: 'sneak', protocol: :activitypub, domain: 'xn--hresiar-mxa.ch', inbox_url: 'http://example.com/inbox') }
|
||||
let!(:status) { Fabricate(:status, account: account, text: 'Hello @sneak@hæresiar.ch') }
|
||||
|
||||
before do
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
it 'creates a mention' do
|
||||
subject.call(status)
|
||||
|
||||
expect(remote_user.mentions.where(status: status).count).to eq 1
|
||||
end
|
||||
end
|
||||
|
@ -79,11 +78,9 @@ RSpec.describe ProcessMentionsService do
|
|||
let!(:remote_user) { Fabricate(:account, username: 'foo', protocol: :activitypub, domain: 'xn--y9a3aq.xn--y9a3aq', inbox_url: 'http://example.com/inbox') }
|
||||
let!(:status) { Fabricate(:status, account: account, text: 'Hello @foo@հայ.հայ') }
|
||||
|
||||
before do
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
it 'creates a mention' do
|
||||
subject.call(status)
|
||||
|
||||
expect(remote_user.mentions.where(status: status).count).to eq 1
|
||||
end
|
||||
end
|
||||
|
@ -95,10 +92,11 @@ RSpec.describe ProcessMentionsService do
|
|||
before do
|
||||
stub_request(:get, 'https://example.com/.well-known/host-meta').to_return(status: 404)
|
||||
stub_request(:get, 'https://example.com/.well-known/webfinger?resource=acct:remote_user@example.com').to_return(status: 500)
|
||||
subject.call(status)
|
||||
end
|
||||
|
||||
it 'creates a mention' do
|
||||
subject.call(status)
|
||||
|
||||
expect(remote_user.mentions.where(status: status).count).to eq 1
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue