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

- `app/views/statuses/_simple_status.html.haml`:
  Small markup change in glitch-soc, on a line that has been modified by
  upstream. Ported upstream changes.
This commit is contained in:
Claire
2021-05-07 18:21:59 +02:00
483 changed files with 13397 additions and 7694 deletions

View File

@ -3,9 +3,19 @@
require 'rails_helper'
describe Admin::DashboardController, type: :controller do
render_views
describe 'GET #index' do
it 'returns 200' do
before do
allow(Admin::SystemCheck).to receive(:perform).and_return([
Admin::SystemCheck::Message.new(:database_schema_check),
Admin::SystemCheck::Message.new(:rules_check, nil, admin_rules_path),
Admin::SystemCheck::Message.new(:sidekiq_process_check, 'foo, bar'),
])
sign_in Fabricate(:user, admin: true)
end
it 'returns 200' do
get :index
expect(response).to have_http_status(200)

View File

@ -32,6 +32,52 @@ describe Auth::ConfirmationsController, type: :controller do
end
end
context 'when user is unconfirmed and unapproved' do
let!(:user) { Fabricate(:user, confirmation_token: 'foobar', confirmed_at: nil, approved: false) }
before do
allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user]
get :show, params: { confirmation_token: 'foobar' }
end
it 'redirects to login' do
expect(response).to redirect_to(new_user_session_path)
end
end
context 'when user is already confirmed' do
let!(:user) { Fabricate(:user) }
before do
allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user]
sign_in(user, scope: :user)
get :show, params: { confirmation_token: 'foobar' }
end
it 'redirects to root path' do
expect(response).to redirect_to(root_path)
end
end
context 'when user is already confirmed but unapproved' do
let!(:user) { Fabricate(:user, approved: false) }
before do
allow(BootstrapTimelineWorker).to receive(:perform_async)
@request.env['devise.mapping'] = Devise.mappings[:user]
user.approved = false
user.save!
sign_in(user, scope: :user)
get :show, params: { confirmation_token: 'foobar' }
end
it 'redirects to settings' do
expect(response).to redirect_to(edit_user_registration_path)
end
end
context 'when user is updating email' do
let!(:user) { Fabricate(:user, confirmation_token: 'foobar', unconfirmed_email: 'new-email@example.com') }

View File

@ -13,7 +13,7 @@ RSpec.describe ActivityPub::Activity::Update do
end
let(:modified_sender) do
sender.dup.tap do |modified_sender|
sender.tap do |modified_sender|
modified_sender.display_name = 'Totally modified now'
end
end

View File

@ -10,12 +10,12 @@ RSpec.describe NotificationMailer, type: :mailer do
it 'renders subject localized for the locale of the receiver' do
locale = %i(de en).sample
receiver.update!(locale: locale)
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: locale))
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: locale))
end
it 'renders subject localized for the default locale if the locale of the receiver is unavailable' do
receiver.update!(locale: nil)
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: I18n.default_locale))
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: I18n.default_locale))
end
end
@ -59,12 +59,12 @@ RSpec.describe NotificationMailer, type: :mailer do
include_examples 'localized subject', 'notification_mailer.favourite.subject', name: 'bob'
it "renders the headers" do
expect(mail.subject).to eq("bob favourited your status")
expect(mail.subject).to eq("bob favourited your post")
expect(mail.to).to eq([receiver.email])
end
it "renders the body" do
expect(mail.body.encoded).to match("Your status was favourited by bob")
expect(mail.body.encoded).to match("Your post was favourited by bob")
expect(mail.body.encoded).to include 'The body of the own status'
end
end
@ -76,12 +76,12 @@ RSpec.describe NotificationMailer, type: :mailer do
include_examples 'localized subject', 'notification_mailer.reblog.subject', name: 'bob'
it "renders the headers" do
expect(mail.subject).to eq("bob boosted your status")
expect(mail.subject).to eq("bob boosted your post")
expect(mail.to).to eq([receiver.email])
end
it "renders the body" do
expect(mail.body.encoded).to match("Your status was boosted by bob")
expect(mail.body.encoded).to match("Your post was boosted by bob")
expect(mail.body.encoded).to include 'The body of the own status'
end
end

View File

@ -9,12 +9,12 @@ describe UserMailer, type: :mailer do
it 'renders subject localized for the locale of the receiver' do
locale = I18n.available_locales.sample
receiver.update!(locale: locale)
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: locale))
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: locale))
end
it 'renders subject localized for the default locale if the locale of the receiver is unavailable' do
receiver.update!(locale: nil)
expect(mail.subject).to eq I18n.t(*args, kwrest.merge(locale: I18n.default_locale))
expect(mail.subject).to eq I18n.t(*args, **kwrest.merge(locale: I18n.default_locale))
end
end

View File

@ -1,38 +0,0 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe AccountTagStat, type: :model do
key = 'accounts_count'
let(:account_tag_stat) { Fabricate(:tag).account_tag_stat }
describe '#increment_count!' do
it 'calls #update' do
args = { key => account_tag_stat.public_send(key) + 1 }
expect(account_tag_stat).to receive(:update).with(args)
account_tag_stat.increment_count!(key)
end
it 'increments value by 1' do
expect do
account_tag_stat.increment_count!(key)
end.to change { account_tag_stat.accounts_count }.by(1)
end
end
describe '#decrement_count!' do
it 'calls #update' do
args = { key => [account_tag_stat.public_send(key) - 1, 0].max }
expect(account_tag_stat).to receive(:update).with(args)
account_tag_stat.decrement_count!(key)
end
it 'decrements value by 1' do
account_tag_stat.update(key => 1)
expect do
account_tag_stat.decrement_count!(key)
end.to change { account_tag_stat.accounts_count }.by(-1)
end
end
end

View File

@ -7,7 +7,7 @@ RSpec.describe FollowRequest, type: :model do
let(:target_account) { Fabricate(:account) }
it 'calls Account#follow!, MergeWorker.perform_async, and #destroy!' do
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri)
expect(account).to receive(:follow!).with(target_account, reblogs: true, notify: false, uri: follow_request.uri, bypass_limit: true)
expect(MergeWorker).to receive(:perform_async).with(target_account.id, account.id)
expect(follow_request).to receive(:destroy!)
follow_request.authorize!

View File

@ -74,13 +74,13 @@ RSpec.describe SessionActivation, type: :model do
let(:options) { { user: Fabricate(:user), session_id: '1' } }
it 'calls create! and purge_old' do
expect(described_class).to receive(:create!).with(options)
expect(described_class).to receive(:create!).with(**options)
expect(described_class).to receive(:purge_old)
described_class.activate(options)
described_class.activate(**options)
end
it 'returns an instance of SessionActivation' do
expect(described_class.activate(options)).to be_kind_of SessionActivation
expect(described_class.activate(**options)).to be_kind_of SessionActivation
end
end

View File

@ -96,6 +96,20 @@ RSpec.describe Tag, type: :model do
end
end
describe '.matches_name' do
it 'returns tags for multibyte case-insensitive names' do
upcase_string = 'abcABCやゆよ'
downcase_string = 'abcabcやゆよ';
tag = Fabricate(:tag, name: downcase_string)
expect(Tag.matches_name(upcase_string)).to eq [tag]
end
it 'uses the LIKE operator' do
expect(Tag.matches_name('100%abc').to_sql).to eq %q[SELECT "tags".* FROM "tags" WHERE LOWER("tags"."name") LIKE LOWER('100\\%abc%')]
end
end
describe '.matching_name' do
it 'returns tags for multibyte case-insensitive names' do
upcase_string = 'abcABCやゆよ'

View File

@ -7,9 +7,9 @@ RSpec.describe TrendingTags do
describe '.update!' do
let!(:at_time) { Time.now.utc }
let!(:tag1) { Fabricate(:tag, name: 'Catstodon') }
let!(:tag2) { Fabricate(:tag, name: 'DogsOfMastodon') }
let!(:tag3) { Fabricate(:tag, name: 'OCs') }
let!(:tag1) { Fabricate(:tag, name: 'Catstodon', trendable: true) }
let!(:tag2) { Fabricate(:tag, name: 'DogsOfMastodon', trendable: true) }
let!(:tag3) { Fabricate(:tag, name: 'OCs', trendable: true) }
before do
allow(Redis.current).to receive(:pfcount) do |key|

View File

@ -13,7 +13,7 @@ RSpec.describe AccountRelationshipsPresenter do
allow(Account).to receive(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map)
end
let(:presenter) { AccountRelationshipsPresenter.new(account_ids, current_account_id, options) }
let(:presenter) { AccountRelationshipsPresenter.new(account_ids, current_account_id, **options) }
let(:current_account_id) { Fabricate(:account).id }
let(:account_ids) { [Fabricate(:account).id] }
let(:default_map) { { 1 => true } }

View File

@ -1,42 +1,4 @@
require 'rails_helper'
RSpec.describe BootstrapTimelineService, type: :service do
subject { described_class.new }
describe '#call' do
let(:source_account) { Fabricate(:account) }
context 'when setting is empty' do
let!(:admin) { Fabricate(:user, admin: true) }
before do
Setting.bootstrap_timeline_accounts = nil
subject.call(source_account)
end
it 'follows admin accounts from account' do
expect(source_account.following?(admin.account)).to be true
end
end
context 'when setting is set' do
let!(:alice) { Fabricate(:account, username: 'alice') }
let!(:bob) { Fabricate(:account, username: 'bob') }
let!(:eve) { Fabricate(:account, username: 'eve', suspended: true) }
before do
Setting.bootstrap_timeline_accounts = 'alice, @bob, eve, unknown'
subject.call(source_account)
end
it 'follows found accounts from account' do
expect(source_account.following?(alice)).to be true
expect(source_account.following?(bob)).to be true
end
it 'does not follow suspended account' do
expect(source_account.following?(eve)).to be false
end
end
end
end