Extract shared example for cacheable response in specs (#25388)

local
Matt Jankowski 7 months ago committed by GitHub
parent 708299bb0d
commit 893b2f33fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 25
      spec/controllers/accounts_controller_spec.rb
  2. 16
      spec/controllers/activitypub/collections_controller_spec.rb
  3. 16
      spec/controllers/activitypub/outboxes_controller_spec.rb
  4. 16
      spec/controllers/activitypub/replies_controller_spec.rb
  5. 23
      spec/controllers/statuses_controller_spec.rb
  6. 22
      spec/support/examples/cache.rb

@ -7,25 +7,6 @@ RSpec.describe AccountsController do
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
let(:format) { 'html' }
@ -186,7 +167,7 @@ RSpec.describe AccountsController do
expect(response.media_type).to eq 'application/activity+json'
end
it_behaves_like 'cacheable response'
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
it 'renders account' do
json = body_as_json
@ -244,7 +225,7 @@ RSpec.describe AccountsController do
expect(response.media_type).to eq 'application/activity+json'
end
it_behaves_like 'cacheable response'
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
it 'renders account' do
json = body_as_json
@ -311,7 +292,7 @@ RSpec.describe AccountsController do
expect(response).to have_http_status(200)
end
it_behaves_like 'cacheable response'
it_behaves_like 'cacheable response', expects_vary: 'Accept, Accept-Language, Cookie'
end
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(: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
allow(controller).to receive(:signed_request_actor).and_return(remote_account)

@ -5,22 +5,6 @@ require 'rails_helper'
RSpec.describe ActivityPub::OutboxesController do
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
Fabricate(:status, account: account, visibility: :public)
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_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
context 'when status is private' do
let(:parent_visibility) { :private }

@ -5,25 +5,6 @@ require 'rails_helper'
describe StatusesController do
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
let(:account) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: account) }
@ -88,7 +69,7 @@ describe StatusesController do
context 'with JSON' do
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
expect(response).to have_http_status(200)
@ -371,7 +352,7 @@ describe StatusesController do
context 'with JSON' do
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
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…
Cancel
Save