Use "cacheable response" shared example in more places (#29419)
parent
54e3a82f1d
commit
9e78129e6e
|
@ -14,17 +14,6 @@ describe CustomCssController do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns public cache control header' do
|
it_behaves_like 'cacheable response'
|
||||||
expect(response.headers['Cache-Control']).to include('public')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not set cookies' do
|
|
||||||
expect(response.cookies).to be_empty
|
|
||||||
expect(response.headers['Set-Cookies']).to be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not set sessions' do
|
|
||||||
expect(session).to be_empty
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,23 +12,18 @@ RSpec.describe InstanceActorsController do
|
||||||
get :show, params: { format: format }
|
get :show, params: { format: format }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns http success with correct media type, headers, and session values' do
|
it 'returns http success with correct media type and body' do
|
||||||
expect(response)
|
expect(response)
|
||||||
.to have_http_status(200)
|
.to have_http_status(200)
|
||||||
.and have_attributes(
|
.and have_attributes(
|
||||||
media_type: eq('application/activity+json'),
|
media_type: eq('application/activity+json')
|
||||||
cookies: be_empty
|
|
||||||
)
|
)
|
||||||
|
|
||||||
expect(response.headers)
|
|
||||||
.to include('Cache-Control' => include('public'))
|
|
||||||
.and not_include('Set-Cookies')
|
|
||||||
|
|
||||||
expect(session).to be_empty
|
|
||||||
|
|
||||||
expect(body_as_json)
|
expect(body_as_json)
|
||||||
.to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
.to include(:id, :type, :preferredUsername, :inbox, :publicKey, :inbox, :outbox, :url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it_behaves_like 'cacheable response'
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|
|
@ -14,17 +14,6 @@ describe ManifestsController do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns public cache control header' do
|
it_behaves_like 'cacheable response'
|
||||||
expect(response.headers['Cache-Control']).to include('public')
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not set cookies' do
|
|
||||||
expect(response.cookies).to be_empty
|
|
||||||
expect(response.headers['Set-Cookies']).to be_nil
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not set sessions' do
|
|
||||||
expect(session).to be_empty
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,13 +20,7 @@ RSpec.describe TagsController do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns Vary header' do
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
||||||
expect(response.headers['Vary']).to eq 'Accept, Accept-Language, Cookie'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns public Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'public'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when requested as JSON' do
|
context 'when requested as JSON' do
|
||||||
|
@ -36,13 +30,7 @@ RSpec.describe TagsController do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns Vary header' do
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
||||||
expect(response.headers['Vary']).to eq 'Accept, Accept-Language, Cookie'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns public Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'public'
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
shared_examples 'cacheable response' do |expects_vary: false|
|
shared_examples 'cacheable response' do |expects_vary: false|
|
||||||
it 'sets correct cache and vary headers and does not set cookies or session' do
|
it 'sets correct cache and vary headers and does not set cookies or session', :aggregate_failures do
|
||||||
expect(response.cookies).to be_empty
|
expect(response.cookies).to be_empty
|
||||||
expect(response.headers['Set-Cookies']).to be_nil
|
expect(response.headers['Set-Cookies']).to be_nil
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue