From ca3cc36549a32ff0c299e4010e1f5de0f5c3df88 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 16 Jun 2025 09:12:23 -0400 Subject: [PATCH] Allow more flexible host/port treatment with LOCAL_DOMAIN values in tests (#35040) --- spec/helpers/home_helper_spec.rb | 2 +- spec/mailers/user_mailer_spec.rb | 2 +- spec/models/remote_follow_spec.rb | 11 ++++++++++- spec/requests/status_show_page_spec.rb | 2 +- spec/support/domain_helpers.rb | 4 ++++ spec/system/captcha_spec.rb | 2 +- spec/system/profile_spec.rb | 4 +--- spec/system/redirections_spec.rb | 2 +- .../publish_scheduled_announcement_worker_spec.rb | 15 ++++++++++++--- 9 files changed, 32 insertions(+), 12 deletions(-) diff --git a/spec/helpers/home_helper_spec.rb b/spec/helpers/home_helper_spec.rb index 9093310cf..c3fbff4e8 100644 --- a/spec/helpers/home_helper_spec.rb +++ b/spec/helpers/home_helper_spec.rb @@ -101,7 +101,7 @@ RSpec.describe HomeHelper do allow(helper).to receive(:closed_registrations?).and_return(true) result = helper.sign_up_message - expect(result).to eq t('auth.registration_closed', instance: Rails.configuration.x.local_domain) + expect(result).to eq t('auth.registration_closed', instance: local_domain_uri.host) end end diff --git a/spec/mailers/user_mailer_spec.rb b/spec/mailers/user_mailer_spec.rb index 6586d51a4..2385ede50 100644 --- a/spec/mailers/user_mailer_spec.rb +++ b/spec/mailers/user_mailer_spec.rb @@ -326,7 +326,7 @@ RSpec.describe UserMailer do expect(mail) .to be_present .and(have_subject(I18n.t('user_mailer.announcement_published.subject'))) - .and(have_body_text(I18n.t('user_mailer.announcement_published.description', domain: Rails.configuration.x.local_domain))) + .and(have_body_text(I18n.t('user_mailer.announcement_published.description', domain: local_domain_uri.host))) end end end diff --git a/spec/models/remote_follow_spec.rb b/spec/models/remote_follow_spec.rb index f4879791f..b3ec7b737 100644 --- a/spec/models/remote_follow_spec.rb +++ b/spec/models/remote_follow_spec.rb @@ -61,7 +61,16 @@ RSpec.describe RemoteFollow do let(:account) { Fabricate(:account, username: 'alice') } it 'returns subscribe address' do - expect(subject).to eq "https://quitter.no/main/ostatussub?profile=https%3A%2F%2F#{Rails.configuration.x.local_domain}%2Fusers%2Falice" + expect(subject).to eq(expected_subscribe_url) + end + + def expected_subscribe_url + Addressable::URI.new( + host: 'quitter.no', + path: '/main/ostatussub', + query_values: { profile: "https://#{Rails.configuration.x.local_domain}/users/alice" }, + scheme: 'https' + ).to_s end end end diff --git a/spec/requests/status_show_page_spec.rb b/spec/requests/status_show_page_spec.rb index 758f9dcfd..ac542e841 100644 --- a/spec/requests/status_show_page_spec.rb +++ b/spec/requests/status_show_page_spec.rb @@ -7,7 +7,7 @@ RSpec.describe 'Statuses' do include AccountsHelper def site_hostname - Rails.configuration.x.web_domain || Rails.configuration.x.local_domain + local_domain_uri.host end it 'has valid opengraph tags' do diff --git a/spec/support/domain_helpers.rb b/spec/support/domain_helpers.rb index 051cdaa7d..e975b712c 100644 --- a/spec/support/domain_helpers.rb +++ b/spec/support/domain_helpers.rb @@ -47,6 +47,10 @@ module DomainHelpers .and_yield(resolver) end + def local_domain_uri + Addressable::URI.parse("//#{Rails.configuration.x.local_domain}") + end + private def double_mx(exchange) diff --git a/spec/system/captcha_spec.rb b/spec/system/captcha_spec.rb index 7b7da0db5..89c480221 100644 --- a/spec/system/captcha_spec.rb +++ b/spec/system/captcha_spec.rb @@ -31,7 +31,7 @@ RSpec.describe 'email confirmation flow when captcha is enabled' do # It presents a page with a link to the app callback expect(page) - .to have_content(I18n.t('auth.confirmations.registration_complete', domain: Rails.configuration.x.local_domain)) + .to have_content(I18n.t('auth.confirmations.registration_complete', domain: local_domain_uri.host)) .and have_link(I18n.t('auth.confirmations.clicking_this_link'), href: client_app.confirmation_redirect_uri) end end diff --git a/spec/system/profile_spec.rb b/spec/system/profile_spec.rb index f9449b52c..21bdb712e 100644 --- a/spec/system/profile_spec.rb +++ b/spec/system/profile_spec.rb @@ -5,8 +5,6 @@ require 'rails_helper' RSpec.describe 'Profile' do include ProfileStories - let(:local_domain) { Rails.configuration.x.local_domain } - before do as_a_logged_in_user Fabricate(:user, account: Fabricate(:account, username: 'alice')) @@ -16,7 +14,7 @@ RSpec.describe 'Profile' do visit account_path('alice') expect(page) - .to have_title("alice (@alice@#{local_domain})") + .to have_title("alice (@alice@#{local_domain_uri.host})") end it 'I can change my account' do diff --git a/spec/system/redirections_spec.rb b/spec/system/redirections_spec.rb index e1f1c4240..6abde389d 100644 --- a/spec/system/redirections_spec.rb +++ b/spec/system/redirections_spec.rb @@ -31,6 +31,6 @@ RSpec.describe 'redirection confirmations' do end def redirect_title - I18n.t('redirects.title', instance: Rails.configuration.x.local_domain) + I18n.t('redirects.title', instance: local_domain_uri.host) end end diff --git a/spec/workers/publish_scheduled_announcement_worker_spec.rb b/spec/workers/publish_scheduled_announcement_worker_spec.rb index c4e17903a..01e065f35 100644 --- a/spec/workers/publish_scheduled_announcement_worker_spec.rb +++ b/spec/workers/publish_scheduled_announcement_worker_spec.rb @@ -5,6 +5,14 @@ require 'rails_helper' RSpec.describe PublishScheduledAnnouncementWorker do subject { described_class.new } + around do |example| + original_web_domain = Rails.configuration.x.web_domain + original_default_host = Rails.configuration.action_mailer.default_url_options[:host] + example.run + Rails.configuration.x.web_domain = original_web_domain + Rails.configuration.action_mailer.default_url_options[:host] = original_default_host + end + let!(:remote_account) { Fabricate(:account, domain: 'domain.com', username: 'foo', uri: 'https://domain.com/users/foo') } let!(:remote_status) { Fabricate(:status, uri: 'https://domain.com/users/foo/12345', account: remote_account) } let!(:local_status) { Fabricate(:status) } @@ -12,15 +20,16 @@ RSpec.describe PublishScheduledAnnouncementWorker do describe 'perform' do before do + Rails.configuration.x.web_domain = 'mastodon.social' # The TwitterText Regex needs a real/plausible link target + Rails.configuration.action_mailer.default_url_options[:host] = Rails.configuration.x.web_domain service = instance_double(FetchRemoteStatusService) allow(FetchRemoteStatusService).to receive(:new).and_return(service) allow(service).to receive(:call).with('https://domain.com/users/foo/12345') { remote_status.reload } - - subject.perform(scheduled_announcement.id) end it 'updates the linked statuses' do - expect(scheduled_announcement.reload.status_ids).to eq [remote_status.id, local_status.id] + expect { subject.perform(scheduled_announcement.id) } + .to change { scheduled_announcement.reload.status_ids }.from(nil).to([remote_status.id, local_status.id]) end end end