Allow more flexible host/port treatment with LOCAL_DOMAIN values in tests (#35040)
This commit is contained in:
		@@ -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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user