mirror of https://github.com/Siphonay/mastodon
Combine double subject runs and DRY up change check in bulk import service spec (#29402)
This commit is contained in:
parent
6fed108703
commit
9ce2db4136
|
@ -95,23 +95,27 @@ RSpec.describe BulkImportRowService do
|
||||||
context 'when importing a list row' do
|
context 'when importing a list row' do
|
||||||
let(:import_type) { 'lists' }
|
let(:import_type) { 'lists' }
|
||||||
let(:target_account) { Fabricate(:account) }
|
let(:target_account) { Fabricate(:account) }
|
||||||
|
let(:list_name) { 'my list' }
|
||||||
let(:data) do
|
let(:data) do
|
||||||
{ 'acct' => target_account.acct, 'list_name' => 'my list' }
|
{ 'acct' => target_account.acct, 'list_name' => list_name }
|
||||||
end
|
end
|
||||||
|
|
||||||
shared_examples 'common behavior' do
|
shared_examples 'common behavior' do
|
||||||
|
shared_examples 'row import success and list addition' do
|
||||||
|
it 'returns true and adds the target account to the list' do
|
||||||
|
result = nil
|
||||||
|
expect { result = subject.call(import_row) }
|
||||||
|
.to change { result }.from(nil).to(true)
|
||||||
|
.and add_target_account_to_list
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when the target account is already followed' do
|
context 'when the target account is already followed' do
|
||||||
before do
|
before do
|
||||||
account.follow!(target_account)
|
account.follow!(target_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true' do
|
include_examples 'row import success and list addition'
|
||||||
expect(subject.call(import_row)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'adds the target account to the list' do
|
|
||||||
expect { subject.call(import_row) }.to add_target_account_to_list
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the user already requested to follow the target account' do
|
context 'when the user already requested to follow the target account' do
|
||||||
|
@ -119,35 +123,17 @@ RSpec.describe BulkImportRowService do
|
||||||
account.request_follow!(target_account)
|
account.request_follow!(target_account)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns true' do
|
include_examples 'row import success and list addition'
|
||||||
expect(subject.call(import_row)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'adds the target account to the list' do
|
|
||||||
expect { subject.call(import_row) }.to add_target_account_to_list
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the target account is neither followed nor requested' do
|
context 'when the target account is neither followed nor requested' do
|
||||||
it 'returns true' do
|
include_examples 'row import success and list addition'
|
||||||
expect(subject.call(import_row)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'adds the target account to the list' do
|
|
||||||
expect { subject.call(import_row) }.to add_target_account_to_list
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the target account is the user themself' do
|
context 'when the target account is the user themself' do
|
||||||
let(:target_account) { account }
|
let(:target_account) { account }
|
||||||
|
|
||||||
it 'returns true' do
|
include_examples 'row import success and list addition'
|
||||||
expect(subject.call(import_row)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'adds the target account to the list' do
|
|
||||||
expect { subject.call(import_row) }.to add_target_account_to_list
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_target_account_to_list
|
def add_target_account_to_list
|
||||||
|
@ -161,7 +147,7 @@ RSpec.describe BulkImportRowService do
|
||||||
.joins(:list)
|
.joins(:list)
|
||||||
.exists?(
|
.exists?(
|
||||||
account_id: target_account.id,
|
account_id: target_account.id,
|
||||||
list: { title: 'my list' }
|
list: { title: list_name }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -172,7 +158,7 @@ RSpec.describe BulkImportRowService do
|
||||||
|
|
||||||
context 'when the list exists' do
|
context 'when the list exists' do
|
||||||
before do
|
before do
|
||||||
Fabricate(:list, account: account, title: 'my list')
|
Fabricate(:list, account: account, title: list_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples 'common behavior'
|
include_examples 'common behavior'
|
||||||
|
@ -180,7 +166,7 @@ RSpec.describe BulkImportRowService do
|
||||||
it 'does not create a new list' do
|
it 'does not create a new list' do
|
||||||
account.follow!(target_account)
|
account.follow!(target_account)
|
||||||
|
|
||||||
expect { subject.call(import_row) }.to_not(change { List.where(title: 'my list').count })
|
expect { subject.call(import_row) }.to_not(change { List.where(title: list_name).count })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue