From 6df24b4bc288f8d4bedecabb3e470b120fe26fb4 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 12 Feb 2025 09:24:03 -0500 Subject: [PATCH] Move signed out statuses controller spec examples to request spec (#33907) --- spec/controllers/statuses_controller_spec.rb | 87 -------------------- spec/requests/statuses_spec.rb | 66 +++++++++++++++ 2 files changed, 66 insertions(+), 87 deletions(-) diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb index a6318badfa..9f45afe693 100644 --- a/spec/controllers/statuses_controller_spec.rb +++ b/spec/controllers/statuses_controller_spec.rb @@ -9,93 +9,6 @@ RSpec.describe StatusesController do let(:account) { Fabricate(:account) } let(:status) { Fabricate(:status, account: account) } - context 'when status is public' do - before do - get :show, params: { account_username: status.account.username, id: status.id, format: format } - end - - context 'with HTML' do - let(:format) { 'html' } - - it 'renders status successfully', :aggregate_failures do - expect(response) - .to have_http_status(200) - .and render_template(:show) - expect(response.headers).to include( - 'Vary' => 'Accept, Accept-Language, Cookie', - 'Cache-Control' => include('public'), - 'Link' => include('activity+json') - ) - expect(response.body).to include status.text - end - end - - context 'with JSON' do - let(:format) { 'json' } - - it 'renders ActivityPub Note object successfully', :aggregate_failures do - expect(response) - .to have_http_status(200) - .and have_cacheable_headers.with_vary('Accept, Accept-Language, Cookie') - - expect(response.headers).to include( - 'Content-Type' => include('application/activity+json'), - 'Link' => include('activity+json') - ) - expect(response.parsed_body) - .to include(content: include(status.text)) - end - end - end - - context 'when status is private' do - let(:status) { Fabricate(:status, account: account, visibility: :private) } - - before do - get :show, params: { account_username: status.account.username, id: status.id, format: format } - end - - context 'with JSON' do - let(:format) { 'json' } - - it 'returns http not found' do - expect(response).to have_http_status(404) - end - end - - context 'with HTML' do - let(:format) { 'html' } - - it 'returns http not found' do - expect(response).to have_http_status(404) - end - end - end - - context 'when status is direct' do - let(:status) { Fabricate(:status, account: account, visibility: :direct) } - - before do - get :show, params: { account_username: status.account.username, id: status.id, format: format } - end - - context 'with JSON' do - let(:format) { 'json' } - - it 'returns http not found' do - expect(response).to have_http_status(404) - end - end - - context 'with HTML' do - let(:format) { 'html' } - - it 'returns http not found' do - expect(response).to have_http_status(404) - end - end - end - context 'when signed-in' do let(:user) { Fabricate(:user) } diff --git a/spec/requests/statuses_spec.rb b/spec/requests/statuses_spec.rb index 58a7144b99..e3bf15540a 100644 --- a/spec/requests/statuses_spec.rb +++ b/spec/requests/statuses_spec.rb @@ -45,6 +45,72 @@ RSpec.describe 'Statuses' do .to redirect_to(original_status.url) end end + + context 'when status visibility is public' do + subject { get short_account_status_path(account_username: account.username, id: status.id, format: format) } + + let(:status) { Fabricate(:status, account: account, visibility: :public) } + + context 'with HTML' do + let(:format) { 'html' } + + it 'renders status successfully', :aggregate_failures do + subject + + expect(response) + .to have_http_status(200) + .and render_template(:show) + expect(response.headers).to include( + 'Vary' => 'Accept, Accept-Language, Cookie', + 'Cache-Control' => include('public'), + 'Link' => include('activity+json') + ) + expect(response.body) + .to include(status.text) + end + end + + context 'with JSON' do + let(:format) { 'json' } + + it 'renders ActivityPub Note object successfully', :aggregate_failures do + subject + + expect(response) + .to have_http_status(200) + .and have_cacheable_headers.with_vary('Accept, Accept-Language, Cookie') + + expect(response.headers).to include( + 'Content-Type' => include('application/activity+json'), + 'Link' => include('activity+json') + ) + expect(response.parsed_body) + .to include(content: include(status.text)) + end + end + end + + context 'when status visibility is private' do + let(:status) { Fabricate(:status, account: account, visibility: :private) } + + it 'returns http not found' do + get short_account_status_path(account_username: account.username, id: status.id) + + expect(response) + .to have_http_status(404) + end + end + + context 'when status visibility is direct' do + let(:status) { Fabricate(:status, account: account, visibility: :direct) } + + it 'returns http not found' do + get short_account_status_path(account_username: account.username, id: status.id) + + expect(response) + .to have_http_status(404) + end + end end context 'when signed in' do