Reduce hard coding of LOCAL_DOMAIN env value throughout tests (#35025)

This commit is contained in:
Matt Jankowski 2025-06-13 03:58:22 -04:00 committed by GitHub
commit ab7f50ce4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 69 additions and 37 deletions

View file

@ -12,7 +12,7 @@ RSpec.describe Admin::SystemCheck::MediaPrivacyCheck do
describe 'pass?' do
context 'when the media cannot be listed' do
before do
stub_request(:get, /ngrok.io/).to_return(status: 200, body: 'a list of no files')
stub_request(:get, /#{Regexp.quote(Rails.configuration.x.local_domain)}/).to_return(status: 200, body: 'a list of no files')
end
it 'returns true' do

View file

@ -3,15 +3,25 @@
require 'rails_helper'
RSpec.describe OStatus::TagManager do
around do |example|
original = Rails.configuration.x.local_domain
example.run
Rails.configuration.x.local_domain = original
end
describe '#unique_tag' do
before { Rails.configuration.x.local_domain = 'mastodon.example' }
it 'returns a unique tag' do
expect(described_class.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status'
expect(described_class.instance.unique_tag(Time.utc(2000), 12, 'Status')).to eq 'tag:mastodon.example,2000-01-01:objectId=12:objectType=Status'
end
end
describe '#unique_tag_to_local_id' do
before { Rails.configuration.x.local_domain = 'mastodon.example' }
it 'returns the ID part' do
expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12'
expect(described_class.instance.unique_tag_to_local_id('tag:mastodon.example,2000-01-01:objectId=12:objectType=Status', 'Status')).to eql '12'
end
it 'returns nil if it is not local id' do
@ -19,17 +29,19 @@ RSpec.describe OStatus::TagManager do
end
it 'returns nil if it is not expected type' do
expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil
expect(described_class.instance.unique_tag_to_local_id('tag:mastodon.example,2000-01-01:objectId=12:objectType=Block', 'Status')).to be_nil
end
it 'returns nil if it does not have object ID' do
expect(described_class.instance.unique_tag_to_local_id('tag:cb6e6126.ngrok.io,2000-01-01:objectType=Status', 'Status')).to be_nil
expect(described_class.instance.unique_tag_to_local_id('tag:mastodon.example,2000-01-01:objectType=Status', 'Status')).to be_nil
end
end
describe '#local_id?' do
before { Rails.configuration.x.local_domain = 'mastodon.example' }
it 'returns true for a local ID' do
expect(described_class.instance.local_id?('tag:cb6e6126.ngrok.io;objectId=12:objectType=Status')).to be true
expect(described_class.instance.local_id?('tag:mastodon.example;objectId=12:objectType=Status')).to be true
end
it 'returns false for a foreign ID' do
@ -63,7 +75,7 @@ RSpec.describe OStatus::TagManager do
it 'returns the URL for account' do
expect(target.object_type).to eq :person
expect(subject).to eq 'https://cb6e6126.ngrok.io/users/alice'
expect(subject).to eq "https://#{Rails.configuration.x.local_domain}/users/alice"
end
end
end

View file

@ -29,7 +29,10 @@ RSpec.describe TextFormatter do
let(:text) { '@alice' }
it 'creates a mention link' do
expect(subject).to include '<a href="https://cb6e6126.ngrok.io/@alice" class="u-url mention">@<span>alice</span></a></span>'
expect(subject)
.to include(<<~LINK.squish)
<a href="https://#{Rails.configuration.x.local_domain}/@alice" class="u-url mention">@<span>alice</span></a>
LINK
end
end