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

This commit is contained in:
KMY 2023-12-21 08:37:12 +09:00
commit a6b57e3890
154 changed files with 7762 additions and 1748 deletions

View file

@ -5,19 +5,18 @@ require 'rails_helper'
RSpec.describe AccountRelationshipsPresenter do
describe '.initialize' do
before do
allow(Account).to receive(:following_map).with(account_ids, current_account_id).and_return(default_map)
allow(Account).to receive(:followed_by_map).with(account_ids, current_account_id).and_return(default_map)
allow(Account).to receive(:blocking_map).with(account_ids, current_account_id).and_return(default_map)
allow(Account).to receive(:muting_map).with(account_ids, current_account_id).and_return(default_map)
allow(Account).to receive(:requested_map).with(account_ids, current_account_id).and_return(default_map)
allow(Account).to receive(:requested_by_map).with(account_ids, current_account_id).and_return(default_map)
allow(Account).to receive(:domain_blocking_map).with(account_ids, current_account_id).and_return(default_map)
allow(Account).to receive(:following_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
allow(Account).to receive(:followed_by_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
allow(Account).to receive(:blocking_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
allow(Account).to receive(:muting_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
allow(Account).to receive(:requested_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
allow(Account).to receive(:requested_by_map).with(accounts.pluck(:id), current_account_id).and_return(default_map)
end
let(:presenter) { described_class.new(account_ids, current_account_id, **options) }
let(:presenter) { described_class.new(accounts, current_account_id, **options) }
let(:current_account_id) { Fabricate(:account).id }
let(:account_ids) { [Fabricate(:account).id] }
let(:default_map) { { 1 => true } }
let(:accounts) { [Fabricate(:account)] }
let(:default_map) { { accounts[0].id => true } }
context 'when options are not set' do
let(:options) { {} }
@ -29,7 +28,33 @@ RSpec.describe AccountRelationshipsPresenter do
blocking: default_map,
muting: default_map,
requested: default_map,
domain_blocking: default_map
domain_blocking: { accounts[0].id => nil }
)
end
end
context 'with a warm cache' do
let(:options) { {} }
before do
described_class.new(accounts, current_account_id, **options)
allow(Account).to receive(:following_map).with([], current_account_id).and_return({})
allow(Account).to receive(:followed_by_map).with([], current_account_id).and_return({})
allow(Account).to receive(:blocking_map).with([], current_account_id).and_return({})
allow(Account).to receive(:muting_map).with([], current_account_id).and_return({})
allow(Account).to receive(:requested_map).with([], current_account_id).and_return({})
allow(Account).to receive(:requested_by_map).with([], current_account_id).and_return({})
end
it 'sets returns expected values' do
expect(presenter).to have_attributes(
following: default_map,
followed_by: default_map,
blocking: default_map,
muting: default_map,
requested: default_map,
domain_blocking: { accounts[0].id => nil }
)
end
end
@ -86,7 +111,7 @@ RSpec.describe AccountRelationshipsPresenter do
let(:options) { { domain_blocking_map: { 7 => true } } }
it 'sets @domain_blocking merged with default_map and options[:domain_blocking_map]' do
expect(presenter.domain_blocking).to eq default_map.merge(options[:domain_blocking_map])
expect(presenter.domain_blocking).to eq({ accounts[0].id => nil }.merge(options[:domain_blocking_map]))
end
end
end

View file

@ -6,12 +6,6 @@ describe InstancePresenter do
let(:instance_presenter) { described_class.new }
describe '#description' do
around do |example|
site_description = Setting.site_short_description
example.run
Setting.site_short_description = site_description
end
it 'delegates site_description to Setting' do
Setting.site_short_description = 'Site desc'
expect(instance_presenter.description).to eq 'Site desc'
@ -19,12 +13,6 @@ describe InstancePresenter do
end
describe '#extended_description' do
around do |example|
site_extended_description = Setting.site_extended_description
example.run
Setting.site_extended_description = site_extended_description
end
it 'delegates site_extended_description to Setting' do
Setting.site_extended_description = 'Extended desc'
expect(instance_presenter.extended_description).to eq 'Extended desc'
@ -32,12 +20,6 @@ describe InstancePresenter do
end
describe '#email' do
around do |example|
site_contact_email = Setting.site_contact_email
example.run
Setting.site_contact_email = site_contact_email
end
it 'delegates contact_email to Setting' do
Setting.site_contact_email = 'admin@example.com'
expect(instance_presenter.contact.email).to eq 'admin@example.com'
@ -45,12 +27,6 @@ describe InstancePresenter do
end
describe '#account' do
around do |example|
site_contact_username = Setting.site_contact_username
example.run
Setting.site_contact_username = site_contact_username
end
it 'returns the account for the site contact username' do
Setting.site_contact_username = 'aaa'
account = Fabricate(:account, username: 'aaa')