1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00

Use shared_example for does not update username scenarios

This commit is contained in:
Angus McLeod 2024-06-12 13:19:57 +02:00
parent ceb9c8ff84
commit d7cd60dfdd

View file

@ -114,15 +114,7 @@ RSpec.describe ActivityPub::Activity::Update do
end
end
context 'when updated username is not unique for domain' do
before do
Fabricate(:account,
username: updated_username,
domain: 'example.com',
inbox_url: "https://example.com/#{updated_username}/inbox",
outbox_url: "https://example.com/#{updated_username}/outbox")
end
shared_examples 'does not update username' do
it 'updates profile' do
subject.perform
expect(sender.reload.display_name).to eq 'Totally modified now'
@ -134,6 +126,18 @@ RSpec.describe ActivityPub::Activity::Update do
end
end
context 'when updated username is not unique for domain' do
before do
Fabricate(:account,
username: updated_username,
domain: 'example.com',
inbox_url: "https://example.com/#{updated_username}/inbox",
outbox_url: "https://example.com/#{updated_username}/outbox")
end
include_examples 'does not update username'
end
context 'when webfinger of updated username does not contain updated username' do
before do
stub_request(:get, "https://example.com/.well-known/webfinger?resource=acct:#{updated_handle}")
@ -155,15 +159,7 @@ RSpec.describe ActivityPub::Activity::Update do
)
end
it 'updates profile' do
subject.perform
expect(sender.reload.display_name).to eq 'Totally modified now'
end
it 'does not update username' do
subject.perform
expect(sender.reload.username).to eq original_username
end
include_examples 'does not update username'
end
context 'when webfinger request of updated username fails' do
@ -172,15 +168,7 @@ RSpec.describe ActivityPub::Activity::Update do
.to_return(status: 404)
end
it 'updates profile' do
subject.perform
expect(sender.reload.display_name).to eq 'Totally modified now'
end
it 'does not update username' do
subject.perform
expect(sender.reload.username).to eq original_username
end
include_examples 'does not update username'
end
end
end