Account statuses filter spec speedup (#27674)

pull/27737/head
Matt Jankowski 2023-11-07 10:47:01 -05:00 committed by GitHub
parent ae7c20b00c
commit ee57bb4b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 48 additions and 46 deletions

View File

@ -3,8 +3,6 @@
require 'rails_helper'
RSpec.describe AccountStatusesFilter do
subject { described_class.new(account, current_account, params) }
let(:account) { Fabricate(:account) }
let(:current_account) { nil }
let(:params) { {} }
@ -38,6 +36,8 @@ RSpec.describe AccountStatusesFilter do
end
describe '#results' do
subject { described_class.new(account, current_account, params).results }
let(:tag) { Fabricate(:tag) }
before do
@ -56,7 +56,7 @@ RSpec.describe AccountStatusesFilter do
let(:params) { { only_media: true } }
it 'returns only statuses with media' do
expect(subject.results.all?(&:with_media?)).to be true
expect(subject.all?(&:with_media?)).to be true
end
end
@ -64,7 +64,7 @@ RSpec.describe AccountStatusesFilter do
let(:params) { { tagged: tag.name } }
it 'returns only statuses with tag' do
expect(subject.results.all? { |s| s.tags.include?(tag) }).to be true
expect(subject.all? { |s| s.tags.include?(tag) }).to be true
end
end
@ -72,7 +72,7 @@ RSpec.describe AccountStatusesFilter do
let(:params) { { exclude_replies: true } }
it 'returns only statuses that are not replies' do
expect(subject.results.none?(&:reply?)).to be true
expect(subject.none?(&:reply?)).to be true
end
end
@ -80,7 +80,7 @@ RSpec.describe AccountStatusesFilter do
let(:params) { { exclude_reblogs: true } }
it 'returns only statuses that are not reblogs' do
expect(subject.results.none?(&:reblog?)).to be true
expect(subject.none?(&:reblog?)).to be true
end
end
end
@ -89,16 +89,12 @@ RSpec.describe AccountStatusesFilter do
let(:current_account) { nil }
let(:direct_status) { nil }
it 'returns only public statuses' do
expect(subject.results.pluck(:visibility).uniq).to match_array %w(unlisted public)
end
it 'returns only public statuses, public replies, and public reblogs' do
expect(results_unique_visibilities).to match_array %w(unlisted public)
it 'returns public replies' do
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
end
expect(results_in_reply_to_ids).to_not be_empty
it 'returns public reblogs' do
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
expect(results_reblog_of_ids).to_not be_empty
end
it_behaves_like 'filter params'
@ -112,23 +108,19 @@ RSpec.describe AccountStatusesFilter do
end
it 'returns nothing' do
expect(subject.results.to_a).to be_empty
expect(subject.to_a).to be_empty
end
end
context 'when accessed by self' do
let(:current_account) { account }
it 'returns everything' do
expect(subject.results.pluck(:visibility).uniq).to match_array %w(direct private unlisted public)
end
it 'returns all statuses, replies, and reblogs' do
expect(results_unique_visibilities).to match_array %w(direct private unlisted public)
it 'returns replies' do
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
end
expect(results_in_reply_to_ids).to_not be_empty
it 'returns reblogs' do
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
expect(results_reblog_of_ids).to_not be_empty
end
it_behaves_like 'filter params'
@ -141,23 +133,19 @@ RSpec.describe AccountStatusesFilter do
current_account.follow!(account)
end
it 'returns private statuses' do
expect(subject.results.pluck(:visibility).uniq).to match_array %w(private unlisted public)
end
it 'returns private statuses, replies, and reblogs' do
expect(results_unique_visibilities).to match_array %w(private unlisted public)
it 'returns replies' do
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
end
expect(results_in_reply_to_ids).to_not be_empty
it 'returns reblogs' do
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
expect(results_reblog_of_ids).to_not be_empty
end
context 'when there is a direct status mentioning the non-follower' do
let!(:direct_status) { status_with_mention!(:direct, current_account) }
it 'returns the direct status' do
expect(subject.results.pluck(:id)).to include(direct_status.id)
expect(results_ids).to include(direct_status.id)
end
end
@ -167,23 +155,19 @@ RSpec.describe AccountStatusesFilter do
context 'when accessed by a non-follower' do
let(:current_account) { Fabricate(:account) }
it 'returns only public statuses' do
expect(subject.results.pluck(:visibility).uniq).to match_array %w(unlisted public)
end
it 'returns only public statuses, replies, and reblogs' do
expect(results_unique_visibilities).to match_array %w(unlisted public)
it 'returns public replies' do
expect(subject.results.pluck(:in_reply_to_id)).to_not be_empty
end
expect(results_in_reply_to_ids).to_not be_empty
it 'returns public reblogs' do
expect(subject.results.pluck(:reblog_of_id)).to_not be_empty
expect(results_reblog_of_ids).to_not be_empty
end
context 'when there is a private status mentioning the non-follower' do
let!(:private_status) { status_with_mention!(:private, current_account) }
it 'returns the private status' do
expect(subject.results.pluck(:id)).to include(private_status.id)
expect(results_ids).to include(private_status.id)
end
end
@ -195,7 +179,7 @@ RSpec.describe AccountStatusesFilter do
end
it 'does not return reblog of blocked account' do
expect(subject.results.pluck(:id)).to_not include(reblog.id)
expect(results_ids).to_not include(reblog.id)
end
end
@ -209,7 +193,7 @@ RSpec.describe AccountStatusesFilter do
end
it 'does not return reblog of blocked domain' do
expect(subject.results.pluck(:id)).to_not include(reblog.id)
expect(results_ids).to_not include(reblog.id)
end
end
@ -223,7 +207,7 @@ RSpec.describe AccountStatusesFilter do
end
it 'returns the reblog from the non-blocked domain' do
expect(subject.results.pluck(:id)).to include(reblog.id)
expect(results_ids).to include(reblog.id)
end
end
@ -235,7 +219,7 @@ RSpec.describe AccountStatusesFilter do
end
it 'does not return reblog of muted account' do
expect(subject.results.pluck(:id)).to_not include(reblog.id)
expect(results_ids).to_not include(reblog.id)
end
end
@ -247,11 +231,29 @@ RSpec.describe AccountStatusesFilter do
end
it 'does not return reblog of blocked-by account' do
expect(subject.results.pluck(:id)).to_not include(reblog.id)
expect(results_ids).to_not include(reblog.id)
end
end
it_behaves_like 'filter params'
end
private
def results_unique_visibilities
subject.pluck(:visibility).uniq
end
def results_in_reply_to_ids
subject.pluck(:in_reply_to_id)
end
def results_reblog_of_ids
subject.pluck(:reblog_of_id)
end
def results_ids
subject.pluck(:id)
end
end
end