mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-23 18:02:59 +01:00
e38fc319dc
* Change account and user fabricators to simplify and improve tests - `Fabricate(:account)` implicitly fabricates an associated `user` if no `domain` attribute is given (an account with `domain: nil` is considered a local account, but no user record was created), unless `user: nil` is passed - `Fabricate(:account, user: Fabricate(:user))` should still be possible but is discouraged. * Fix and refactor tests - avoid passing unneeded attributes to `Fabricate(:user)` or `Fabricate(:account)` - avoid embedding `Fabricate(:user)` into a `Fabricate(:account)` or the other way around - prefer `Fabricate(:user, account_attributes: …)` to `Fabricate(:user, account: Fabricate(:account, …)` - also, some tests were using remote accounts with local user records, which is not representative of production code.
210 lines
6.9 KiB
Ruby
210 lines
6.9 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe PublicFeed, type: :model do
|
|
let(:account) { Fabricate(:account) }
|
|
|
|
describe '#get' do
|
|
subject { described_class.new(nil).get(20).map(&:id) }
|
|
|
|
it 'only includes statuses with public visibility' do
|
|
public_status = Fabricate(:status, visibility: :public)
|
|
private_status = Fabricate(:status, visibility: :private)
|
|
|
|
expect(subject).to include(public_status.id)
|
|
expect(subject).not_to include(private_status.id)
|
|
end
|
|
|
|
it 'does not include replies' do
|
|
status = Fabricate(:status)
|
|
reply = Fabricate(:status, in_reply_to_id: status.id)
|
|
|
|
expect(subject).to include(status.id)
|
|
expect(subject).not_to include(reply.id)
|
|
end
|
|
|
|
it 'does not include boosts' do
|
|
status = Fabricate(:status)
|
|
boost = Fabricate(:status, reblog_of_id: status.id)
|
|
|
|
expect(subject).to include(status.id)
|
|
expect(subject).not_to include(boost.id)
|
|
end
|
|
|
|
it 'filters out silenced accounts' do
|
|
silenced_account = Fabricate(:account, silenced: true)
|
|
status = Fabricate(:status, account: account)
|
|
silenced_status = Fabricate(:status, account: silenced_account)
|
|
|
|
expect(subject).to include(status.id)
|
|
expect(subject).not_to include(silenced_status.id)
|
|
end
|
|
|
|
context 'without local_only option' do
|
|
let(:viewer) { nil }
|
|
|
|
let!(:local_account) { Fabricate(:account, domain: nil) }
|
|
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
|
|
let!(:local_status) { Fabricate(:status, account: local_account) }
|
|
let!(:remote_status) { Fabricate(:status, account: remote_account) }
|
|
|
|
subject { described_class.new(viewer).get(20).map(&:id) }
|
|
|
|
context 'without a viewer' do
|
|
let(:viewer) { nil }
|
|
|
|
it 'includes remote instances statuses' do
|
|
expect(subject).to include(remote_status.id)
|
|
end
|
|
|
|
it 'includes local statuses' do
|
|
expect(subject).to include(local_status.id)
|
|
end
|
|
end
|
|
|
|
context 'with a viewer' do
|
|
let(:viewer) { Fabricate(:account, username: 'viewer') }
|
|
|
|
it 'includes remote instances statuses' do
|
|
expect(subject).to include(remote_status.id)
|
|
end
|
|
|
|
it 'includes local statuses' do
|
|
expect(subject).to include(local_status.id)
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'with a local_only option set' do
|
|
let!(:local_account) { Fabricate(:account, domain: nil) }
|
|
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
|
|
let!(:local_status) { Fabricate(:status, account: local_account) }
|
|
let!(:remote_status) { Fabricate(:status, account: remote_account) }
|
|
|
|
subject { described_class.new(viewer, local: true).get(20).map(&:id) }
|
|
|
|
context 'without a viewer' do
|
|
let(:viewer) { nil }
|
|
|
|
it 'does not include remote instances statuses' do
|
|
expect(subject).to include(local_status.id)
|
|
expect(subject).not_to include(remote_status.id)
|
|
end
|
|
end
|
|
|
|
context 'with a viewer' do
|
|
let(:viewer) { Fabricate(:account, username: 'viewer') }
|
|
|
|
it 'does not include remote instances statuses' do
|
|
expect(subject).to include(local_status.id)
|
|
expect(subject).not_to include(remote_status.id)
|
|
end
|
|
|
|
it 'is not affected by personal domain blocks' do
|
|
viewer.block_domain!('test.com')
|
|
expect(subject).to include(local_status.id)
|
|
expect(subject).not_to include(remote_status.id)
|
|
end
|
|
end
|
|
end
|
|
|
|
context 'with a remote_only option set' do
|
|
let!(:local_account) { Fabricate(:account, domain: nil) }
|
|
let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
|
|
let!(:local_status) { Fabricate(:status, account: local_account) }
|
|
let!(:remote_status) { Fabricate(:status, account: remote_account) }
|
|
|
|
subject { described_class.new(viewer, remote: true).get(20).map(&:id) }
|
|
|
|
context 'without a viewer' do
|
|
let(:viewer) { nil }
|
|
|
|
it 'does not include local instances statuses' do
|
|
expect(subject).not_to include(local_status.id)
|
|
expect(subject).to include(remote_status.id)
|
|
end
|
|
end
|
|
|
|
context 'with a viewer' do
|
|
let(:viewer) { Fabricate(:account, username: 'viewer') }
|
|
|
|
it 'does not include local instances statuses' do
|
|
expect(subject).not_to include(local_status.id)
|
|
expect(subject).to include(remote_status.id)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe 'with an account passed in' do
|
|
before do
|
|
@account = Fabricate(:account)
|
|
end
|
|
|
|
subject { described_class.new(@account).get(20).map(&:id) }
|
|
|
|
it 'excludes statuses from accounts blocked by the account' do
|
|
blocked = Fabricate(:account)
|
|
@account.block!(blocked)
|
|
blocked_status = Fabricate(:status, account: blocked)
|
|
|
|
expect(subject).not_to include(blocked_status.id)
|
|
end
|
|
|
|
it 'excludes statuses from accounts who have blocked the account' do
|
|
blocker = Fabricate(:account)
|
|
blocker.block!(@account)
|
|
blocked_status = Fabricate(:status, account: blocker)
|
|
|
|
expect(subject).not_to include(blocked_status.id)
|
|
end
|
|
|
|
it 'excludes statuses from accounts muted by the account' do
|
|
muted = Fabricate(:account)
|
|
@account.mute!(muted)
|
|
muted_status = Fabricate(:status, account: muted)
|
|
|
|
expect(subject).not_to include(muted_status.id)
|
|
end
|
|
|
|
it 'excludes statuses from accounts from personally blocked domains' do
|
|
blocked = Fabricate(:account, domain: 'example.com')
|
|
@account.block_domain!(blocked.domain)
|
|
blocked_status = Fabricate(:status, account: blocked)
|
|
|
|
expect(subject).not_to include(blocked_status.id)
|
|
end
|
|
|
|
context 'with language preferences' do
|
|
it 'excludes statuses in languages not allowed by the account user' do
|
|
@account.user.update(chosen_languages: [:en, :es])
|
|
en_status = Fabricate(:status, language: 'en')
|
|
es_status = Fabricate(:status, language: 'es')
|
|
fr_status = Fabricate(:status, language: 'fr')
|
|
|
|
expect(subject).to include(en_status.id)
|
|
expect(subject).to include(es_status.id)
|
|
expect(subject).not_to include(fr_status.id)
|
|
end
|
|
|
|
it 'includes all languages when user does not have a setting' do
|
|
@account.user.update(chosen_languages: nil)
|
|
|
|
en_status = Fabricate(:status, language: 'en')
|
|
es_status = Fabricate(:status, language: 'es')
|
|
|
|
expect(subject).to include(en_status.id)
|
|
expect(subject).to include(es_status.id)
|
|
end
|
|
|
|
it 'includes all languages when account does not have a user' do
|
|
@account.update(user: nil)
|
|
|
|
en_status = Fabricate(:status, language: 'en')
|
|
es_status = Fabricate(:status, language: 'es')
|
|
|
|
expect(subject).to include(en_status.id)
|
|
expect(subject).to include(es_status.id)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|