mirror of
https://github.com/mastodon/mastodon.git
synced 2025-05-07 20:26:15 +00:00
Add model specs
This commit is contained in:
parent
c94e298746
commit
cee1378231
|
@ -15,4 +15,5 @@ Fabricator(:account) do
|
|||
user { |attrs| attrs[:domain].nil? ? Fabricate.build(:user, account: nil) : nil }
|
||||
uri { |attrs| attrs[:domain].nil? ? '' : "https://#{attrs[:domain]}/users/#{attrs[:username]}" }
|
||||
discoverable true
|
||||
indexable true
|
||||
end
|
||||
|
|
|
@ -3,5 +3,92 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Fasp::BackfillRequest do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe '#next_objects' do
|
||||
let(:account) { Fabricate(:account) }
|
||||
|
||||
before { Fabricate.times(3, :status, account:).sort_by(&:id) }
|
||||
|
||||
context 'with a new backfill request' do
|
||||
subject { Fabricate(:fasp_backfill_request, max_count: 2) }
|
||||
|
||||
it 'returns the newest two statuses' do
|
||||
expect(subject.next_objects).to eq [statuses[2], statuses[1]]
|
||||
end
|
||||
end
|
||||
|
||||
context 'with cursor set to second newest status' do
|
||||
subject do
|
||||
Fabricate(:fasp_backfill_request, max_count: 2, cursor: statuses[1].id)
|
||||
end
|
||||
|
||||
it 'returns the oldest status' do
|
||||
expect(subject.next_objects).to eq [statuses[0]]
|
||||
end
|
||||
end
|
||||
|
||||
context 'when all statuses are not `indexable`' do
|
||||
subject { Fabricate(:fasp_backfill_request) }
|
||||
|
||||
let(:account) { Fabricate(:account, indexable: false) }
|
||||
|
||||
it 'returns no statuses' do
|
||||
expect(subject.next_objects).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#next_uris' do
|
||||
subject { Fabricate(:fasp_backfill_request) }
|
||||
|
||||
let(:statuses) { Fabricate.times(2, :status) }
|
||||
|
||||
it 'returns uris of the next objects' do
|
||||
uris = statuses.map(&:uri)
|
||||
|
||||
expect(subject.next_uris).to match_array(uris)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#more_objects_available?' do
|
||||
subject { Fabricate(:fasp_backfill_request, max_count: 2) }
|
||||
|
||||
context 'when more objects are available' do
|
||||
before { Fabricate.times(3, :status) }
|
||||
|
||||
it 'returns `true`' do
|
||||
expect(subject.more_objects_available?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'when no more objects are available' do
|
||||
before { Fabricate.times(2, :status) }
|
||||
|
||||
it 'returns `false`' do
|
||||
expect(subject.more_objects_available?).to be false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#advance!' do
|
||||
subject { Fabricate(:fasp_backfill_request, max_count: 2) }
|
||||
|
||||
context 'when more objects are available' do
|
||||
before { Fabricate.times(3, :status) }
|
||||
|
||||
it 'updates `cursor`' do
|
||||
expect { subject.advance! }.to change(subject, :cursor)
|
||||
expect(subject).to be_persisted
|
||||
end
|
||||
end
|
||||
|
||||
context 'when no more objects are available' do
|
||||
before { Fabricate.times(2, :status) }
|
||||
|
||||
it 'sets `fulfilled` to `true`' do
|
||||
expect { subject.advance! }.to change(subject, :fulfilled)
|
||||
.from(false).to(true)
|
||||
expect(subject).to be_persisted
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,5 +3,31 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Fasp::Subscription do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
describe '#threshold=' do
|
||||
subject { described_class.new }
|
||||
|
||||
it 'allows setting all threshold values at once' do
|
||||
subject.threshold = {
|
||||
'timeframe' => 30,
|
||||
'shares' => 5,
|
||||
'likes' => 8,
|
||||
'replies' => 7,
|
||||
}
|
||||
|
||||
expect(subject.threshold_timeframe).to eq 30
|
||||
expect(subject.threshold_shares).to eq 5
|
||||
expect(subject.threshold_likes).to eq 8
|
||||
expect(subject.threshold_replies).to eq 7
|
||||
end
|
||||
end
|
||||
|
||||
describe '#timeframe_start' do
|
||||
subject { described_class.new(threshold_timeframe: 45) }
|
||||
|
||||
it 'returns a Time representing the beginning of the timeframe' do
|
||||
travel_to Time.zone.local(2025, 4, 7, 16, 40) do
|
||||
expect(subject.timeframe_start).to eq Time.zone.local(2025, 4, 7, 15, 55)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user