Merge remote-tracking branch 'parent/main' into upstream-20231204
This commit is contained in:
commit
94c2396a34
179 changed files with 1036 additions and 775 deletions
62
spec/models/concerns/account/counters_spec.rb
Normal file
62
spec/models/concerns/account/counters_spec.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Account::Counters do
|
||||
let!(:account) { Fabricate(:account) }
|
||||
|
||||
describe '#increment_count!' do
|
||||
it 'increments the count' do
|
||||
expect(account.followers_count).to eq 0
|
||||
account.increment_count!(:followers_count)
|
||||
expect(account.followers_count).to eq 1
|
||||
end
|
||||
|
||||
it 'increments the count in multi-threaded an environment' do
|
||||
increment_by = 15
|
||||
wait_for_start = true
|
||||
|
||||
threads = Array.new(increment_by) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
account.increment_count!(:statuses_count)
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(account.statuses_count).to eq increment_by
|
||||
end
|
||||
end
|
||||
|
||||
describe '#decrement_count!' do
|
||||
it 'decrements the count' do
|
||||
account.followers_count = 15
|
||||
account.save!
|
||||
expect(account.followers_count).to eq 15
|
||||
account.decrement_count!(:followers_count)
|
||||
expect(account.followers_count).to eq 14
|
||||
end
|
||||
|
||||
it 'decrements the count in multi-threaded an environment' do
|
||||
decrement_by = 10
|
||||
wait_for_start = true
|
||||
|
||||
account.statuses_count = 15
|
||||
account.save!
|
||||
|
||||
threads = Array.new(decrement_by) do
|
||||
Thread.new do
|
||||
true while wait_for_start
|
||||
account.decrement_count!(:statuses_count)
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_start = false
|
||||
threads.each(&:join)
|
||||
|
||||
expect(account.statuses_count).to eq 5
|
||||
end
|
||||
end
|
||||
end
|
105
spec/models/concerns/account/finder_concern_spec.rb
Normal file
105
spec/models/concerns/account/finder_concern_spec.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Account::FinderConcern do
|
||||
describe 'local finders' do
|
||||
let!(:account) { Fabricate(:account, username: 'Alice') }
|
||||
|
||||
describe '.find_local' do
|
||||
it 'returns case-insensitive result' do
|
||||
expect(Account.find_local('alice')).to eq(account)
|
||||
end
|
||||
|
||||
it 'returns correctly cased result' do
|
||||
expect(Account.find_local('Alice')).to eq(account)
|
||||
end
|
||||
|
||||
it 'returns nil without a match' do
|
||||
expect(Account.find_local('a_ice')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for regex style username value' do
|
||||
expect(Account.find_local('al%')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for nil username value' do
|
||||
expect(Account.find_local(nil)).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for blank username value' do
|
||||
expect(Account.find_local('')).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '.find_local!' do
|
||||
it 'returns matching result' do
|
||||
expect(Account.find_local!('alice')).to eq(account)
|
||||
end
|
||||
|
||||
it 'raises on non-matching result' do
|
||||
expect { Account.find_local!('missing') }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'raises with blank username' do
|
||||
expect { Account.find_local!('') }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'raises with nil username' do
|
||||
expect { Account.find_local!(nil) }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'remote finders' do
|
||||
let!(:account) { Fabricate(:account, username: 'Alice', domain: 'mastodon.social') }
|
||||
|
||||
describe '.find_remote' do
|
||||
it 'returns exact match result' do
|
||||
expect(Account.find_remote('alice', 'mastodon.social')).to eq(account)
|
||||
end
|
||||
|
||||
it 'returns case-insensitive result' do
|
||||
expect(Account.find_remote('ALICE', 'MASTODON.SOCIAL')).to eq(account)
|
||||
end
|
||||
|
||||
it 'returns nil when username does not match' do
|
||||
expect(Account.find_remote('a_ice', 'mastodon.social')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil when domain does not match' do
|
||||
expect(Account.find_remote('alice', 'm_stodon.social')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for regex style domain value' do
|
||||
expect(Account.find_remote('alice', 'm%')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for nil username value' do
|
||||
expect(Account.find_remote(nil, 'domain')).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for blank username value' do
|
||||
expect(Account.find_remote('', 'domain')).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe '.find_remote!' do
|
||||
it 'returns matching result' do
|
||||
expect(Account.find_remote!('alice', 'mastodon.social')).to eq(account)
|
||||
end
|
||||
|
||||
it 'raises on non-matching result' do
|
||||
expect { Account.find_remote!('missing', 'mastodon.host') }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'raises with blank username' do
|
||||
expect { Account.find_remote!('', '') }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
|
||||
it 'raises with nil username' do
|
||||
expect { Account.find_remote!(nil, nil) }.to raise_error(ActiveRecord::RecordNotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
730
spec/models/concerns/account/interactions_spec.rb
Normal file
730
spec/models/concerns/account/interactions_spec.rb
Normal file
|
@ -0,0 +1,730 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Account::Interactions do
|
||||
let(:account) { Fabricate(:account, username: 'account') }
|
||||
let(:account_id) { account.id }
|
||||
let(:account_ids) { [account_id] }
|
||||
let(:target_account) { Fabricate(:account, username: 'target') }
|
||||
let(:target_account_id) { target_account.id }
|
||||
let(:target_account_ids) { [target_account_id] }
|
||||
let(:follower_account) { Fabricate(:account, username: 'follower') }
|
||||
let(:followee_account) { Fabricate(:account, username: 'followee') }
|
||||
|
||||
describe '.following_map' do
|
||||
subject { Account.following_map(target_account_ids, account_id) }
|
||||
|
||||
context 'when Account with Follow' do
|
||||
it 'returns { target_account_id => true }' do
|
||||
Fabricate(:follow, account: account, target_account: target_account)
|
||||
expect(subject).to eq(target_account_id => { reblogs: true, notify: false, languages: nil })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Account without Follow' do
|
||||
it 'returns {}' do
|
||||
expect(subject).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.followed_by_map' do
|
||||
subject { Account.followed_by_map(target_account_ids, account_id) }
|
||||
|
||||
context 'when Account with Follow' do
|
||||
it 'returns { target_account_id => true }' do
|
||||
Fabricate(:follow, account: target_account, target_account: account)
|
||||
expect(subject).to eq(target_account_id => true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Account without Follow' do
|
||||
it 'returns {}' do
|
||||
expect(subject).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.blocking_map' do
|
||||
subject { Account.blocking_map(target_account_ids, account_id) }
|
||||
|
||||
context 'when Account with Block' do
|
||||
it 'returns { target_account_id => true }' do
|
||||
Fabricate(:block, account: account, target_account: target_account)
|
||||
expect(subject).to eq(target_account_id => true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Account without Block' do
|
||||
it 'returns {}' do
|
||||
expect(subject).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '.muting_map' do
|
||||
subject { Account.muting_map(target_account_ids, account_id) }
|
||||
|
||||
context 'when Account with Mute' do
|
||||
before do
|
||||
Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
|
||||
end
|
||||
|
||||
context 'when Mute#hide_notifications?' do
|
||||
let(:hide) { true }
|
||||
|
||||
it 'returns { target_account_id => { notifications: true } }' do
|
||||
expect(subject).to eq(target_account_id => { notifications: true })
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not Mute#hide_notifications?' do
|
||||
let(:hide) { false }
|
||||
|
||||
it 'returns { target_account_id => { notifications: false } }' do
|
||||
expect(subject).to eq(target_account_id => { notifications: false })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Account without Mute' do
|
||||
it 'returns {}' do
|
||||
expect(subject).to eq({})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#follow!' do
|
||||
it 'creates and returns Follow' do
|
||||
expect do
|
||||
expect(account.follow!(target_account)).to be_a Follow
|
||||
end.to change { account.following.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#block' do
|
||||
it 'creates and returns Block' do
|
||||
expect do
|
||||
expect(account.block!(target_account)).to be_a Block
|
||||
end.to change { account.block_relationships.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mute!' do
|
||||
subject { account.mute!(target_account, notifications: arg_notifications) }
|
||||
|
||||
context 'when Mute does not exist yet' do
|
||||
context 'when arg :notifications is nil' do
|
||||
let(:arg_notifications) { nil }
|
||||
|
||||
it 'creates Mute, and returns Mute' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to change { account.mute_relationships.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'when arg :notifications is false' do
|
||||
let(:arg_notifications) { false }
|
||||
|
||||
it 'creates Mute, and returns Mute' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to change { account.mute_relationships.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
context 'when arg :notifications is true' do
|
||||
let(:arg_notifications) { true }
|
||||
|
||||
it 'creates Mute, and returns Mute' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to change { account.mute_relationships.count }.by 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when Mute already exists' do
|
||||
before do
|
||||
account.mute_relationships << mute
|
||||
end
|
||||
|
||||
let(:mute) do
|
||||
Fabricate(:mute,
|
||||
account: account,
|
||||
target_account: target_account,
|
||||
hide_notifications: hide_notifications)
|
||||
end
|
||||
|
||||
context 'when mute.hide_notifications is true' do
|
||||
let(:hide_notifications) { true }
|
||||
|
||||
context 'when arg :notifications is nil' do
|
||||
let(:arg_notifications) { nil }
|
||||
|
||||
it 'returns Mute without updating mute.hide_notifications' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to_not change { mute.reload.hide_notifications? }.from(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when arg :notifications is false' do
|
||||
let(:arg_notifications) { false }
|
||||
|
||||
it 'returns Mute, and updates mute.hide_notifications false' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to change { mute.reload.hide_notifications? }.from(true).to(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when arg :notifications is true' do
|
||||
let(:arg_notifications) { true }
|
||||
|
||||
it 'returns Mute without updating mute.hide_notifications' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to_not change { mute.reload.hide_notifications? }.from(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when mute.hide_notifications is false' do
|
||||
let(:hide_notifications) { false }
|
||||
|
||||
context 'when arg :notifications is nil' do
|
||||
let(:arg_notifications) { nil }
|
||||
|
||||
it 'returns Mute, and updates mute.hide_notifications true' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when arg :notifications is false' do
|
||||
let(:arg_notifications) { false }
|
||||
|
||||
it 'returns Mute without updating mute.hide_notifications' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to_not change { mute.reload.hide_notifications? }.from(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when arg :notifications is true' do
|
||||
let(:arg_notifications) { true }
|
||||
|
||||
it 'returns Mute, and updates mute.hide_notifications true' do
|
||||
expect do
|
||||
expect(subject).to be_a Mute
|
||||
end.to change { mute.reload.hide_notifications? }.from(false).to(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mute_conversation!' do
|
||||
subject { account.mute_conversation!(conversation) }
|
||||
|
||||
let(:conversation) { Fabricate(:conversation) }
|
||||
|
||||
it 'creates and returns ConversationMute' do
|
||||
expect do
|
||||
expect(subject).to be_a ConversationMute
|
||||
end.to change { account.conversation_mutes.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#block_domain!' do
|
||||
subject { account.block_domain!(domain) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
it 'creates and returns AccountDomainBlock' do
|
||||
expect do
|
||||
expect(subject).to be_a AccountDomainBlock
|
||||
end.to change { account.domain_blocks.count }.by 1
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unfollow!' do
|
||||
subject { account.unfollow!(target_account) }
|
||||
|
||||
context 'when following target_account' do
|
||||
it 'returns destroyed Follow' do
|
||||
account.active_relationships.create(target_account: target_account)
|
||||
expect(subject).to be_a Follow
|
||||
expect(subject).to be_destroyed
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not following target_account' do
|
||||
it 'returns nil' do
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unblock!' do
|
||||
subject { account.unblock!(target_account) }
|
||||
|
||||
context 'when blocking target_account' do
|
||||
it 'returns destroyed Block' do
|
||||
account.block_relationships.create(target_account: target_account)
|
||||
expect(subject).to be_a Block
|
||||
expect(subject).to be_destroyed
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not blocking target_account' do
|
||||
it 'returns nil' do
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unmute!' do
|
||||
subject { account.unmute!(target_account) }
|
||||
|
||||
context 'when muting target_account' do
|
||||
it 'returns destroyed Mute' do
|
||||
account.mute_relationships.create(target_account: target_account)
|
||||
expect(subject).to be_a Mute
|
||||
expect(subject).to be_destroyed
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not muting target_account' do
|
||||
it 'returns nil' do
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unmute_conversation!' do
|
||||
subject { account.unmute_conversation!(conversation) }
|
||||
|
||||
let(:conversation) { Fabricate(:conversation) }
|
||||
|
||||
context 'when muting the conversation' do
|
||||
it 'returns destroyed ConversationMute' do
|
||||
account.conversation_mutes.create(conversation: conversation)
|
||||
expect(subject).to be_a ConversationMute
|
||||
expect(subject).to be_destroyed
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not muting the conversation' do
|
||||
it 'returns nil' do
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#unblock_domain!' do
|
||||
subject { account.unblock_domain!(domain) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
context 'when blocking the domain' do
|
||||
it 'returns destroyed AccountDomainBlock' do
|
||||
account_domain_block = Fabricate(:account_domain_block, domain: domain)
|
||||
account.domain_blocks << account_domain_block
|
||||
expect(subject).to be_a AccountDomainBlock
|
||||
expect(subject).to be_destroyed
|
||||
end
|
||||
end
|
||||
|
||||
context 'when unblocking the domain' do
|
||||
it 'returns nil' do
|
||||
expect(subject).to be_nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#following?' do
|
||||
subject { account.following?(target_account) }
|
||||
|
||||
context 'when following target_account' do
|
||||
it 'returns true' do
|
||||
account.active_relationships.create(target_account: target_account)
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not following target_account' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#followed_by?' do
|
||||
subject { account.followed_by?(target_account) }
|
||||
|
||||
context 'when followed by target_account' do
|
||||
it 'returns true' do
|
||||
account.passive_relationships.create(account: target_account)
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not followed by target_account' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#blocking?' do
|
||||
subject { account.blocking?(target_account) }
|
||||
|
||||
context 'when blocking target_account' do
|
||||
it 'returns true' do
|
||||
account.block_relationships.create(target_account: target_account)
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not blocking target_account' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#domain_blocking?' do
|
||||
subject { account.domain_blocking?(domain) }
|
||||
|
||||
let(:domain) { 'example.com' }
|
||||
|
||||
context 'when blocking the domain' do
|
||||
it 'returns true' do
|
||||
account_domain_block = Fabricate(:account_domain_block, domain: domain)
|
||||
account.domain_blocks << account_domain_block
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not blocking the domain' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#muting?' do
|
||||
subject { account.muting?(target_account) }
|
||||
|
||||
context 'when muting target_account' do
|
||||
it 'returns true' do
|
||||
mute = Fabricate(:mute, account: account, target_account: target_account)
|
||||
account.mute_relationships << mute
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not muting target_account' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#muting_conversation?' do
|
||||
subject { account.muting_conversation?(conversation) }
|
||||
|
||||
let(:conversation) { Fabricate(:conversation) }
|
||||
|
||||
context 'when muting the conversation' do
|
||||
it 'returns true' do
|
||||
account.conversation_mutes.create(conversation: conversation)
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not muting the conversation' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#muting_notifications?' do
|
||||
subject { account.muting_notifications?(target_account) }
|
||||
|
||||
before do
|
||||
mute = Fabricate(:mute, target_account: target_account, account: account, hide_notifications: hide)
|
||||
account.mute_relationships << mute
|
||||
end
|
||||
|
||||
context 'when muting notifications of target_account' do
|
||||
let(:hide) { true }
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not muting notifications of target_account' do
|
||||
let(:hide) { false }
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#requested?' do
|
||||
subject { account.requested?(target_account) }
|
||||
|
||||
context 'with requested by target_account' do
|
||||
it 'returns true' do
|
||||
Fabricate(:follow_request, account: account, target_account: target_account)
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not requested by target_account' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#favourited?' do
|
||||
subject { account.favourited?(status) }
|
||||
|
||||
let(:status) { Fabricate(:status, account: account, favourites: favourites) }
|
||||
|
||||
context 'when favorited' do
|
||||
let(:favourites) { [Fabricate(:favourite, account: account)] }
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not favorited' do
|
||||
let(:favourites) { [] }
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#reblogged?' do
|
||||
subject { account.reblogged?(status) }
|
||||
|
||||
let(:status) { Fabricate(:status, account: account, reblogs: reblogs) }
|
||||
|
||||
context 'with reblogged' do
|
||||
let(:reblogs) { [Fabricate(:status, account: account)] }
|
||||
|
||||
it 'returns true' do
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not reblogged' do
|
||||
let(:reblogs) { [] }
|
||||
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#pinned?' do
|
||||
subject { account.pinned?(status) }
|
||||
|
||||
let(:status) { Fabricate(:status, account: account) }
|
||||
|
||||
context 'when pinned' do
|
||||
it 'returns true' do
|
||||
Fabricate(:status_pin, account: account, status: status)
|
||||
expect(subject).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when not pinned' do
|
||||
it 'returns false' do
|
||||
expect(subject).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#remote_followers_hash' do
|
||||
let(:me) { Fabricate(:account, username: 'Me') }
|
||||
let(:remote_alice) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
||||
let(:remote_bob) { Fabricate(:account, username: 'bob', domain: 'example.org', uri: 'https://example.org/users/bob') }
|
||||
let(:remote_instance_actor) { Fabricate(:account, username: 'instance-actor', domain: 'example.org', uri: 'https://example.org') }
|
||||
let(:remote_eve) { Fabricate(:account, username: 'eve', domain: 'foo.org', uri: 'https://foo.org/users/eve') }
|
||||
|
||||
before do
|
||||
remote_alice.follow!(me)
|
||||
remote_bob.follow!(me)
|
||||
remote_instance_actor.follow!(me)
|
||||
remote_eve.follow!(me)
|
||||
me.follow!(remote_alice)
|
||||
end
|
||||
|
||||
it 'returns correct hash for remote domains' do
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '20aecbe774b3d61c25094370baf370012b9271c5b172ecedb05caff8d79ef0c7'
|
||||
expect(me.remote_followers_hash('https://foo.org/')).to eq 'ccb9c18a67134cfff9d62c7f7e7eb88e6b803446c244b84265565f4eba29df0e'
|
||||
expect(me.remote_followers_hash('https://foo.org.evil.com/')).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
expect(me.remote_followers_hash('https://foo')).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
end
|
||||
|
||||
it 'invalidates cache as needed when removing or adding followers' do
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '20aecbe774b3d61c25094370baf370012b9271c5b172ecedb05caff8d79ef0c7'
|
||||
remote_instance_actor.unfollow!(me)
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '707962e297b7bd94468a21bc8e506a1bcea607a9142cd64e27c9b106b2a5f6ec'
|
||||
remote_alice.unfollow!(me)
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '241b00794ce9b46aa864f3220afadef128318da2659782985bac5ed5bd436bff'
|
||||
remote_alice.follow!(me)
|
||||
expect(me.remote_followers_hash('https://example.org/')).to eq '707962e297b7bd94468a21bc8e506a1bcea607a9142cd64e27c9b106b2a5f6ec'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#local_followers_hash' do
|
||||
let(:me) { Fabricate(:account, username: 'Me') }
|
||||
let(:remote_alice) { Fabricate(:account, username: 'alice', domain: 'example.org', uri: 'https://example.org/users/alice') }
|
||||
|
||||
before do
|
||||
me.follow!(remote_alice)
|
||||
end
|
||||
|
||||
it 'returns correct hash for local users' do
|
||||
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
end
|
||||
|
||||
it 'invalidates cache as needed when removing or adding followers' do
|
||||
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
me.unfollow!(remote_alice)
|
||||
expect(remote_alice.local_followers_hash).to eq '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
me.follow!(remote_alice)
|
||||
expect(remote_alice.local_followers_hash).to eq Digest::SHA256.hexdigest(ActivityPub::TagManager.instance.uri_for(me))
|
||||
end
|
||||
end
|
||||
|
||||
describe 'muting an account' do
|
||||
let(:me) { Fabricate(:account, username: 'Me') }
|
||||
let(:you) { Fabricate(:account, username: 'You') }
|
||||
|
||||
context 'with the notifications option unspecified' do
|
||||
before do
|
||||
me.mute!(you)
|
||||
end
|
||||
|
||||
it 'defaults to muting notifications' do
|
||||
expect(me.muting_notifications?(you)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the notifications option set to false' do
|
||||
before do
|
||||
me.mute!(you, notifications: false)
|
||||
end
|
||||
|
||||
it 'does not mute notifications' do
|
||||
expect(me.muting_notifications?(you)).to be false
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the notifications option set to true' do
|
||||
before do
|
||||
me.mute!(you, notifications: true)
|
||||
end
|
||||
|
||||
it 'does mute notifications' do
|
||||
expect(me.muting_notifications?(you)).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'ignoring reblogs from an account' do
|
||||
let!(:me) { Fabricate(:account, username: 'Me') }
|
||||
let!(:you) { Fabricate(:account, username: 'You') }
|
||||
|
||||
context 'with the reblogs option unspecified' do
|
||||
before do
|
||||
me.follow!(you)
|
||||
end
|
||||
|
||||
it 'defaults to showing reblogs' do
|
||||
expect(me.muting_reblogs?(you)).to be(false)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the reblogs option set to false' do
|
||||
before do
|
||||
me.follow!(you, reblogs: false)
|
||||
end
|
||||
|
||||
it 'does mute reblogs' do
|
||||
expect(me.muting_reblogs?(you)).to be(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with the reblogs option set to true' do
|
||||
before do
|
||||
me.follow!(you, reblogs: true)
|
||||
end
|
||||
|
||||
it 'does not mute reblogs' do
|
||||
expect(me.muting_reblogs?(you)).to be(false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#lists_for_local_distribution' do
|
||||
let(:account) { Fabricate(:user, current_sign_in_at: Time.now.utc).account }
|
||||
let!(:inactive_follower_user) { Fabricate(:user, current_sign_in_at: 5.years.ago) }
|
||||
let!(:follower_user) { Fabricate(:user, current_sign_in_at: Time.now.utc) }
|
||||
let!(:follow_request_user) { Fabricate(:user, current_sign_in_at: Time.now.utc) }
|
||||
|
||||
let!(:inactive_follower_list) { Fabricate(:list, account: inactive_follower_user.account) }
|
||||
let!(:follower_list) { Fabricate(:list, account: follower_user.account) }
|
||||
let!(:follow_request_list) { Fabricate(:list, account: follow_request_user.account) }
|
||||
|
||||
let!(:self_list) { Fabricate(:list, account: account) }
|
||||
|
||||
before do
|
||||
inactive_follower_user.account.follow!(account)
|
||||
follower_user.account.follow!(account)
|
||||
follow_request_user.account.follow_requests.create!(target_account: account)
|
||||
|
||||
inactive_follower_list.accounts << account
|
||||
follower_list.accounts << account
|
||||
follow_request_list.accounts << account
|
||||
self_list.accounts << account
|
||||
end
|
||||
|
||||
it 'includes only the list from the active follower and from oneself' do
|
||||
expect(account.lists_for_local_distribution.to_a).to contain_exactly(follower_list, self_list)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#mutuals' do
|
||||
subject { account.mutuals }
|
||||
|
||||
context 'when following target_account' do
|
||||
it 'mutual one' do
|
||||
account.follow!(target_account)
|
||||
target_account.follow!(account)
|
||||
follower_account.follow!(account)
|
||||
account.follow!(followee_account)
|
||||
|
||||
expect(subject.count).to eq 1
|
||||
expect(subject.first.id).to eq target_account.id
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
66
spec/models/concerns/account/statuses_search_spec.rb
Normal file
66
spec/models/concerns/account/statuses_search_spec.rb
Normal file
|
@ -0,0 +1,66 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
describe Account::StatusesSearch do
|
||||
let(:account) { Fabricate(:account, indexable: indexable) }
|
||||
|
||||
before do
|
||||
allow(Chewy).to receive(:enabled?).and_return(true)
|
||||
end
|
||||
|
||||
describe '#enqueue_update_public_statuses_index' do
|
||||
before do
|
||||
allow(account).to receive(:enqueue_add_to_public_statuses_index)
|
||||
allow(account).to receive(:enqueue_remove_from_public_statuses_index)
|
||||
end
|
||||
|
||||
context 'when account is indexable' do
|
||||
let(:indexable) { true }
|
||||
|
||||
it 'enqueues add_to_public_statuses_index and not to remove_from_public_statuses_index' do
|
||||
account.enqueue_update_public_statuses_index
|
||||
expect(account).to have_received(:enqueue_add_to_public_statuses_index)
|
||||
expect(account).to_not have_received(:enqueue_remove_from_public_statuses_index)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when account is not indexable' do
|
||||
let(:indexable) { false }
|
||||
|
||||
it 'enqueues remove_from_public_statuses_index and not to add_to_public_statuses_index' do
|
||||
account.enqueue_update_public_statuses_index
|
||||
expect(account).to have_received(:enqueue_remove_from_public_statuses_index)
|
||||
expect(account).to_not have_received(:enqueue_add_to_public_statuses_index)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#enqueue_add_to_public_statuses_index' do
|
||||
let(:indexable) { true }
|
||||
let(:worker) { AddToPublicStatusesIndexWorker }
|
||||
|
||||
before do
|
||||
allow(worker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
it 'enqueues AddToPublicStatusesIndexWorker' do
|
||||
account.enqueue_add_to_public_statuses_index
|
||||
expect(worker).to have_received(:perform_async).with(account.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#enqueue_remove_from_public_statuses_index' do
|
||||
let(:indexable) { false }
|
||||
let(:worker) { RemoveFromPublicStatusesIndexWorker }
|
||||
|
||||
before do
|
||||
allow(worker).to receive(:perform_async)
|
||||
end
|
||||
|
||||
it 'enqueues RemoveFromPublicStatusesIndexWorker' do
|
||||
account.enqueue_remove_from_public_statuses_index
|
||||
expect(worker).to have_received(:perform_async).with(account.id)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue