Merge remote-tracking branch 'parent/main' into upstream-20241107
This commit is contained in:
commit
a003c2db89
98 changed files with 2002 additions and 590 deletions
|
@ -57,36 +57,24 @@ RSpec.describe AccountStatusesFilter do
|
|||
end
|
||||
|
||||
shared_examples 'filter params' do
|
||||
context 'with only_media param' do
|
||||
let(:params) { { only_media: true } }
|
||||
it 'respects param options in results' do
|
||||
expect(results_for(only_media: true))
|
||||
.to all(satisfy(&:with_media?))
|
||||
|
||||
it 'returns only statuses with media' do
|
||||
expect(subject.all?(&:with_media?)).to be true
|
||||
end
|
||||
expect(results_for(tagged: tag.name))
|
||||
.to all(satisfy { |status| status.tags.include?(tag) })
|
||||
|
||||
expect(results_for(exclude_replies: true))
|
||||
.to all(satisfy { |status| !status.reply? })
|
||||
|
||||
expect(results_for(exclude_reblogs: true))
|
||||
.to all(satisfy { |status| !status.reblog? })
|
||||
end
|
||||
|
||||
context 'with tagged param' do
|
||||
let(:params) { { tagged: tag.name } }
|
||||
|
||||
it 'returns only statuses with tag' do
|
||||
expect(subject.all? { |s| s.tags.include?(tag) }).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'with exclude_replies param' do
|
||||
let(:params) { { exclude_replies: true } }
|
||||
|
||||
it 'returns only statuses that are not replies' do
|
||||
expect(subject.none?(&:reply?)).to be true
|
||||
end
|
||||
end
|
||||
|
||||
context 'with exclude_reblogs param' do
|
||||
let(:params) { { exclude_reblogs: true } }
|
||||
|
||||
it 'returns only statuses that are not reblogs' do
|
||||
expect(subject.none?(&:reblog?)).to be true
|
||||
end
|
||||
def results_for(params)
|
||||
described_class
|
||||
.new(account, current_account, params)
|
||||
.results
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -4,17 +4,20 @@ require 'rails_helper'
|
|||
|
||||
RSpec.describe AnnualReport::Percentiles do
|
||||
describe '#generate' do
|
||||
subject { described_class.new(account, Time.zone.now.year) }
|
||||
subject { described_class.new(account, year) }
|
||||
|
||||
let(:year) { Time.zone.now.year }
|
||||
|
||||
context 'with an inactive account' do
|
||||
let(:account) { Fabricate :account }
|
||||
|
||||
it 'builds a report for an account' do
|
||||
described_class.prepare(year)
|
||||
|
||||
expect(subject.generate)
|
||||
.to include(
|
||||
percentiles: include(
|
||||
followers: 0,
|
||||
statuses: 0
|
||||
statuses: 100
|
||||
)
|
||||
)
|
||||
end
|
||||
|
@ -25,16 +28,15 @@ RSpec.describe AnnualReport::Percentiles do
|
|||
|
||||
before do
|
||||
Fabricate.times 2, :status # Others as `account`
|
||||
Fabricate.times 2, :follow # Others as `target_account`
|
||||
Fabricate.times 2, :status, account: account
|
||||
Fabricate.times 2, :follow, target_account: account
|
||||
end
|
||||
|
||||
it 'builds a report for an account' do
|
||||
described_class.prepare(year)
|
||||
|
||||
expect(subject.generate)
|
||||
.to include(
|
||||
percentiles: include(
|
||||
followers: 50,
|
||||
statuses: 50
|
||||
)
|
||||
)
|
||||
|
|
|
@ -126,16 +126,54 @@ RSpec.describe FeaturedTag do
|
|||
end
|
||||
|
||||
describe '#decrement' do
|
||||
it 'decreases the count and updates the last_status_at timestamp' do
|
||||
tag = Fabricate :tag, name: 'test'
|
||||
status = Fabricate :status, visibility: :public, created_at: 10.days.ago
|
||||
status.tags << tag
|
||||
let(:tag) { Fabricate(:tag, name: 'test') }
|
||||
let(:account) { Fabricate(:account) }
|
||||
let(:featured_tag) { Fabricate(:featured_tag, name: 'test', account: account) }
|
||||
|
||||
featured_tag = Fabricate :featured_tag, name: 'test', account: status.account
|
||||
context 'when removing the last status using the tag' do
|
||||
let(:status) { Fabricate(:status, visibility: :public, account: account, created_at: 10.days.ago) }
|
||||
|
||||
expect { featured_tag.decrement(status.id) }
|
||||
.to change(featured_tag, :statuses_count).from(1).to(0)
|
||||
.and change(featured_tag, :last_status_at).to(nil)
|
||||
before do
|
||||
status.tags << tag
|
||||
end
|
||||
|
||||
it 'decreases the count and updates the last_status_at timestamp' do
|
||||
expect { featured_tag.decrement(status) }
|
||||
.to change(featured_tag, :statuses_count).from(1).to(0)
|
||||
.and change(featured_tag, :last_status_at).to(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when removing a previous status using the tag' do
|
||||
let(:previous_status) { Fabricate(:status, visibility: :public, account: account, created_at: 1.month.ago) }
|
||||
let(:status) { Fabricate(:status, visibility: :public, account: account, created_at: 10.days.ago) }
|
||||
|
||||
before do
|
||||
previous_status.tags << tag
|
||||
status.tags << tag
|
||||
end
|
||||
|
||||
it 'decreases the count and updates the last_status_at timestamp' do
|
||||
expect { featured_tag.decrement(previous_status) }
|
||||
.to change(featured_tag, :statuses_count).from(2).to(1)
|
||||
.and not_change(featured_tag, :last_status_at)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when removing the most recent use of the tag' do
|
||||
let(:previous_status) { Fabricate(:status, visibility: :public, account: account, created_at: 1.month.ago) }
|
||||
let(:status) { Fabricate(:status, visibility: :public, account: account, created_at: 10.days.ago) }
|
||||
|
||||
before do
|
||||
previous_status.tags << tag
|
||||
status.tags << tag
|
||||
end
|
||||
|
||||
it 'decreases the count and updates the last_status_at timestamp' do
|
||||
expect { featured_tag.decrement(status) }
|
||||
.to change(featured_tag, :statuses_count).from(2).to(1)
|
||||
.and change(featured_tag, :last_status_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue