From 38a3466741cfa148692c7aa58d8cf207793ac3c1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 27 Aug 2024 03:55:25 -0400 Subject: [PATCH] Convert `api/oembed` controller spec to request spec (#31605) --- .../controllers/api/oembed_controller_spec.rb | 22 ------------- spec/requests/api/oembed_spec.rb | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 22 deletions(-) delete mode 100644 spec/controllers/api/oembed_controller_spec.rb create mode 100644 spec/requests/api/oembed_spec.rb diff --git a/spec/controllers/api/oembed_controller_spec.rb b/spec/controllers/api/oembed_controller_spec.rb deleted file mode 100644 index 5f0ca560d..000000000 --- a/spec/controllers/api/oembed_controller_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'rails_helper' - -RSpec.describe Api::OEmbedController do - render_views - - let(:alice) { Fabricate(:account, username: 'alice') } - let(:status) { Fabricate(:status, text: 'Hello world', account: alice) } - - describe 'GET #show' do - before do - request.host = Rails.configuration.x.local_domain - get :show, params: { url: short_account_status_url(alice, status) }, format: :json - end - - it 'returns private cache control headers', :aggregate_failures do - expect(response).to have_http_status(200) - expect(response.headers['Cache-Control']).to include('private, no-store') - end - end -end diff --git a/spec/requests/api/oembed_spec.rb b/spec/requests/api/oembed_spec.rb new file mode 100644 index 000000000..b9578b37c --- /dev/null +++ b/spec/requests/api/oembed_spec.rb @@ -0,0 +1,33 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'API OEmbed' do + describe 'GET /api/oembed' do + before { host! Rails.configuration.x.local_domain } + + context 'when status is public' do + let(:status) { Fabricate(:status, visibility: :public) } + + it 'returns success with private cache control headers' do + get '/api/oembed', params: { url: short_account_status_url(status.account, status) } + + expect(response) + .to have_http_status(200) + expect(response.headers['Cache-Control']) + .to include('private, no-store') + end + end + + context 'when status is not public' do + let(:status) { Fabricate(:status, visibility: :direct) } + + it 'returns not found' do + get '/api/oembed', params: { url: short_account_status_url(status.account, status) } + + expect(response) + .to have_http_status(404) + end + end + end +end