mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-11-27 18:40:12 -05:00
Reduce factory creation (14 -> 8) in ActivityPub::Activity::Block
spec (#32488)
This commit is contained in:
parent
ae676edc2b
commit
527d1253bf
@ -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,61 +18,39 @@ 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
|
||||||
subject { described_class.new(json, sender) }
|
context 'when the recipient does not follow the sender' do
|
||||||
|
|
||||||
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
|
||||||
end
|
|
||||||
|
expect(sender)
|
||||||
|
.to be_blocking(recipient)
|
||||||
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')
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#perform' do
|
it 'creates a block from sender to recipient and sets uri to last received block activity' do
|
||||||
subject { described_class.new(json, sender) }
|
|
||||||
|
|
||||||
before 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 be_blocking(recipient)
|
||||||
end
|
expect(sender.block_relationships.find_by(target_account: recipient).uri)
|
||||||
|
.to eq 'foo'
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when the recipient follows the sender' do
|
context 'when the recipient follows the sender' do
|
||||||
before do
|
before { recipient.follow!(sender) }
|
||||||
recipient.follow!(sender)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe '#perform' do
|
it 'creates a block from sender to recipient and ensures recipient not following sender' do
|
||||||
subject { described_class.new(json, sender) }
|
|
||||||
|
|
||||||
before 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 be_blocking(recipient)
|
||||||
end
|
expect(recipient)
|
||||||
|
.to_not be_following(sender)
|
||||||
it 'ensures recipient is not following sender' do
|
|
||||||
expect(recipient.following?(sender)).to be false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -90,19 +70,13 @@ RSpec.describe ActivityPub::Activity::Block do
|
|||||||
ActivityPub::Activity::Undo.new(undo_json, sender).perform
|
ActivityPub::Activity::Undo.new(undo_json, sender).perform
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#perform' do
|
it 'does not create a block from sender to recipient and ensures recipient not following sender' do
|
||||||
subject { described_class.new(json, sender) }
|
|
||||||
|
|
||||||
before do
|
|
||||||
subject.perform
|
subject.perform
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not create a block from sender to recipient' do
|
expect(sender)
|
||||||
expect(sender.blocking?(recipient)).to be false
|
.to_not be_blocking(recipient)
|
||||||
end
|
expect(recipient)
|
||||||
|
.to_not be_following(sender)
|
||||||
it 'ensures recipient is not following sender' do
|
|
||||||
expect(recipient.following?(sender)).to be false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user