mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-22 10:38:07 +01:00
Reduce factory creation (14 -> 8) in ActivityPub::Activity::Block
spec (#32488)
This commit is contained in:
parent
ae676edc2b
commit
527d1253bf
1 changed files with 51 additions and 77 deletions
|
@ -3,6 +3,8 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ActivityPub::Activity::Block do
|
RSpec.describe ActivityPub::Activity::Block do
|
||||||
|
subject { described_class.new(json, sender) }
|
||||||
|
|
||||||
let(:sender) { Fabricate(:account) }
|
let(:sender) { Fabricate(:account) }
|
||||||
let(:recipient) { Fabricate(:account) }
|
let(:recipient) { Fabricate(:account) }
|
||||||
|
|
||||||
|
@ -16,93 +18,65 @@ RSpec.describe ActivityPub::Activity::Block do
|
||||||
}.with_indifferent_access
|
}.with_indifferent_access
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the recipient does not follow the sender' do
|
describe '#perform' do
|
||||||
describe '#perform' do
|
context 'when the recipient does not follow the sender' do
|
||||||
subject { described_class.new(json, sender) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
subject.perform
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'creates a block from sender to recipient' do
|
it 'creates a block from sender to recipient' do
|
||||||
expect(sender.blocking?(recipient)).to be true
|
subject.perform
|
||||||
|
|
||||||
|
expect(sender)
|
||||||
|
.to be_blocking(recipient)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the recipient is already blocked' do
|
context 'when the recipient is already blocked' do
|
||||||
before do
|
before { sender.block!(recipient, uri: 'old') }
|
||||||
sender.block!(recipient, uri: 'old')
|
|
||||||
|
it 'creates a block from sender to recipient and sets uri to last received block activity' do
|
||||||
|
subject.perform
|
||||||
|
|
||||||
|
expect(sender)
|
||||||
|
.to be_blocking(recipient)
|
||||||
|
expect(sender.block_relationships.find_by(target_account: recipient).uri)
|
||||||
|
.to eq 'foo'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#perform' do
|
context 'when the recipient follows the sender' do
|
||||||
subject { described_class.new(json, sender) }
|
before { recipient.follow!(sender) }
|
||||||
|
|
||||||
|
it 'creates a block from sender to recipient and ensures recipient not following sender' do
|
||||||
|
subject.perform
|
||||||
|
|
||||||
|
expect(sender)
|
||||||
|
.to be_blocking(recipient)
|
||||||
|
expect(recipient)
|
||||||
|
.to_not be_following(sender)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when a matching undo has been received first' do
|
||||||
|
let(:undo_json) do
|
||||||
|
{
|
||||||
|
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||||
|
id: 'bar',
|
||||||
|
type: 'Undo',
|
||||||
|
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||||
|
object: json,
|
||||||
|
}.with_indifferent_access
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
recipient.follow!(sender)
|
||||||
|
ActivityPub::Activity::Undo.new(undo_json, sender).perform
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does not create a block from sender to recipient and ensures recipient not following sender' do
|
||||||
subject.perform
|
subject.perform
|
||||||
end
|
|
||||||
|
|
||||||
it 'creates a block from sender to recipient' do
|
expect(sender)
|
||||||
expect(sender.blocking?(recipient)).to be true
|
.to_not be_blocking(recipient)
|
||||||
end
|
expect(recipient)
|
||||||
|
.to_not be_following(sender)
|
||||||
it 'sets the uri to that of last received block activity' do
|
|
||||||
expect(sender.block_relationships.find_by(target_account: recipient).uri).to eq 'foo'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when the recipient follows the sender' do
|
|
||||||
before do
|
|
||||||
recipient.follow!(sender)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#perform' do
|
|
||||||
subject { described_class.new(json, sender) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
subject.perform
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'creates a block from sender to recipient' do
|
|
||||||
expect(sender.blocking?(recipient)).to be true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'ensures recipient is not following sender' do
|
|
||||||
expect(recipient.following?(sender)).to be false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context 'when a matching undo has been received first' do
|
|
||||||
let(:undo_json) do
|
|
||||||
{
|
|
||||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
|
||||||
id: 'bar',
|
|
||||||
type: 'Undo',
|
|
||||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
|
||||||
object: json,
|
|
||||||
}.with_indifferent_access
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
|
||||||
recipient.follow!(sender)
|
|
||||||
ActivityPub::Activity::Undo.new(undo_json, sender).perform
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#perform' do
|
|
||||||
subject { described_class.new(json, sender) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
subject.perform
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not create a block from sender to recipient' do
|
|
||||||
expect(sender.blocking?(recipient)).to be false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'ensures recipient is not following sender' do
|
|
||||||
expect(recipient.following?(sender)).to be false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue