From 5be938e6619736018cc2a1f13fced461c2308bec Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 17 Jan 2025 05:06:52 -0500 Subject: [PATCH] Migrate visibility interaction checks on statuses to request spec (#33622) --- spec/controllers/statuses_controller_spec.rb | 50 --------------- spec/requests/statuses_spec.rb | 67 ++++++++++++++++++++ 2 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 spec/requests/statuses_spec.rb diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb index e14a7f6916..e589693b17 100644 --- a/spec/controllers/statuses_controller_spec.rb +++ b/spec/controllers/statuses_controller_spec.rb @@ -9,45 +9,6 @@ RSpec.describe StatusesController do let(:account) { Fabricate(:account) } let(:status) { Fabricate(:status, account: account) } - context 'when account is permanently suspended' do - before do - account.suspend! - account.deletion_request.destroy - - get :show, params: { account_username: account.username, id: status.id } - end - - it 'returns http gone' do - expect(response).to have_http_status(410) - end - end - - context 'when account is temporarily suspended' do - before do - account.suspend! - - get :show, params: { account_username: account.username, id: status.id } - end - - it 'returns http forbidden' do - expect(response).to have_http_status(403) - end - end - - context 'when status is a reblog' do - let(:original_account) { Fabricate(:account, domain: 'example.com') } - let(:original_status) { Fabricate(:status, account: original_account, url: 'https://example.com/123') } - let(:status) { Fabricate(:status, account: account, reblog: original_status) } - - before do - get :show, params: { account_username: status.account.username, id: status.id } - end - - it 'redirects to the original status' do - expect(response).to redirect_to(original_status.url) - end - end - context 'when status is public' do before do get :show, params: { account_username: status.account.username, id: status.id, format: format } @@ -142,17 +103,6 @@ RSpec.describe StatusesController do sign_in(user) end - context 'when account blocks user' do - before do - account.block!(user.account) - get :show, params: { account_username: status.account.username, id: status.id } - end - - it 'returns http not found' do - expect(response).to have_http_status(404) - end - end - context 'when status is public' do before do get :show, params: { account_username: status.account.username, id: status.id, format: format } diff --git a/spec/requests/statuses_spec.rb b/spec/requests/statuses_spec.rb new file mode 100644 index 0000000000..f86d67d405 --- /dev/null +++ b/spec/requests/statuses_spec.rb @@ -0,0 +1,67 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Statuses' do + describe 'GET /@:account_username/:id' do + let(:account) { Fabricate(:account) } + let(:status) { Fabricate(:status, account: account) } + + context 'when signed out' do + context 'when account is permanently suspended' do + before do + account.suspend! + account.deletion_request.destroy + end + + it 'returns http gone' do + get "/@#{account.username}/#{status.id}" + + expect(response) + .to have_http_status(410) + end + end + + context 'when account is temporarily suspended' do + before { account.suspend! } + + it 'returns http forbidden' do + get "/@#{account.username}/#{status.id}" + + expect(response) + .to have_http_status(403) + end + end + + context 'when status is a reblog' do + let(:original_account) { Fabricate(:account, domain: 'example.com') } + let(:original_status) { Fabricate(:status, account: original_account, url: 'https://example.com/123') } + let(:status) { Fabricate(:status, account: account, reblog: original_status) } + + it 'redirects to the original status' do + get "/@#{status.account.username}/#{status.id}" + + expect(response) + .to redirect_to(original_status.url) + end + end + end + + context 'when signed in' do + let(:user) { Fabricate(:user) } + + before { sign_in(user) } + + context 'when account blocks user' do + before { account.block!(user.account) } + + it 'returns http not found' do + get "/@#{status.account.username}/#{status.id}" + + expect(response) + .to have_http_status(404) + end + end + end + end +end