Merge remote-tracking branch 'parent/main' into upstream-20240319

This commit is contained in:
KMY 2024-03-19 09:15:20 +09:00
commit 76598bd542
496 changed files with 5795 additions and 3709 deletions

View file

@ -901,7 +901,7 @@ RSpec.describe Account do
end
describe 'MENTION_RE' do
subject { Account::MENTION_RE }
subject { described_class::MENTION_RE }
it 'matches usernames in the middle of a sentence' do
expect(subject.match('Hello to @alice from me')[1]).to eq 'alice'
@ -1111,7 +1111,7 @@ RSpec.describe Account do
{ username: 'b', domain: 'b' },
].map(&method(:Fabricate).curry(2).call(:account))
expect(described_class.where('id > 0').alphabetic).to eq matches
expect(described_class.without_internal.alphabetic).to eq matches
end
end
@ -1162,7 +1162,7 @@ RSpec.describe Account do
it 'returns an array of accounts who do not have a domain' do
local_account = Fabricate(:account, domain: nil)
_account_with_domain = Fabricate(:account, domain: 'example.com')
expect(described_class.where('id > 0').local).to contain_exactly(local_account)
expect(described_class.without_internal.local).to contain_exactly(local_account)
end
end
@ -1173,14 +1173,14 @@ RSpec.describe Account do
matches[index] = Fabricate(:account, domain: matches[index])
end
expect(described_class.where('id > 0').partitioned).to match_array(matches)
expect(described_class.without_internal.partitioned).to match_array(matches)
end
end
describe 'recent' do
it 'returns a relation of accounts sorted by recent creation' do
matches = Array.new(2) { Fabricate(:account) }
expect(described_class.where('id > 0').recent).to match_array(matches)
expect(described_class.without_internal.recent).to match_array(matches)
end
end

View file

@ -1,6 +1,100 @@
# frozen_string_literal: true
# Reverted this commit.temporarily because load issues.
# Whenever a manual merge occurs, be sure to check the following commits.
# Hash: ee8d0b94473df357677cd1f82581251ce0423c01
# Message: Fix follow suggestions potentially including silenced or blocked accounts (#29306)
require 'rails_helper'
RSpec.describe AccountSuggestions::FriendsOfFriendsSource do
describe '#get' do
subject { described_class.new }
let!(:bob) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:alice) { Fabricate(:account, discoverable: true, hide_collections: true) }
let!(:eve) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:mallory) { Fabricate(:account, discoverable: false, hide_collections: false) }
let!(:eugen) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:neil) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:john) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:jerk) { Fabricate(:account, discoverable: true, hide_collections: false) }
let!(:larry) { Fabricate(:account, discoverable: true, hide_collections: false) }
context 'with follows and blocks' do
before do
bob.block!(jerk)
FollowRecommendationMute.create!(account: bob, target_account: neil)
# bob follows eugen, alice and larry
[eugen, alice, larry].each { |account| bob.follow!(account) }
# alice follows eve and mallory
[john, mallory].each { |account| alice.follow!(account) }
# eugen follows eve, john, jerk, larry and neil
[eve, mallory, jerk, larry, neil].each { |account| eugen.follow!(account) }
end
it 'returns eligible accounts', :aggregate_failures do
results = subject.get(bob)
# eve is returned through eugen
expect(results).to include([eve.id, :friends_of_friends])
# john is not reachable because alice hides who she follows
expect(results).to_not include([john.id, :friends_of_friends])
# mallory is not discoverable
expect(results).to_not include([mallory.id, :friends_of_friends])
# larry is not included because he's followed already
expect(results).to_not include([larry.id, :friends_of_friends])
# jerk is blocked
expect(results).to_not include([jerk.id, :friends_of_friends])
# the suggestion for neil has already been rejected
expect(results).to_not include([neil.id, :friends_of_friends])
end
end
context 'with deterministic order' do
before do
# bob follows eve and mallory
[eve, mallory].each { |account| bob.follow!(account) }
# eve follows eugen, john, and jerk
[jerk, eugen, john].each { |account| eve.follow!(account) }
# mallory follows eugen, john, and neil
[neil, eugen, john].each { |account| mallory.follow!(account) }
john.follow!(eugen)
john.follow!(neil)
end
it 'returns eligible accounts in the expected order' do
expect(subject.get(bob)).to eq expected_results
end
it 'contains correct underlying source data' do
expect(source_query_values)
.to contain_exactly(
[john.id, 2, 2], # Followed by 2 friends of bob (eve, mallory), 2 followers total (breaks tie)
[eugen.id, 2, 3], # Followed by 2 friends of bob (eve, mallory), 3 followers total
[jerk.id, 1, 1], # Followed by 1 friends of bob (eve), 1 followers total (breaks tie)
[neil.id, 1, 2] # Followed by 1 friends of bob (mallory), 2 followers total
)
end
def expected_results
[
[john.id, :friends_of_friends],
[eugen.id, :friends_of_friends],
[jerk.id, :friends_of_friends],
[neil.id, :friends_of_friends],
]
end
def source_query_values
subject.source_query(bob).to_a
end
end
end
end

View file

@ -32,4 +32,12 @@ RSpec.describe CustomFilter do
expect(record).to model_have_error_on_field(:context)
end
end
describe 'Normalizations' do
it 'cleans up context values' do
record = described_class.new(context: ['home', 'notifications', 'public ', ''])
expect(record.context).to eq(%w(home notifications public))
end
end
end

View file

@ -30,7 +30,7 @@ RSpec.describe Form::Import do
it 'has errors' do
subject.validate
expect(subject.errors[:data]).to include(I18n.t('imports.errors.over_rows_processing_limit', count: Form::Import::ROWS_PROCESSING_LIMIT))
expect(subject.errors[:data]).to include(I18n.t('imports.errors.over_rows_processing_limit', count: described_class::ROWS_PROCESSING_LIMIT))
end
end

View file

@ -8,7 +8,7 @@ describe PrivacyPolicy do
it 'has the privacy text' do
policy = described_class.current
expect(policy.text).to eq(PrivacyPolicy::DEFAULT_PRIVACY_POLICY)
expect(policy.text).to eq(described_class::DEFAULT_PRIVACY_POLICY)
end
end

View file

@ -22,7 +22,7 @@ RSpec.describe Tag do
end
describe 'HASHTAG_RE' do
subject { Tag::HASHTAG_RE }
subject { described_class::HASHTAG_RE }
it 'does not match URLs with anchors with non-hashtag characters' do
expect(subject.match('Check this out https://medium.com/@alice/some-article#.abcdef123')).to be_nil

View file

@ -8,7 +8,7 @@ RSpec.describe UserRole do
describe '#can?' do
context 'with a single flag' do
it 'returns true if any of them are present' do
subject.permissions = UserRole::FLAGS[:manage_reports]
subject.permissions = described_class::FLAGS[:manage_reports]
expect(subject.can?(:manage_reports)).to be true
end
@ -19,7 +19,7 @@ RSpec.describe UserRole do
context 'with multiple flags' do
it 'returns true if any of them are present' do
subject.permissions = UserRole::FLAGS[:manage_users]
subject.permissions = described_class::FLAGS[:manage_users]
expect(subject.can?(:manage_reports, :manage_users)).to be true
end
@ -51,7 +51,7 @@ RSpec.describe UserRole do
describe '#permissions_as_keys' do
before do
subject.permissions = UserRole::FLAGS[:invite_users] | UserRole::FLAGS[:view_dashboard] | UserRole::FLAGS[:manage_reports]
subject.permissions = described_class::FLAGS[:invite_users] | described_class::FLAGS[:view_dashboard] | described_class::FLAGS[:manage_reports]
end
it 'returns an array' do
@ -70,7 +70,7 @@ RSpec.describe UserRole do
let(:input) { %w(manage_users) }
it 'sets permission flags' do
expect(subject.permissions).to eq UserRole::FLAGS[:manage_users]
expect(subject.permissions).to eq described_class::FLAGS[:manage_users]
end
end
@ -78,7 +78,7 @@ RSpec.describe UserRole do
let(:input) { %w(manage_users manage_reports) }
it 'sets permission flags' do
expect(subject.permissions).to eq UserRole::FLAGS[:manage_users] | UserRole::FLAGS[:manage_reports]
expect(subject.permissions).to eq described_class::FLAGS[:manage_users] | described_class::FLAGS[:manage_reports]
end
end
@ -86,7 +86,7 @@ RSpec.describe UserRole do
let(:input) { %w(foo) }
it 'does not set permission flags' do
expect(subject.permissions).to eq UserRole::Flags::NONE
expect(subject.permissions).to eq described_class::Flags::NONE
end
end
end
@ -96,7 +96,7 @@ RSpec.describe UserRole do
subject { described_class.nobody }
it 'returns none' do
expect(subject.computed_permissions).to eq UserRole::Flags::NONE
expect(subject.computed_permissions).to eq described_class::Flags::NONE
end
end
@ -110,11 +110,11 @@ RSpec.describe UserRole do
context 'when role has the administrator flag' do
before do
subject.permissions = UserRole::FLAGS[:administrator]
subject.permissions = described_class::FLAGS[:administrator]
end
it 'returns all permissions' do
expect(subject.computed_permissions).to eq UserRole::Flags::ALL
expect(subject.computed_permissions).to eq described_class::Flags::ALL
end
end
@ -159,7 +159,7 @@ RSpec.describe UserRole do
end
it 'has no permissions' do
expect(subject.permissions).to eq UserRole::Flags::NONE
expect(subject.permissions).to eq described_class::Flags::NONE
end
it 'has negative position' do

View file

@ -24,7 +24,7 @@ RSpec.describe UserSettings do
context 'when setting was not defined' do
it 'raises error' do
expect { subject[:foo] }.to raise_error UserSettings::KeyError
expect { subject[:foo] }.to raise_error described_class::KeyError
end
end
end
@ -93,7 +93,7 @@ RSpec.describe UserSettings do
describe '.definition_for' do
context 'when key is defined' do
it 'returns a setting' do
expect(described_class.definition_for(:always_send_emails)).to be_a UserSettings::Setting
expect(described_class.definition_for(:always_send_emails)).to be_a described_class::Setting
end
end