Extract shared example for cacheable response in specs (#25388)
parent
708299bb0d
commit
893b2f33fd
|
@ -7,25 +7,6 @@ RSpec.describe AccountsController do
|
||||||
|
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
|
|
||||||
shared_examples 'cacheable response' do
|
|
||||||
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
|
|
||||||
|
|
||||||
it 'returns Vary header' do
|
|
||||||
expect(response.headers['Vary']).to include 'Accept'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns public Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'public'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
let(:format) { 'html' }
|
let(:format) { 'html' }
|
||||||
|
|
||||||
|
@ -186,7 +167,7 @@ RSpec.describe AccountsController do
|
||||||
expect(response.media_type).to eq 'application/activity+json'
|
expect(response.media_type).to eq 'application/activity+json'
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'cacheable response'
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
||||||
|
|
||||||
it 'renders account' do
|
it 'renders account' do
|
||||||
json = body_as_json
|
json = body_as_json
|
||||||
|
@ -244,7 +225,7 @@ RSpec.describe AccountsController do
|
||||||
expect(response.media_type).to eq 'application/activity+json'
|
expect(response.media_type).to eq 'application/activity+json'
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'cacheable response'
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
||||||
|
|
||||||
it 'renders account' do
|
it 'renders account' do
|
||||||
json = body_as_json
|
json = body_as_json
|
||||||
|
@ -311,7 +292,7 @@ RSpec.describe AccountsController do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
end
|
end
|
||||||
|
|
||||||
it_behaves_like 'cacheable response'
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with a normal account in an RSS request' do
|
context 'with a normal account in an RSS request' do
|
||||||
|
|
|
@ -7,22 +7,6 @@ RSpec.describe ActivityPub::CollectionsController do
|
||||||
let!(:private_pinned) { Fabricate(:status, account: account, text: 'secret private stuff', visibility: :private) }
|
let!(:private_pinned) { Fabricate(:status, account: account, text: 'secret private stuff', visibility: :private) }
|
||||||
let(:remote_account) { nil }
|
let(:remote_account) { nil }
|
||||||
|
|
||||||
shared_examples 'cacheable response' do
|
|
||||||
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
|
|
||||||
response
|
|
||||||
expect(session).to be_empty
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns public Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'public'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
allow(controller).to receive(:signed_request_actor).and_return(remote_account)
|
||||||
|
|
||||||
|
|
|
@ -5,22 +5,6 @@ require 'rails_helper'
|
||||||
RSpec.describe ActivityPub::OutboxesController do
|
RSpec.describe ActivityPub::OutboxesController do
|
||||||
let!(:account) { Fabricate(:account) }
|
let!(:account) { Fabricate(:account) }
|
||||||
|
|
||||||
shared_examples 'cacheable response' do
|
|
||||||
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
|
|
||||||
response
|
|
||||||
expect(session).to be_empty
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns public Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'public'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Fabricate(:status, account: account, visibility: :public)
|
Fabricate(:status, account: account, visibility: :public)
|
||||||
Fabricate(:status, account: account, visibility: :unlisted)
|
Fabricate(:status, account: account, visibility: :unlisted)
|
||||||
|
|
|
@ -8,22 +8,6 @@ RSpec.describe ActivityPub::RepliesController do
|
||||||
let(:remote_reply_id) { 'https://foobar.com/statuses/1234' }
|
let(:remote_reply_id) { 'https://foobar.com/statuses/1234' }
|
||||||
let(:remote_querier) { nil }
|
let(:remote_querier) { nil }
|
||||||
|
|
||||||
shared_examples 'cacheable response' do
|
|
||||||
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
|
|
||||||
response
|
|
||||||
expect(session).to be_empty
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns public Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'public'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
shared_examples 'common behavior' do
|
shared_examples 'common behavior' do
|
||||||
context 'when status is private' do
|
context 'when status is private' do
|
||||||
let(:parent_visibility) { :private }
|
let(:parent_visibility) { :private }
|
||||||
|
|
|
@ -5,25 +5,6 @@ require 'rails_helper'
|
||||||
describe StatusesController do
|
describe StatusesController do
|
||||||
render_views
|
render_views
|
||||||
|
|
||||||
shared_examples 'cacheable response' do
|
|
||||||
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
|
|
||||||
|
|
||||||
it 'returns Vary header' do
|
|
||||||
expect(response.headers['Vary']).to include 'Accept, Accept-Language, Cookie'
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns public Cache-Control header' do
|
|
||||||
expect(response.headers['Cache-Control']).to include 'public'
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'GET #show' do
|
describe 'GET #show' do
|
||||||
let(:account) { Fabricate(:account) }
|
let(:account) { Fabricate(:account) }
|
||||||
let(:status) { Fabricate(:status, account: account) }
|
let(:status) { Fabricate(:status, account: account) }
|
||||||
|
@ -88,7 +69,7 @@ describe StatusesController do
|
||||||
context 'with JSON' do
|
context 'with JSON' do
|
||||||
let(:format) { 'json' }
|
let(:format) { 'json' }
|
||||||
|
|
||||||
it_behaves_like 'cacheable response'
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
||||||
|
|
||||||
it 'renders ActivityPub Note object successfully', :aggregate_failures do
|
it 'renders ActivityPub Note object successfully', :aggregate_failures do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
@ -371,7 +352,7 @@ describe StatusesController do
|
||||||
context 'with JSON' do
|
context 'with JSON' do
|
||||||
let(:format) { 'json' }
|
let(:format) { 'json' }
|
||||||
|
|
||||||
it_behaves_like 'cacheable response'
|
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
|
||||||
|
|
||||||
it 'renders ActivityPub Note object successfully', :aggregate_failures do
|
it 'renders ActivityPub Note object successfully', :aggregate_failures do
|
||||||
expect(response).to have_http_status(200)
|
expect(response).to have_http_status(200)
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
shared_examples 'cacheable response' do |expects_vary: false|
|
||||||
|
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
|
||||||
|
|
||||||
|
if expects_vary
|
||||||
|
it 'returns Vary header' do
|
||||||
|
expect(response.headers['Vary']).to include(expects_vary)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns public Cache-Control header' do
|
||||||
|
expect(response.headers['Cache-Control']).to include('public')
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue