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
+25 -4
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Rack::Attack do
@@ -8,6 +10,17 @@ describe Rack::Attack do
end
shared_examples 'throttled endpoint' do
before do
# Rack::Attack periods are not rolling, so avoid flaky tests by setting the time in a way
# to avoid crossing period boundaries.
# The code Rack::Attack uses to set periods is the following:
# https://github.com/rack/rack-attack/blob/v6.6.1/lib/rack/attack/cache.rb#L64-L66
# So we want to minimize `Time.now.to_i % period`
travel_to Time.zone.at((Time.now.to_i / period.seconds).to_i * period.seconds)
end
context 'when the number of requests is lower than the limit' do
it 'does not change the request status' do
limit.times do
@@ -18,11 +31,16 @@ describe Rack::Attack do
end
context 'when the number of requests is higher than the limit' do
it 'returns http too many requests' do
it 'returns http too many requests after limit and returns to normal status after period' do
(limit * 2).times do |i|
request.call
expect(last_response.status).to eq(429) if i > limit
end
travel period
request.call
expect(last_response.status).to_not eq(429)
end
end
end
@@ -31,7 +49,8 @@ describe Rack::Attack do
describe 'throttle excessive sign-up requests by IP address' do
context 'through the website' do
let(:limit) { 25 }
let(:limit) { 25 }
let(:period) { 5.minutes }
let(:request) { -> { post path, {}, 'REMOTE_ADDR' => remote_ip } }
context 'for exact path' do
@@ -48,7 +67,8 @@ describe Rack::Attack do
end
context 'through the API' do
let(:limit) { 5 }
let(:limit) { 5 }
let(:period) { 30.minutes }
let(:request) { -> { post path, {}, 'REMOTE_ADDR' => remote_ip } }
context 'for exact path' do
@@ -69,7 +89,8 @@ describe Rack::Attack do
end
describe 'throttle excessive sign-in requests by IP address' do
let(:limit) { 25 }
let(:limit) { 25 }
let(:period) { 5.minutes }
let(:request) { -> { post path, {}, 'REMOTE_ADDR' => remote_ip } }
context 'for exact path' do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AboutController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AccountsController, type: :controller do
@@ -35,10 +35,11 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
describe 'GET #show' do
context 'when id is "featured"' do
context 'without signature' do
let(:remote_account) { nil }
subject(:body) { body_as_json }
subject(:response) { get :show, params: { id: 'featured', account_username: account.username } }
subject(:body) { body_as_json }
let(:remote_account) { nil }
it 'returns http success' do
expect(response).to have_http_status(200)
@@ -60,7 +61,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
end
it 'does not include contents of private pinned status' do
expect(response.body).not_to include(private_pinned.text)
expect(response.body).to_not include(private_pinned.text)
end
context 'when account is permanently suspended' do
@@ -115,7 +116,7 @@ RSpec.describe ActivityPub::CollectionsController, type: :controller do
end
it 'does not include contents of private pinned status' do
expect(response.body).not_to include(private_pinned.text)
expect(response.body).to_not include(private_pinned.text)
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::FollowersSynchronizationsController, type: :controller do
@@ -32,10 +34,11 @@ RSpec.describe ActivityPub::FollowersSynchronizationsController, type: :controll
end
context 'with signature from example.com' do
let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
subject(:body) { body_as_json }
subject(:response) { get :show, params: { account_username: account.username } }
subject(:body) { body_as_json }
let(:remote_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/instance') }
it 'returns http success' do
expect(response).to have_http_status(200)
@@ -22,10 +22,10 @@ RSpec.describe ActivityPub::InboxesController, type: :controller do
end
context 'for a specific account' do
let(:account) { Fabricate(:account) }
subject(:response) { post :create, params: { account_username: account.username }, body: '{}' }
let(:account) { Fabricate(:account) }
context 'when account is permanently suspended' do
before do
account.suspend!
@@ -68,7 +68,7 @@ RSpec.describe ActivityPub::InboxesController, type: :controller do
let(:synchronization_collection) { 'https://example.com/followers2' }
it 'does not start a synchronization job' do
expect(ActivityPub::FollowersSynchronizationWorker).not_to have_received(:perform_async)
expect(ActivityPub::FollowersSynchronizationWorker).to_not have_received(:perform_async)
end
end
@@ -76,13 +76,13 @@ RSpec.describe ActivityPub::InboxesController, type: :controller do
let(:synchronization_url) { 'https://example.org/followers' }
it 'does not start a synchronization job' do
expect(ActivityPub::FollowersSynchronizationWorker).not_to have_received(:perform_async)
expect(ActivityPub::FollowersSynchronizationWorker).to_not have_received(:perform_async)
end
end
context 'with matching digest' do
it 'does not start a synchronization job' do
expect(ActivityPub::FollowersSynchronizationWorker).not_to have_received(:perform_async)
expect(ActivityPub::FollowersSynchronizationWorker).to_not have_received(:perform_async)
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::OutboxesController, type: :controller do
@@ -33,10 +35,11 @@ RSpec.describe ActivityPub::OutboxesController, type: :controller do
describe 'GET #show' do
context 'without signature' do
let(:remote_account) { nil }
subject(:body) { body_as_json }
subject(:response) { get :show, params: { account_username: account.username, page: page } }
subject(:body) { body_as_json }
let(:remote_account) { nil }
context 'with page not requested' do
let(:page) { nil }
@@ -181,6 +181,7 @@ RSpec.describe ActivityPub::RepliesController, type: :controller do
describe 'GET #index' do
subject(:response) { get :index, params: { account_username: status.account.username, status_id: status.id, only_other_accounts: only_other_accounts } }
let(:only_other_accounts) { nil }
context 'with no signature' do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::AccountModerationNotesController, type: :controller do
@@ -26,7 +28,7 @@ RSpec.describe Admin::AccountModerationNotesController, type: :controller do
let(:params) { { account_moderation_note: { target_account_id: target_account.id, content: '' } } }
it 'falls to create a note' do
expect { subject }.not_to change { AccountModerationNote.count }
expect { subject }.to_not change { AccountModerationNote.count }
expect(subject).to render_template 'admin/accounts/show'
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::AccountsController, type: :controller do
@@ -83,8 +85,8 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:target_role) { UserRole.find_by(name: 'Admin') }
it 'fails to memorialize account' do
is_expected.to have_http_status :forbidden
expect(account.reload).not_to be_memorial
expect(subject).to have_http_status 403
expect(account.reload).to_not be_memorial
end
end
@@ -92,7 +94,7 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:target_role) { UserRole.find_by(name: 'Moderator') }
it 'succeeds in memorializing account' do
is_expected.to redirect_to admin_account_path(account.id)
expect(subject).to redirect_to admin_account_path(account.id)
expect(account.reload).to be_memorial
end
end
@@ -105,8 +107,8 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:target_role) { UserRole.find_by(name: 'Admin') }
it 'fails to memorialize account' do
is_expected.to have_http_status :forbidden
expect(account.reload).not_to be_memorial
expect(subject).to have_http_status 403
expect(account.reload).to_not be_memorial
end
end
@@ -114,8 +116,8 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:target_role) { UserRole.find_by(name: 'Moderator') }
it 'fails to memorialize account' do
is_expected.to have_http_status :forbidden
expect(account.reload).not_to be_memorial
expect(subject).to have_http_status 403
expect(account.reload).to_not be_memorial
end
end
end
@@ -132,8 +134,8 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'succeeds in enabling account' do
is_expected.to redirect_to admin_account_path(account.id)
expect(user.reload).not_to be_disabled
expect(subject).to redirect_to admin_account_path(account.id)
expect(user.reload).to_not be_disabled
end
end
@@ -141,7 +143,7 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.everyone }
it 'fails to enable account' do
is_expected.to have_http_status :forbidden
expect(subject).to have_http_status 403
expect(user.reload).to be_disabled
end
end
@@ -162,12 +164,12 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'succeeds in approving account' do
is_expected.to redirect_to admin_accounts_path(status: 'pending')
expect(subject).to redirect_to admin_accounts_path(status: 'pending')
expect(user.reload).to be_approved
end
it 'logs action' do
is_expected.to have_http_status :found
expect(subject).to have_http_status 302
log_item = Admin::ActionLog.last
@@ -182,8 +184,8 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.everyone }
it 'fails to approve account' do
is_expected.to have_http_status :forbidden
expect(user.reload).not_to be_approved
expect(subject).to have_http_status 403
expect(user.reload).to_not be_approved
end
end
end
@@ -203,11 +205,11 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'succeeds in rejecting account' do
is_expected.to redirect_to admin_accounts_path(status: 'pending')
expect(subject).to redirect_to admin_accounts_path(status: 'pending')
end
it 'logs action' do
is_expected.to have_http_status :found
expect(subject).to have_http_status 302
log_item = Admin::ActionLog.last
@@ -222,8 +224,8 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.everyone }
it 'fails to reject account' do
is_expected.to have_http_status :forbidden
expect(user.reload).not_to be_approved
expect(subject).to have_http_status 403
expect(user.reload).to_not be_approved
end
end
end
@@ -242,7 +244,7 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'succeeds in redownloading' do
is_expected.to redirect_to admin_account_path(account.id)
expect(subject).to redirect_to admin_account_path(account.id)
end
end
@@ -250,7 +252,7 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.everyone }
it 'fails to redownload' do
is_expected.to have_http_status :forbidden
expect(subject).to have_http_status 403
end
end
end
@@ -265,7 +267,7 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'succeeds in removing avatar' do
is_expected.to redirect_to admin_account_path(account.id)
expect(subject).to redirect_to admin_account_path(account.id)
end
end
@@ -273,7 +275,7 @@ RSpec.describe Admin::AccountsController, type: :controller do
let(:role) { UserRole.everyone }
it 'fails to remove avatar' do
is_expected.to have_http_status :forbidden
expect(subject).to have_http_status 403
end
end
end
@@ -303,7 +305,7 @@ RSpec.describe Admin::AccountsController, type: :controller do
it 'fails to remove avatar' do
subject
expect(response).to have_http_status :forbidden
expect(response).to have_http_status 403
end
end
end
@@ -15,7 +15,7 @@ describe Admin::BaseController, type: :controller do
sign_in(Fabricate(:user))
get :success
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
it 'renders admin layout as a moderator' do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::ChangeEmailsController, type: :controller do
@@ -35,7 +37,7 @@ RSpec.describe Admin::ChangeEmailsController, type: :controller do
expect(user.email).to eq previous_email
expect(user.unconfirmed_email).to eq 'test@example.com'
expect(user.confirmation_token).not_to be_nil
expect(user.confirmation_token).to_not be_nil
expect(UserMailer).to have_received(:confirmation_instructions).with(user, user.confirmation_token, { to: 'test@example.com' })
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::ConfirmationsController, type: :controller do
@@ -55,7 +57,7 @@ RSpec.describe Admin::ConfirmationsController, type: :controller do
it 'does not resend confirmation mail' do
expect(subject).to redirect_to admin_accounts_path
expect(flash[:error]).to eq I18n.t('admin.accounts.resend_confirmation.already_confirmed')
expect(UserMailer).not_to have_received(:confirmation_instructions)
expect(UserMailer).to_not have_received(:confirmation_instructions)
end
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::CustomEmojisController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::Disputes::AppealsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::DomainAllowsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::DomainBlocksController, type: :controller do
@@ -54,7 +56,7 @@ RSpec.describe Admin::DomainBlocksController, type: :controller do
post :create, params: { domain_block: { domain: 'example.com', severity: 'silence' } }
expect(DomainBlockWorker).not_to have_received(:perform_async)
expect(DomainBlockWorker).to_not have_received(:perform_async)
expect(response).to render_template :new
end
@@ -72,16 +74,15 @@ RSpec.describe 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_block: { 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_block: { domain: 'example.com', severity: new_severity } }
end
context 'downgrading a domain suspension to silence' do
let(:original_severity) { 'suspend' }
let(:new_severity) { 'silence' }
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::ExportDomainAllowsController, type: :controller do
@@ -14,7 +16,7 @@ RSpec.describe Admin::ExportDomainAllowsController, type: :controller do
get :export, params: { format: :csv }
expect(response).to have_http_status(200)
expect(response.body).to eq(IO.read(File.join(file_fixture_path, 'domain_allows.csv')))
expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_allows.csv')))
end
end
@@ -25,12 +27,12 @@ RSpec.describe Admin::ExportDomainAllowsController, type: :controller do
expect(response).to redirect_to(admin_instances_path)
# Header should not be imported
expect(DomainAllow.where(domain: '#domain').present?).to eq(false)
expect(DomainAllow.where(domain: '#domain').present?).to be(false)
# Domains should now be added
get :export, params: { format: :csv }
expect(response).to have_http_status(200)
expect(response.body).to eq(IO.read(File.join(file_fixture_path, 'domain_allows.csv')))
expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_allows.csv')))
end
it 'displays error on no file selected' do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::ExportDomainBlocksController, type: :controller do
@@ -16,7 +18,7 @@ RSpec.describe Admin::ExportDomainBlocksController, type: :controller do
get :export, params: { format: :csv }
expect(response).to have_http_status(200)
expect(response.body).to eq(IO.read(File.join(file_fixture_path, 'domain_blocks.csv')))
expect(response.body).to eq(File.read(File.join(file_fixture_path, 'domain_blocks.csv')))
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Admin::InstancesController, type: :controller do
@@ -42,7 +44,7 @@ RSpec.describe Admin::InstancesController, type: :controller do
let(:role) { UserRole.find_by(name: 'Admin') }
it 'succeeds in purging instance' do
is_expected.to redirect_to admin_instances_path
expect(subject).to redirect_to admin_instances_path
end
end
@@ -50,7 +52,7 @@ RSpec.describe Admin::InstancesController, type: :controller do
let(:role) { nil }
it 'fails to purge instance' do
is_expected.to have_http_status :forbidden
expect(subject).to have_http_status 403
end
end
end
@@ -33,10 +33,10 @@ describe Admin::InvitesController do
end
describe 'DELETE #destroy' do
let!(:invite) { Fabricate(:invite, expires_at: nil) }
subject { delete :destroy, params: { id: invite.id } }
let!(:invite) { Fabricate(:invite, expires_at: nil) }
it 'expires invite' do
expect(subject).to redirect_to admin_invites_path
expect(invite.reload).to be_expired
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::ReportNotesController do
@@ -34,7 +36,7 @@ describe Admin::ReportNotesController do
it 'creates a report note and does not resolve report' do
expect { subject }.to change { ReportNote.count }.by(1)
expect(report.reload).not_to be_action_taken
expect(report.reload).to_not be_action_taken
expect(subject).to redirect_to admin_report_path(report)
end
end
@@ -49,7 +51,7 @@ describe Admin::ReportNotesController do
it 'creates a report note and unresolves report' do
expect { subject }.to change { ReportNote.count }.by(1)
expect(report.reload).not_to be_action_taken
expect(report.reload).to_not be_action_taken
expect(subject).to redirect_to admin_report_path(report)
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::Reports::ActionsController do
@@ -116,18 +118,20 @@ describe Admin::Reports::ActionsController do
it 'marks the non-deleted as sensitive' do
subject
expect(media_attached_status.reload.sensitive).to eq true
expect(media_attached_status.reload.sensitive).to be true
end
end
end
context 'action as submit button' do
subject { post :create, params: { report_id: report.id, text: text, action => '' } }
it_behaves_like 'all action types'
end
context 'action as submit button' do
subject { post :create, params: { report_id: report.id, text: text, moderation_action: action } }
it_behaves_like 'all action types'
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::ReportsController do
@@ -55,7 +57,7 @@ describe Admin::ReportsController do
expect(response).to redirect_to(admin_reports_path)
report.reload
expect(report.action_taken_by_account).to eq user.account
expect(report.action_taken?).to eq true
expect(report.action_taken?).to be true
end
end
@@ -66,8 +68,8 @@ describe Admin::ReportsController do
put :reopen, params: { id: report }
expect(response).to redirect_to(admin_report_path(report))
report.reload
expect(report.action_taken_by_account).to eq nil
expect(report.action_taken?).to eq false
expect(report.action_taken_by_account).to be_nil
expect(report.action_taken?).to be false
end
end
@@ -89,7 +91,7 @@ describe Admin::ReportsController do
put :unassign, params: { id: report }
expect(response).to redirect_to(admin_report_path(report))
report.reload
expect(report.assigned_account).to eq nil
expect(report.assigned_account).to be_nil
end
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::ResetsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::RolesController do
@@ -18,7 +20,7 @@ describe Admin::RolesController do
context 'when user does not have permission to manage roles' do
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
@@ -38,7 +40,7 @@ describe Admin::RolesController do
context 'when user does not have permission to manage roles' do
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
@@ -128,7 +130,7 @@ describe Admin::RolesController do
context 'when user does not have permission to manage roles' do
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
@@ -145,7 +147,7 @@ describe Admin::RolesController do
let(:role_position) { current_role.position + 1 }
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
end
@@ -165,7 +167,7 @@ describe Admin::RolesController do
context 'when user does not have permission to manage roles' do
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
it 'does not update the role' do
@@ -203,7 +205,7 @@ describe Admin::RolesController do
let(:role_position) { current_role.position + 1 }
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
it 'does not update the role' do
@@ -224,7 +226,7 @@ describe Admin::RolesController do
context 'when user does not have permission to manage roles' do
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
@@ -241,7 +243,7 @@ describe Admin::RolesController do
let(:role_position) { current_role.position + 1 }
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::StatusesController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Admin::Users::RolesController do
@@ -26,7 +28,7 @@ describe Admin::Users::RolesController do
let(:previous_role) { UserRole.create(name: 'Baz', permissions: UserRole::FLAGS[:administrator], position: 100) }
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
end
@@ -74,7 +76,7 @@ describe Admin::Users::RolesController do
end
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
require 'webauthn/fake_client'
@@ -20,7 +22,7 @@ describe Admin::Users::TwoFactorAuthenticationsController do
delete :destroy, params: { user_id: user.id }
user.reload
expect(user.otp_enabled?).to eq false
expect(user.otp_enabled?).to be false
expect(response).to redirect_to(admin_account_path(user.account_id))
end
end
@@ -43,8 +45,8 @@ describe Admin::Users::TwoFactorAuthenticationsController do
delete :destroy, params: { user_id: user.id }
user.reload
expect(user.otp_enabled?).to eq false
expect(user.webauthn_enabled?).to eq false
expect(user.otp_enabled?).to be false
expect(user.webauthn_enabled?).to be false
expect(response).to redirect_to(admin_account_path(user.account_id))
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::OEmbedController, type: :controller do
@@ -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
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::FollowerAccountsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::FollowingAccountsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::ListsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::NotesController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Accounts::RelationshipsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Accounts::SearchController, type: :controller do
@@ -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
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::AccountsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::AccountActionsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::AccountsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::DomainAllowsController, type: :controller do
@@ -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' }
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Admin::ReportsController, type: :controller do
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::ConversationsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::DomainBlocksController, type: :controller do
@@ -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
@@ -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
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FiltersController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FollowRequestsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::FollowedTagsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Api::V1::Lists::AccountsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::ListsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::MarkersController, type: :controller do
@@ -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
@@ -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
@@ -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
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::Polls::VotesController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::PollsController, type: :controller do
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V1::TagsController, type: :controller do
@@ -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
@@ -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
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V2::Admin::AccountsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V2::Filters::KeywordsController, type: :controller do
@@ -45,7 +47,7 @@ RSpec.describe Api::V2::Filters::KeywordsController, type: :controller do
it 'returns a keyword' do
json = body_as_json
expect(json[:keyword]).to eq 'magic'
expect(json[:whole_word]).to eq false
expect(json[:whole_word]).to be false
end
it 'creates a keyword' do
@@ -78,7 +80,7 @@ RSpec.describe Api::V2::Filters::KeywordsController, type: :controller do
it 'returns expected data' do
json = body_as_json
expect(json[:keyword]).to eq 'foo'
expect(json[:whole_word]).to eq false
expect(json[:whole_word]).to be false
end
context "when trying to access another user's filter keyword" do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V2::Filters::StatusesController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Api::V2::FiltersController, type: :controller do
@@ -11,6 +11,7 @@ describe Api::Web::EmbedsController do
describe 'POST #create' do
subject(:response) { post :create, params: { url: url } }
subject(:body) { JSON.parse(response.body, symbolize_names: true) }
context 'when successfully finds status' do
@@ -18,7 +19,7 @@ describe Api::Web::EmbedsController do
let(:url) { "http://#{Rails.configuration.x.web_domain}/@#{status.account.username}/#{status.id}" }
it 'returns a right response' do
expect(response).to have_http_status :ok
expect(response).to have_http_status 200
expect(body[:author_name]).to eq status.account.username
end
end
@@ -36,7 +37,7 @@ describe Api::Web::EmbedsController do
let(:call_result) { { result: :ok } }
it 'returns a right response' do
expect(response).to have_http_status :ok
expect(response).to have_http_status 200
expect(body[:result]).to eq 'ok'
end
end
@@ -45,7 +46,7 @@ describe Api::Web::EmbedsController do
let(:call_result) { nil }
it 'returns a right response' do
expect(response).to have_http_status :not_found
expect(response).to have_http_status 404
end
end
end
@@ -28,7 +28,7 @@ describe ApplicationController, type: :controller do
end
it 'renders template for http' do
is_expected.to render_template("errors/#{code}", layout: 'error')
expect(subject).to render_template("errors/#{code}", layout: 'error')
end
end
@@ -57,19 +57,19 @@ describe ApplicationController, type: :controller do
describe 'helper_method :single_user_mode?' do
it 'returns false if it is in single_user_mode but there is no account' do
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
expect(controller.view_context.single_user_mode?).to eq false
expect(controller.view_context.single_user_mode?).to be false
end
it 'returns false if there is an account but it is not in single_user_mode' do
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(false)
Fabricate(:account)
expect(controller.view_context.single_user_mode?).to eq false
expect(controller.view_context.single_user_mode?).to be false
end
it 'returns true if it is in single_user_mode and there is an account' do
allow(Rails.configuration.x).to receive(:single_user_mode).and_return(true)
Fabricate(:account)
expect(controller.view_context.single_user_mode?).to eq true
expect(controller.view_context.single_user_mode?).to be true
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Auth::RegistrationsController, type: :controller do
@@ -95,18 +97,18 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
before { request.env['devise.mapping'] = Devise.mappings[:user] }
context do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'open'
request.headers['Accept-Language'] = accept_language
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@@ -121,18 +123,18 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end
context 'when user has not agreed to terms of service' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'open'
request.headers['Accept-Language'] = accept_language
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'false' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'does not create user' do
subject
user = User.find_by(email: 'test@example.com')
@@ -141,18 +143,18 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end
context 'approval-based registrations without invite' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'approved'
request.headers['Accept-Language'] = accept_language
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@@ -163,17 +165,11 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
user = User.find_by(email: 'test@example.com')
expect(user).to_not be_nil
expect(user.locale).to eq(accept_language)
expect(user.approved).to eq(false)
expect(user.approved).to be(false)
end
end
context 'approval-based registrations with expired invite' do
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
subject do
Setting.registrations_mode = 'approved'
request.headers['Accept-Language'] = accept_language
@@ -181,6 +177,12 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
example.run
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@@ -191,19 +193,11 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
user = User.find_by(email: 'test@example.com')
expect(user).to_not be_nil
expect(user.locale).to eq(accept_language)
expect(user.approved).to eq(false)
expect(user.approved).to be(false)
end
end
context 'approval-based registrations with valid invite and required invite text' do
around do |example|
registrations_mode = Setting.registrations_mode
require_invite_text = Setting.require_invite_text
example.run
Setting.require_invite_text = require_invite_text
Setting.registrations_mode = registrations_mode
end
subject do
inviter = Fabricate(:user, confirmed_at: 2.days.ago)
Setting.registrations_mode = 'approved'
@@ -213,6 +207,14 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
post :create, params: { user: { account_attributes: { username: 'test' }, email: 'test@example.com', password: '12345678', password_confirmation: '12345678', invite_code: invite.code, agreement: 'true' } }
end
around do |example|
registrations_mode = Setting.registrations_mode
require_invite_text = Setting.require_invite_text
example.run
Setting.require_invite_text = require_invite_text
Setting.registrations_mode = registrations_mode
end
it 'redirects to setup' do
subject
expect(response).to redirect_to auth_setup_path
@@ -223,7 +225,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
user = User.find_by(email: 'test@example.com')
expect(user).to_not be_nil
expect(user.locale).to eq(accept_language)
expect(user.approved).to eq(true)
expect(user.approved).to be(true)
end
end
@@ -245,7 +247,7 @@ RSpec.describe Auth::RegistrationsController, type: :controller do
end
it 'returns http not found' do
expect(response).to have_http_status(:not_found)
expect(response).to have_http_status(404)
end
it 'does not delete user' do
@@ -422,7 +422,7 @@ RSpec.describe Auth::SessionsController, type: :controller do
it 'returns http success' do
get :webauthn_options
expect(response).to have_http_status :ok
expect(response).to have_http_status 200
end
end
end
@@ -29,7 +29,7 @@ describe ApplicationController, type: :controller do
it 'returns unauthorized when not signed in' do
get :index, format: :csv
expect(response).to have_http_status(:unauthorized)
expect(response).to have_http_status(401)
end
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Disputes::AppealsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Disputes::StrikesController, type: :controller do
@@ -23,7 +25,7 @@ RSpec.describe Disputes::StrikesController, type: :controller do
let(:strike) { Fabricate(:account_warning) }
it 'returns http forbidden' do
expect(response).to have_http_status(:forbidden)
expect(response).to have_http_status(403)
end
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe EmojisController do
@@ -7,6 +9,7 @@ describe EmojisController do
describe 'GET #show' do
subject(:response) { get :show, params: { id: emoji.id, format: :json } }
subject(:body) { JSON.parse(response.body, symbolize_names: true) }
it 'returns the right response' do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe FollowerAccountsController do
@@ -38,6 +40,7 @@ describe FollowerAccountsController do
context 'when format is json' do
subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
subject(:body) { JSON.parse(response.body) }
context 'with page' do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe FollowingAccountsController do
@@ -38,6 +40,7 @@ describe FollowingAccountsController do
context 'when format is json' do
subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
subject(:body) { JSON.parse(response.body) }
context 'with page' do
+4 -2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe HomeController, type: :controller do
@@ -9,7 +11,7 @@ RSpec.describe HomeController, type: :controller do
context 'when not signed in' do
it 'returns http success' do
@request.path = '/'
is_expected.to have_http_status(:success)
expect(subject).to have_http_status(:success)
end
end
@@ -21,7 +23,7 @@ RSpec.describe HomeController, type: :controller do
end
it 'returns http success' do
is_expected.to have_http_status(:success)
expect(subject).to have_http_status(:success)
end
end
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe InstanceActorsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe IntentsController, type: :controller do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe InvitesController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe ManifestsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe RelationshipsController do
@@ -7,7 +9,7 @@ describe RelationshipsController do
shared_examples 'authenticate user' do
it 'redirects when not signed in' do
is_expected.to redirect_to '/auth/sign_in'
expect(subject).to redirect_to '/auth/sign_in'
end
end
@@ -51,6 +53,7 @@ describe RelationshipsController do
context 'when select parameter is not provided' do
subject { patch :update }
include_examples 'redirects back to followers page'
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Settings::ApplicationsController do
@@ -32,7 +34,7 @@ describe Settings::ApplicationsController do
app.update!(owner: nil)
get :show, params: { id: app.id }
expect(response.status).to eq 404
expect(response).to have_http_status 404
end
end
@@ -73,7 +75,7 @@ describe Settings::ApplicationsController do
name: 'My New App',
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
website: 'http://google.com',
scopes: ['read', 'write', 'follow'],
scopes: %w(read write follow),
},
}
response
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Settings::DeletesController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Settings::Exports::BlockedAccountsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Settings::Exports::BookmarksController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Settings::Exports::FollowingAccountsController do
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rails_helper'
describe Settings::Exports::MutedAccountsController do

Some files were not shown because too many files have changed in this diff Show More