Merge remote-tracking branch 'parent/main' into upstream-20240310
This commit is contained in:
commit
5979c0ea1d
345 changed files with 4304 additions and 2540 deletions
|
@ -193,4 +193,57 @@ RSpec.describe 'Media' do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'DELETE /api/v1/media/:id' do
|
||||
subject do
|
||||
delete "/api/v1/media/#{media.id}", headers: headers
|
||||
end
|
||||
|
||||
context 'when media is not attached to a status' do
|
||||
let(:media) { Fabricate(:media_attachment, account: user.account, status: nil) }
|
||||
|
||||
it 'returns http empty response' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
|
||||
expect(MediaAttachment.where(id: media.id)).to_not exist
|
||||
end
|
||||
end
|
||||
|
||||
context 'when media is attached to a status' do
|
||||
let(:media) { Fabricate(:media_attachment, account: user.account, status: Fabricate.build(:status)) }
|
||||
|
||||
it 'returns http unprocessable entity' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(422)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
expect(response.parsed_body).to match(
|
||||
a_hash_including(
|
||||
error: 'Media attachment is currently used by a status'
|
||||
)
|
||||
)
|
||||
|
||||
expect(MediaAttachment.where(id: media.id)).to exist
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the media belongs to somebody else' do
|
||||
let(:media) { Fabricate(:media_attachment, status: nil) }
|
||||
|
||||
it 'returns http not found' do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(404)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
|
||||
expect(MediaAttachment.where(id: media.id)).to exist
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -346,13 +346,30 @@ RSpec.describe '/api/v1/statuses' do
|
|||
|
||||
it_behaves_like 'forbidden for wrong scope', 'read read:statuses'
|
||||
|
||||
it 'removes the status', :aggregate_failures do
|
||||
it 'discards the status and schedules removal as a redraft', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
expect(Status.find_by(id: status.id)).to be_nil
|
||||
expect(RemovalWorker).to have_enqueued_sidekiq_job(status.id, { 'redraft' => true })
|
||||
end
|
||||
|
||||
context 'when called with truthy delete_media' do
|
||||
subject do
|
||||
delete "/api/v1/statuses/#{status.id}?delete_media=true", headers: headers
|
||||
end
|
||||
|
||||
it 'discards the status and schedules removal without the redraft flag', :aggregate_failures do
|
||||
subject
|
||||
|
||||
expect(response).to have_http_status(200)
|
||||
expect(response.content_type)
|
||||
.to start_with('application/json')
|
||||
expect(Status.find_by(id: status.id)).to be_nil
|
||||
expect(RemovalWorker).to have_enqueued_sidekiq_job(status.id, { 'redraft' => false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
20
spec/requests/settings/sessions_spec.rb
Normal file
20
spec/requests/settings/sessions_spec.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Settings Sessions' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before { sign_in(user) }
|
||||
|
||||
describe 'DELETE /settings/sessions/:id' do
|
||||
context 'when session activation does not exist' do
|
||||
it 'returns not found' do
|
||||
delete settings_session_path(123_456_789)
|
||||
|
||||
expect(response)
|
||||
.to have_http_status(404)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
66
spec/requests/status_show_page_spec.rb
Normal file
66
spec/requests/status_show_page_spec.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe 'Statuses' do
|
||||
describe 'GET /@:account_username/:id' do
|
||||
include AccountsHelper
|
||||
|
||||
def site_hostname
|
||||
Rails.configuration.x.web_domain || Rails.configuration.x.local_domain
|
||||
end
|
||||
|
||||
it 'has valid opengraph tags' do
|
||||
account = Fabricate(:account, username: 'alice', display_name: 'Alice')
|
||||
status = Fabricate(:status, account: account, text: 'Hello World')
|
||||
|
||||
get "/@#{account.username}/#{status.id}"
|
||||
|
||||
expect(head_link_icons.size).to eq(3) # Three favicons with sizes
|
||||
|
||||
expect(head_meta_content('og:title')).to match "#{display_name(account)} (#{acct(account)})"
|
||||
expect(head_meta_content('og:type')).to eq 'article'
|
||||
expect(head_meta_content('og:published_time')).to eq status.created_at.iso8601
|
||||
expect(head_meta_content('og:url')).to eq short_account_status_url(account_username: account.username, id: status.id)
|
||||
expect(head_meta_exists('og:locale')).to be false
|
||||
end
|
||||
|
||||
it 'has og:locale opengraph tag if the status has is written in a given language' do
|
||||
status_text = "Una prova d'estatus català"
|
||||
account = Fabricate(:account, username: 'alice', display_name: 'Alice')
|
||||
status = Fabricate(:status, account: account, text: status_text, language: 'ca')
|
||||
|
||||
get "/@#{account.username}/#{status.id}"
|
||||
|
||||
expect(head_meta_content('og:title')).to match "#{display_name(account)} (#{acct(account)})"
|
||||
expect(head_meta_content('og:type')).to eq 'article'
|
||||
expect(head_meta_content('og:published_time')).to eq status.created_at.iso8601
|
||||
expect(head_meta_content('og:url')).to eq short_account_status_url(account_username: account.username, id: status.id)
|
||||
|
||||
expect(head_meta_exists('og:locale')).to be true
|
||||
expect(head_meta_content('og:locale')).to eq 'ca'
|
||||
expect(head_meta_content('og:description')).to eq status_text
|
||||
end
|
||||
|
||||
def head_link_icons
|
||||
response
|
||||
.parsed_body
|
||||
.search('html head link[rel=icon]')
|
||||
end
|
||||
|
||||
def head_meta_content(property)
|
||||
response
|
||||
.parsed_body
|
||||
.search("html head meta[property='#{property}']")
|
||||
.attr('content')
|
||||
.text
|
||||
end
|
||||
|
||||
def head_meta_exists(property)
|
||||
!response
|
||||
.parsed_body
|
||||
.search("html head meta[property='#{property}']")
|
||||
.empty?
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue