Reduce factory data created in spec/models/trends/statuses spec (#25410)

pull/25421/head
Matt Jankowski 2023-06-14 03:57:06 -04:00 committed by GitHub
parent 31d5bc89d1
commit ae9f5379d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 10 deletions

View File

@ -15,8 +15,8 @@ RSpec.describe Trends::Statuses do
let!(:status2) { Fabricate(:status, text: 'Bar', language: 'en', trendable: true, created_at: today) } let!(:status2) { Fabricate(:status, text: 'Bar', language: 'en', trendable: true, created_at: today) }
before do before do
15.times { reblog(status1, today) } default_threshold_value.times { reblog(status1, today) }
12.times { reblog(status2, today) } default_threshold_value.times { reblog(status2, today) }
subject.refresh(today) subject.refresh(today)
end end
@ -76,9 +76,9 @@ RSpec.describe Trends::Statuses do
let!(:status3) { Fabricate(:status, text: 'Baz', language: 'en', trendable: true, created_at: today) } let!(:status3) { Fabricate(:status, text: 'Baz', language: 'en', trendable: true, created_at: today) }
before do before do
13.times { reblog(status1, today) } default_threshold_value.times { reblog(status1, today) }
13.times { reblog(status2, today) } default_threshold_value.times { reblog(status2, today) }
4.times { reblog(status3, today) } (default_threshold_value - 1).times { reblog(status3, today) }
end end
context 'when status trends are refreshed' do context 'when status trends are refreshed' do
@ -86,12 +86,11 @@ RSpec.describe Trends::Statuses do
subject.refresh(today) subject.refresh(today)
end end
it 'calculates and re-calculates scores' do it 'returns correct statuses from query' do
expect(subject.query.limit(10).to_a).to eq [status2, status1] results = subject.query.limit(10).to_a
end
it 'omits statuses below threshold' do expect(results).to eq [status2, status1]
expect(subject.query.limit(10).to_a).to_not include(status3) expect(results).to_not include(status3)
end end
end end
@ -109,4 +108,8 @@ RSpec.describe Trends::Statuses do
reblog = Fabricate(:status, reblog: status, created_at: at_time) reblog = Fabricate(:status, reblog: status, created_at: at_time)
subject.add(status, reblog.account_id, at_time) subject.add(status, reblog.account_id, at_time)
end end
def default_threshold_value
described_class.default_options[:threshold]
end
end end