Pull out https/hostname setup for request specs to shared config (#31622)

This commit is contained in:
Matt Jankowski 2024-09-03 11:28:57 -04:00 committed by GitHub
parent dc2f67f69b
commit ef4920c6c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 11 deletions

View file

@ -142,6 +142,12 @@ RSpec.configure do |config|
end
end
config.before :each, type: :request do
# Use https and configured hostname in request spec requests
integration_session.https!
host! Rails.configuration.x.local_domain
end
config.after do
Rails.cache.clear
redis.del(redis.keys)

View file

@ -14,7 +14,7 @@ describe 'The account show page' do
expect(head_meta_content('og:title')).to match alice.display_name
expect(head_meta_content('og:type')).to eq 'profile'
expect(head_meta_content('og:image')).to match '.+'
expect(head_meta_content('og:url')).to match 'http://.+'
expect(head_meta_content('og:url')).to eq short_account_url(username: alice.username)
end
def head_link_icons

View file

@ -10,12 +10,11 @@ describe 'API V1 Streaming' do
Rails.configuration.x.streaming_api_base_url = before
end
let(:headers) { { 'Host' => Rails.configuration.x.web_domain } }
context 'with streaming api on same host' do
describe 'GET /api/v1/streaming' do
it 'raises ActiveRecord::RecordNotFound' do
get '/api/v1/streaming', headers: headers
integration_session.https!(false)
get '/api/v1/streaming'
expect(response).to have_http_status(404)
end

View file

@ -13,7 +13,7 @@ describe 'Link headers' do
it 'contains webfinger url in link header' do
link_header = link_header_with_type('application/jrd+json')
expect(link_header.href).to eq 'http://www.example.com/.well-known/webfinger?resource=acct%3Atest%40cb6e6126.ngrok.io'
expect(link_header.href).to eq 'https://cb6e6126.ngrok.io/.well-known/webfinger?resource=acct%3Atest%40cb6e6126.ngrok.io'
expect(link_header.attr_pairs.first).to eq %w(rel lrdd)
end

View file

@ -4,12 +4,7 @@ require 'rails_helper'
describe 'Media Proxy' do
describe 'GET /media_proxy/:id' do
before do
integration_session.https! # TODO: Move to global rails_helper for all request specs?
host! Rails.configuration.x.local_domain # TODO: Move to global rails_helper for all request specs?
stub_request(:get, 'http://example.com/attachment.png').to_return(request_fixture('avatar.txt'))
end
before { stub_attachment_request }
context 'when attached to a status' do
let(:status) { Fabricate(:status) }
@ -63,5 +58,15 @@ describe 'Media Proxy' do
.to have_http_status(404)
end
end
def stub_attachment_request
stub_request(
:get,
'http://example.com/attachment.png'
)
.to_return(
request_fixture('avatar.txt')
)
end
end
end