Account statuses filter spec speedup (#27674)

This commit is contained in:
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

View file

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