mastodon/spec/models/public_feed_spec.rb
Claire d77fbbed73 Merge commit 'f877aa9d70d0d600961989b8e97c0e0ce3ac1db6' into glitch-soc/merge-upstream
Conflicts:
- `.github/dependabot.yml`:
  Upstream made changes, but we had removed it.
  Discarded upstream changes.
- `.rubocop_todo.yml`:
  Upstream regenerated the file, we had some glitch-soc-specific ignores.
- `app/models/account_statuses_filter.rb`:
  Minor upstream code style change where glitch-soc had slightly different code
  due to handling of local-only posts.
  Updated to match upstream's code style.
- `app/models/status.rb`:
  Upstream moved ActiveRecord callback definitions, glitch-soc had an extra one.
  Moved the definitions as upstream did.
- `app/services/backup_service.rb`:
  Upstream rewrote a lot of the backup service, glitch-soc had changes because
  of exporting local-only posts.
  Took upstream changes and added back code to deal with local-only posts.
- `config/routes.rb`:
  Upstream split the file into different files, while glitch-soc had a few
  extra routes.
  Extra routes added to `config/routes/settings.rb`, `config/routes/api.rb`
  and `config/routes/admin.rb`
- `db/schema.rb`:
  Upstream has new migrations, while glitch-soc had an extra migration.
  Updated the expected serial number to match upstream's.
- `lib/mastodon/version.rb`:
  Upstream added support to set version tags from environment variables, while
  glitch-soc has an extra `+glitch` tag.
  Changed the code to support upstream's feature but prepending a `+glitch`.
- `spec/lib/activitypub/activity/create_spec.rb`:
  Minor code style change upstream, while glitch-soc has extra tests due to
  `directMessage` handling.
  Applied upstream's changes while keeping glitch-soc's extra tests.
- `spec/models/concerns/account_interactions_spec.rb`:
  Minor code style change upstream, while glitch-soc has extra tests.
  Applied upstream's changes while keeping glitch-soc's extra tests.
2023-05-08 19:28:21 +02:00

275 lines
9 KiB
Ruby

# frozen_string_literal: true
require 'rails_helper'
RSpec.describe PublicFeed 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).to_not 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).to_not 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).to_not 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).to_not include(silenced_status.id)
end
context 'without local_only option' do
subject { described_class.new(viewer).get(20).map(&:id) }
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) }
let!(:local_only_status) { Fabricate(:status, account: local_account, local_only: true) }
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
it 'does not include local-only statuses' do
expect(subject).to_not include(local_only_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
it 'does not include local-only statuses' do
expect(subject).to_not include(local_only_status.id)
end
end
end
context 'without local_only option but allow_local_only' do
subject { described_class.new(viewer, allow_local_only: true).get(20).map(&:id) }
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) }
let!(:local_only_status) { Fabricate(:status, account: local_account, local_only: true) }
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
it 'does not include local-only statuses' do
expect(subject).to_not include(local_only_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
it 'includes local-only statuses' do
expect(subject).to include(local_only_status.id)
end
end
end
context 'with a local_only option set' do
subject { described_class.new(viewer, local: true).get(20).map(&:id) }
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) }
let!(:local_only_status) { Fabricate(:status, account: local_account, local_only: true) }
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).to_not include(remote_status.id)
end
it 'does not include local-only statuses' do
expect(subject).to_not include(local_only_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).to_not 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).to_not include(remote_status.id)
end
it 'includes local-only statuses' do
expect(subject).to include(local_only_status.id)
end
end
end
context 'with a remote_only option set' do
subject { described_class.new(viewer, remote: true).get(20).map(&:id) }
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) }
context 'without a viewer' do
let(:viewer) { nil }
it 'does not include local instances statuses' do
expect(subject).to_not 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).to_not include(local_status.id)
expect(subject).to include(remote_status.id)
end
end
end
describe 'with an account passed in' do
subject { described_class.new(@account).get(20).map(&:id) }
before do
@account = Fabricate(:account)
end
it 'excludes statuses from accounts blocked by the account' do
blocked = Fabricate(:account)
@account.block!(blocked)
blocked_status = Fabricate(:status, account: blocked)
expect(subject).to_not 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).to_not 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).to_not 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).to_not 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).to_not 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