Merge branch 'main' into glitch-soc/merge-upstream

Conflicts:
- `.prettierignore`:
  Upstream added a line at the end of the file, while glitch-soc had its own
  extra lines.
  Took upstream's change.
- `CONTRIBUTING.md`:
  We have our custom CONTRIBUTING.md quoting upstream. Upstream made changes.
  Ported upstream changes.
- `app/controllers/application_controller.rb`:
  Upstream made code style changes in a method that is entirely replaced
  in glitch-soc.
  Ignored the change.
- `app/models/account.rb`:
  Code style changes textually close to glitch-soc-specific changes.
  Ported upstream changes.
- `lib/sanitize_ext/sanitize_config.rb`:
  Upstream code style changes.
  Ignored them.
This commit is contained in:
Claire
2023-02-25 14:00:40 +01:00
946 changed files with 4147 additions and 3072 deletions

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::CredentialsController do
@@ -51,7 +53,7 @@ describe Api::V1::Accounts::CredentialsController do
expect(user.account.avatar).to exist
expect(user.account.header).to exist
expect(user.setting_default_privacy).to eq('unlisted')
expect(user.setting_default_sensitive).to eq(true)
expect(user.setting_default_sensitive).to be(true)
end
it 'queues up an account update distribution' do
@@ -80,7 +82,7 @@ describe Api::V1::Accounts::CredentialsController do
end
it 'returns http unprocessable entity' do
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(422)
end
end
end
@@ -88,20 +90,20 @@ describe Api::V1::Accounts::CredentialsController do
context 'without an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { nil }
allow(controller).to receive(:doorkeeper_token).and_return(nil)
end
describe 'GET #show' do
it 'returns http unauthorized' do
get :show
expect(response).to have_http_status(:unauthorized)
expect(response).to have_http_status(401)
end
end
describe 'PATCH #update' do
it 'returns http unauthorized' do
patch :update, params: { note: 'Foo' }
expect(response).to have_http_status(:unauthorized)
expect(response).to have_http_status(401)
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::FollowerAccountsController do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::FollowingAccountsController do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::ListsController do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::NotesController do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::RelationshipsController do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Accounts::SearchController, type: :controller do

View File

@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::StatusesController do
@@ -16,7 +17,7 @@ describe Api::V1::Accounts::StatusesController do
it 'returns http success' do
get :index, params: { account_id: user.account.id, limit: 1 }
expect(response).to have_http_status(:ok)
expect(response).to have_http_status(200)
end
it 'returns expected headers' do
@@ -29,7 +30,7 @@ describe Api::V1::Accounts::StatusesController do
it 'returns http success' do
get :index, params: { account_id: user.account.id, only_media: true }
expect(response).to have_http_status(:ok)
expect(response).to have_http_status(200)
end
end
@@ -44,7 +45,7 @@ describe Api::V1::Accounts::StatusesController do
end
it 'returns http success' do
expect(response).to have_http_status(:ok)
expect(response).to have_http_status(200)
end
it 'returns posts along with self replies' do
@@ -63,7 +64,7 @@ describe Api::V1::Accounts::StatusesController do
it 'returns http success' do
get :index, params: { account_id: user.account.id, pinned: true }
expect(response).to have_http_status(:ok)
expect(response).to have_http_status(200)
end
end
@@ -79,7 +80,7 @@ describe Api::V1::Accounts::StatusesController do
it 'returns http success' do
get :index, params: { account_id: account.id, pinned: true }
expect(response).to have_http_status(:ok)
expect(response).to have_http_status(200)
end
context 'when user does not follow account' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::AccountsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::AccountActionsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::AccountsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::DomainAllowsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::DomainBlocksController, type: :controller do
@@ -73,16 +75,15 @@ RSpec.describe Api::V1::Admin::DomainBlocksController, type: :controller do
describe 'PUT #update' do
let!(:remote_account) { Fabricate(:account, domain: 'example.com') }
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }
let(:subject) do
post :update, params: { id: domain_block.id, domain: 'example.com', severity: new_severity }
end
let(:domain_block) { Fabricate(:domain_block, domain: 'example.com', severity: original_severity) }
before do
BlockDomainService.new.call(domain_block)
end
let(:subject) do
post :update, params: { id: domain_block.id, domain: 'example.com', severity: new_severity }
end
context 'downgrading a domain suspension to silence' do
let(:original_severity) { 'suspend' }
let(:new_severity) { 'silence' }

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::ReportsController, type: :controller do

View File

@@ -15,7 +15,7 @@ RSpec.describe Api::V1::Announcements::ReactionsController, type: :controller do
context 'without token' do
it 'returns http unauthorized' do
put :update, params: { announcement_id: announcement.id, id: '😂' }
expect(response).to have_http_status :unauthorized
expect(response).to have_http_status 401
end
end
@@ -43,7 +43,7 @@ RSpec.describe Api::V1::Announcements::ReactionsController, type: :controller do
context 'without token' do
it 'returns http unauthorized' do
delete :destroy, params: { announcement_id: announcement.id, id: '😂' }
expect(response).to have_http_status :unauthorized
expect(response).to have_http_status 401
end
end

View File

@@ -15,7 +15,7 @@ RSpec.describe Api::V1::AnnouncementsController, type: :controller do
context 'without token' do
it 'returns http unprocessable entity' do
get :index
expect(response).to have_http_status :unprocessable_entity
expect(response).to have_http_status 422
end
end
@@ -35,7 +35,7 @@ RSpec.describe Api::V1::AnnouncementsController, type: :controller do
context 'without token' do
it 'returns http unauthorized' do
post :dismiss, params: { id: announcement.id }
expect(response).to have_http_status :unauthorized
expect(response).to have_http_status 401
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Apps::CredentialsController do
@@ -30,13 +32,13 @@ describe Api::V1::Apps::CredentialsController do
context 'without an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { nil }
allow(controller).to receive(:doorkeeper_token).and_return(nil)
end
describe 'GET #show' do
it 'returns http unauthorized' do
get :show
expect(response).to have_http_status(:unauthorized)
expect(response).to have_http_status(401)
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::AppsController, type: :controller do
@@ -68,7 +70,7 @@ RSpec.describe Api::V1::AppsController, type: :controller do
end
context 'with a too-long website' do
let(:website) { 'https://foo.bar/' + ('hoge' * 2_000) }
let(:website) { "https://foo.bar/#{'hoge' * 2_000}" }
it 'returns http unprocessable entity' do
expect(response).to have_http_status(422)
@@ -76,7 +78,7 @@ RSpec.describe Api::V1::AppsController, type: :controller do
end
context 'with a too-long redirect_uris' do
let(:redirect_uris) { 'https://foo.bar/' + ('hoge' * 2_000) }
let(:redirect_uris) { "https://foo.bar/#{'hoge' * 2_000}" }
it 'returns http unprocessable entity' do
expect(response).to have_http_status(422)

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::BlocksController, type: :controller do
@@ -37,13 +39,13 @@ RSpec.describe Api::V1::BlocksController, type: :controller do
it 'sets pagination header for next path' do
blocks = 2.times.map { Fabricate(:block, account: user.account) }
get :index, params: { limit: 1, since_id: blocks[0] }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v1_blocks_url(limit: 1, max_id: blocks[1])
end
it 'sets pagination header for previous path' do
block = Fabricate(:block, account: user.account)
get :index
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_blocks_url(since_id: block)
expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq api_v1_blocks_url(since_id: block)
end
it 'returns http success' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::BookmarksController, type: :controller do
@@ -10,7 +12,7 @@ RSpec.describe Api::V1::BookmarksController, type: :controller do
context 'without token' do
it 'returns http unauthorized' do
get :index
expect(response).to have_http_status :unauthorized
expect(response).to have_http_status 401
end
end
@@ -24,7 +26,7 @@ RSpec.describe Api::V1::BookmarksController, type: :controller do
it 'returns http forbidden' do
get :index
expect(response).to have_http_status :forbidden
expect(response).to have_http_status 403
end
end
@@ -38,7 +40,7 @@ RSpec.describe Api::V1::BookmarksController, type: :controller do
it 'returns http unprocessable entity' do
get :index
expect(response).to have_http_status :unprocessable_entity
expect(response).to have_http_status 422
end
end
@@ -63,14 +65,14 @@ RSpec.describe Api::V1::BookmarksController, type: :controller do
get :index, params: { limit: 1 }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq "http://test.host/api/v1/bookmarks?limit=1&max_id=#{bookmark.id}"
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq "http://test.host/api/v1/bookmarks?limit=1&min_id=#{bookmark.id}"
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq "http://test.host/api/v1/bookmarks?limit=1&max_id=#{bookmark.id}"
expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq "http://test.host/api/v1/bookmarks?limit=1&min_id=#{bookmark.id}"
end
it 'does not add pagination headers if not necessary' do
get :index
expect(response.headers['Link']).to eq nil
expect(response.headers['Link']).to be_nil
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::ConversationsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::DomainBlocksController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
@@ -16,7 +18,7 @@ RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
context 'from a random app' do
it 'returns http forbidden' do
post :create
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
@@ -30,7 +32,7 @@ RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
it 'returns http forbidden' do
post :create
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
context 'but user changed e-mail and has not confirmed it' do
@@ -57,7 +59,7 @@ RSpec.describe Api::V1::Emails::ConfirmationsController, type: :controller do
context 'without an oauth token' do
it 'returns http unauthorized' do
post :create
expect(response).to have_http_status(:unauthorized)
expect(response).to have_http_status(401)
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FavouritesController, type: :controller do
@@ -10,7 +12,7 @@ RSpec.describe Api::V1::FavouritesController, type: :controller do
context 'without token' do
it 'returns http unauthorized' do
get :index
expect(response).to have_http_status :unauthorized
expect(response).to have_http_status 401
end
end
@@ -24,7 +26,7 @@ RSpec.describe Api::V1::FavouritesController, type: :controller do
it 'returns http forbidden' do
get :index
expect(response).to have_http_status :forbidden
expect(response).to have_http_status 403
end
end
@@ -38,7 +40,7 @@ RSpec.describe Api::V1::FavouritesController, type: :controller do
it 'returns http unprocessable entity' do
get :index
expect(response).to have_http_status :unprocessable_entity
expect(response).to have_http_status 422
end
end
@@ -63,14 +65,14 @@ RSpec.describe Api::V1::FavouritesController, type: :controller do
get :index, params: { limit: 1 }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq "http://test.host/api/v1/favourites?limit=1&max_id=#{favourite.id}"
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq "http://test.host/api/v1/favourites?limit=1&min_id=#{favourite.id}"
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq "http://test.host/api/v1/favourites?limit=1&max_id=#{favourite.id}"
expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq "http://test.host/api/v1/favourites?limit=1&min_id=#{favourite.id}"
end
it 'does not add pagination headers if not necessary' do
get :index
expect(response.headers['Link']).to eq nil
expect(response.headers['Link']).to be_nil
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FiltersController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FollowRequestsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FollowedTagsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Lists::AccountsController do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::ListsController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::MarkersController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::MediaController, type: :controller do
@@ -19,7 +21,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
end
it 'returns http 422' do
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(422)
end
end
@@ -106,7 +108,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
it 'returns http not found' do
put :update, params: { id: media.id, description: 'Lorem ipsum!!!' }
expect(response).to have_http_status(:not_found)
expect(response).to have_http_status(404)
end
end
@@ -126,7 +128,7 @@ RSpec.describe Api::V1::MediaController, type: :controller do
let(:status) { Fabricate(:status, account: user.account) }
it 'returns http not found' do
expect(response).to have_http_status(:not_found)
expect(response).to have_http_status(404)
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::MutesController, type: :controller do
@@ -37,13 +39,13 @@ RSpec.describe Api::V1::MutesController, type: :controller do
it 'sets pagination header for next path' do
mutes = 2.times.map { Fabricate(:mute, account: user.account) }
get :index, params: { limit: 1, since_id: mutes[0] }
expect(response.headers['Link'].find_link(['rel', 'next']).href).to eq api_v1_mutes_url(limit: 1, max_id: mutes[1])
expect(response.headers['Link'].find_link(%w(rel next)).href).to eq api_v1_mutes_url(limit: 1, max_id: mutes[1])
end
it 'sets pagination header for previous path' do
mute = Fabricate(:mute, account: user.account)
get :index
expect(response.headers['Link'].find_link(['rel', 'prev']).href).to eq api_v1_mutes_url(since_id: mute)
expect(response.headers['Link'].find_link(%w(rel prev)).href).to eq api_v1_mutes_url(since_id: mute)
end
it 'returns http success' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::NotificationsController, type: :controller do
@@ -70,19 +72,19 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
end
it 'includes reblog' do
expect(body_as_json.map { |x| x[:type] }).to include 'reblog'
expect(body_as_json.pluck(:type)).to include 'reblog'
end
it 'includes mention' do
expect(body_as_json.map { |x| x[:type] }).to include 'mention'
expect(body_as_json.pluck(:type)).to include 'mention'
end
it 'includes favourite' do
expect(body_as_json.map { |x| x[:type] }).to include 'favourite'
expect(body_as_json.pluck(:type)).to include 'favourite'
end
it 'includes follow' do
expect(body_as_json.map { |x| x[:type] }).to include 'follow'
expect(body_as_json.pluck(:type)).to include 'follow'
end
end
@@ -125,7 +127,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
it 'returns everything but excluded type' do
expect(body_as_json.size).to_not eq 0
expect(body_as_json.map { |x| x[:type] }.uniq).to_not include 'mention'
expect(body_as_json.pluck(:type).uniq).to_not include 'mention'
end
end
@@ -139,7 +141,7 @@ RSpec.describe Api::V1::NotificationsController, type: :controller do
end
it 'returns only requested type' do
expect(body_as_json.map { |x| x[:type] }.uniq).to eq ['mention']
expect(body_as_json.pluck(:type).uniq).to eq ['mention']
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Polls::VotesController, type: :controller do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::PollsController, type: :controller do

View File

@@ -5,13 +5,7 @@ require 'rails_helper'
describe Api::V1::Push::SubscriptionsController do
render_views
let(:user) { Fabricate(:user) }
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'push') }
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
let(:user) { Fabricate(:user) }
let(:create_payload) do
{
subscription: {
@@ -23,7 +17,6 @@ describe Api::V1::Push::SubscriptionsController do
},
}.with_indifferent_access
end
let(:alerts_payload) do
{
data: {
@@ -41,6 +34,11 @@ describe Api::V1::Push::SubscriptionsController do
},
}.with_indifferent_access
end
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: 'push') }
before do
allow(controller).to receive(:doorkeeper_token) { token }
end
describe 'POST #create' do
before do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Statuses::FavouritedByAccountsController, type: :controller do
@@ -45,7 +47,7 @@ RSpec.describe Api::V1::Statuses::FavouritedByAccountsController, type: :control
context 'without an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { nil }
allow(controller).to receive(:doorkeeper_token).and_return(nil)
end
context 'with a private status' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Statuses::RebloggedByAccountsController, type: :controller do
@@ -45,7 +47,7 @@ RSpec.describe Api::V1::Statuses::RebloggedByAccountsController, type: :controll
context 'without an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { nil }
allow(controller).to receive(:doorkeeper_token).and_return(nil)
end
context 'with a private status' do

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::StatusesController, type: :controller do
@@ -219,7 +221,7 @@ RSpec.describe Api::V1::StatusesController, type: :controller do
context 'without an oauth token' do
before do
allow(controller).to receive(:doorkeeper_token) { nil }
allow(controller).to receive(:doorkeeper_token).and_return(nil)
end
context 'with a private status' do

View File

@@ -25,7 +25,7 @@ describe Api::V1::StreamingController do
context 'with streaming api on different host' do
before(:each) do
Rails.configuration.x.streaming_api_base_url = 'wss://streaming-' + Rails.configuration.x.web_domain
Rails.configuration.x.streaming_api_base_url = "wss://streaming-#{Rails.configuration.x.web_domain}"
@streaming_host = URI.parse(Rails.configuration.x.streaming_api_base_url).host
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::SuggestionsController, type: :controller do
@@ -29,7 +31,7 @@ RSpec.describe Api::V1::SuggestionsController, type: :controller do
json = body_as_json
expect(json.size).to be >= 1
expect(json.map { |i| i[:id] }).to include(*[bob, jeff].map { |i| i.id.to_s })
expect(json.pluck(:id)).to include(*[bob, jeff].map { |i| i.id.to_s })
end
end
end

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::TagsController, type: :controller do

View File

@@ -36,7 +36,7 @@ describe Api::V1::Timelines::HomeController do
it 'returns http unprocessable entity' do
get :show
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(422)
expect(response.headers['Link']).to be_nil
end
end

View File

@@ -36,7 +36,7 @@ describe Api::V1::Timelines::ListController do
describe 'GET #show' do
it 'returns http not found' do
get :show, params: { id: list.id }
expect(response).to have_http_status(:not_found)
expect(response).to have_http_status(404)
end
end
end
@@ -48,7 +48,7 @@ describe Api::V1::Timelines::ListController do
it 'returns http unprocessable entity' do
get :show, params: { id: list.id }
expect(response).to have_http_status(:unprocessable_entity)
expect(response).to have_http_status(422)
expect(response.headers['Link']).to be_nil
end
end