diff options
author | Matt Jankowski <matt@jankowski.online> | 2024-10-15 10:18:20 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-15 14:18:20 +0000 |
commit | 28131b4b00e65826ac58a034d99b13123461940d (patch) | |
tree | 0e46983d19d3fadc0c534cf30ab1087cb22e2756 | |
parent | 52bc33115d1dc0c544244aa008cb0f2c356531d1 (diff) |
Convert status embed controller to request spec (#32448)
-rw-r--r-- | spec/controllers/statuses_controller_spec.rb | 72 | ||||
-rw-r--r-- | spec/requests/statuses/embed_spec.rb | 74 |
2 files changed, 74 insertions, 72 deletions
diff --git a/spec/controllers/statuses_controller_spec.rb b/spec/controllers/statuses_controller_spec.rb index d9702251f41..121e4aa6c6f 100644 --- a/spec/controllers/statuses_controller_spec.rb +++ b/spec/controllers/statuses_controller_spec.rb @@ -736,76 +736,4 @@ RSpec.describe StatusesController do end end end - - describe 'GET #embed' do - let(:account) { Fabricate(:account) } - let(:status) { Fabricate(:status, account: account) } - - context 'when account is suspended' do - let(:account) { Fabricate(:account, suspended: true) } - - before do - get :embed, 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 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 :embed, 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 :embed, params: { account_username: status.account.username, id: status.id } - end - - it 'renders status successfully', :aggregate_failures do - expect(response) - .to have_http_status(200) - .and render_template(:embed) - expect(response.headers).to include( - 'Vary' => 'Accept, Accept-Language, Cookie', - 'Cache-Control' => include('public'), - 'Link' => include('activity+json') - ) - end - end - - context 'when status is private' do - let(:status) { Fabricate(:status, account: account, visibility: :private) } - - before do - get :embed, 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 direct' do - let(:status) { Fabricate(:status, account: account, visibility: :direct) } - - before do - get :embed, 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 - end end diff --git a/spec/requests/statuses/embed_spec.rb b/spec/requests/statuses/embed_spec.rb new file mode 100644 index 00000000000..33c7ea192c8 --- /dev/null +++ b/spec/requests/statuses/embed_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe 'Status embed' do + describe 'GET /users/:account_username/statuses/:id/embed' do + subject { get "/users/#{account.username}/statuses/#{status.id}/embed" } + + let(:account) { Fabricate(:account) } + let(:status) { Fabricate(:status, account: account) } + + context 'when account is suspended' do + let(:account) { Fabricate(:account, suspended: true) } + + it 'returns http gone' do + subject + + expect(response) + .to have_http_status(410) + 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 'returns http not found' do + subject + + expect(response) + .to have_http_status(404) + end + end + + context 'when status is public' do + it 'renders status successfully', :aggregate_failures do + subject + + expect(response) + .to have_http_status(200) + expect(response.parsed_body.at('body.embed')) + .to be_present + expect(response.headers).to include( + 'Vary' => 'Accept, Accept-Language, Cookie', + 'Cache-Control' => include('public'), + 'Link' => include('activity+json') + ) + end + end + + context 'when status is private' do + let(:status) { Fabricate(:status, account: account, visibility: :private) } + + it 'returns http not found' do + subject + + expect(response) + .to have_http_status(404) + end + end + + context 'when status is direct' do + let(:status) { Fabricate(:status, account: account, visibility: :direct) } + + it 'returns http not found' do + subject + + expect(response) + .to have_http_status(404) + end + end + end +end |