1
0
Fork 0
forked from gitea/nas

Merge remote-tracking branch 'parent/main' into upstream-20241101

This commit is contained in:
KMY 2024-11-01 08:04:03 +09:00
commit 1c1f76697b
200 changed files with 1931 additions and 741 deletions

View file

@ -0,0 +1,22 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe PreviewCardTrend do
describe 'Associations' do
it { is_expected.to belong_to(:preview_card).required }
end
describe '.locales' do
before do
Fabricate :preview_card_trend, language: 'en'
Fabricate :preview_card_trend, language: 'en'
Fabricate :preview_card_trend, language: 'es'
end
it 'returns unique set of languages' do
expect(described_class.locales)
.to eq(['en', 'es'])
end
end
end

View file

@ -3,70 +3,100 @@
require 'rails_helper'
RSpec.describe StatusPin do
describe 'validations' do
it 'allows pins of own statuses' do
account = Fabricate(:account)
status = Fabricate(:status, account: account)
describe 'Validations' do
subject { Fabricate.build :status_pin }
expect(described_class.new(account: account, status: status).save).to be true
end
context 'with an account pinning statuses' do
subject { Fabricate.build :status_pin, account: account }
it 'does not allow pins of statuses by someone else' do
account = Fabricate(:account)
status = Fabricate(:status)
let(:account) { Fabricate(:account) }
expect(described_class.new(account: account, status: status).save).to be false
end
context 'with a self-owned status' do
let(:status) { Fabricate(:status, account: account) }
it 'does not allow pins of reblogs' do
account = Fabricate(:account)
status = Fabricate(:status, account: account)
reblog = Fabricate(:status, reblog: status)
expect(described_class.new(account: account, status: reblog).save).to be false
end
it 'does allow pins of direct statuses' do
account = Fabricate(:account)
status = Fabricate(:status, account: account, visibility: :private)
expect(described_class.new(account: account, status: status).save).to be true
end
it 'does not allow pins of direct statuses' do
account = Fabricate(:account)
status = Fabricate(:status, account: account, visibility: :direct)
expect(described_class.new(account: account, status: status).save).to be false
end
context 'with a pin limit' do
before { stub_const('StatusPinValidator::PIN_LIMIT', 2) }
it 'does not allow pins above the max' do
account = Fabricate(:account)
Fabricate.times(StatusPinValidator::PIN_LIMIT, :status_pin, account: account)
pin = described_class.new(account: account, status: Fabricate(:status, account: account))
expect(pin.save)
.to be(false)
expect(pin.errors[:base])
.to contain_exactly(I18n.t('statuses.pin_errors.limit'))
it { is_expected.to allow_value(status).for(:status) }
end
it 'allows pins above the max for remote accounts' do
account = Fabricate(:account, domain: 'remote.test', username: 'bob', url: 'https://remote.test/')
context 'with a status from someone else' do
let(:status) { Fabricate(:status) }
Fabricate.times(StatusPinValidator::PIN_LIMIT, :status_pin, account: account)
it { is_expected.to_not allow_value(status).for(:status).against(:base) }
end
pin = described_class.new(account: account, status: Fabricate(:status, account: account))
expect(pin.save)
.to be(true)
context 'with a reblog status' do
let(:status) { Fabricate(:status, reblog: Fabricate(:status, account: account)) }
expect(pin.errors[:base])
.to be_empty
it { is_expected.to_not allow_value(status).for(:status).against(:base) }
end
context 'with a private status' do
let(:status) { Fabricate(:status, account: account, visibility: :private) }
it { is_expected.to allow_value(status).for(:status).against(:base) }
end
context 'with a direct status' do
let(:status) { Fabricate(:status, account: account, visibility: :direct) }
it { is_expected.to_not allow_value(status).for(:status).against(:base) }
end
end
context 'with a validator pin limit' do
before { stub_const('StatusPinValidator::PIN_LIMIT', 2) }
context 'with a local account at the limit' do
let(:account) { Fabricate :account }
before { Fabricate.times(StatusPinValidator::PIN_LIMIT, :status_pin, account: account) }
it { is_expected.to_not allow_value(account).for(:account).against(:base).with_message(I18n.t('statuses.pin_errors.limit')) }
end
context 'with a remote account at the limit' do
let(:account) { Fabricate :account, domain: 'remote.test' }
before { Fabricate.times(StatusPinValidator::PIN_LIMIT, :status_pin, account: account) }
it { is_expected.to allow_value(account).for(:account) }
end
end
end
describe 'Callbacks' do
describe 'Invalidating status via policy' do
subject { Fabricate :status_pin, status: Fabricate(:status, account: account), account: account }
context 'with a local account that owns the status and has a policy' do
let(:account) { Fabricate :account, domain: nil }
before do
Fabricate :account_statuses_cleanup_policy, account: account
account.statuses_cleanup_policy.record_last_inspected(subject.status.id + 1_024)
end
it 'calls the invalidator on destroy' do
expect { subject.destroy }
.to change(account.statuses_cleanup_policy, :last_inspected)
end
end
context 'with a local account that owns the status and does not have a policy' do
let(:account) { Fabricate :account, domain: nil }
it 'does not call the invalidator on destroy' do
expect { subject.destroy }
.to_not change(account, :updated_at)
end
end
context 'with a remote account' do
let(:account) { Fabricate :account, domain: 'host.example' }
it 'does not call the invalidator on destroy' do
expect { subject.destroy }
.to_not change(account, :updated_at)
end
end
end
end

View file

@ -339,6 +339,31 @@ RSpec.describe Status do
end
end
describe '#untrusted_reblogs_count' do
before do
alice.update(domain: 'example.com')
subject.status_stat.tap do |status_stat|
status_stat.untrusted_reblogs_count = 0
status_stat.save
end
subject.save
end
it 'is incremented by the number of reblogs' do
Fabricate(:status, account: bob, reblog: subject)
Fabricate(:status, account: alice, reblog: subject)
expect(subject.untrusted_reblogs_count).to eq 2
end
it 'is decremented when reblog is removed' do
reblog = Fabricate(:status, account: bob, reblog: subject)
expect(subject.untrusted_reblogs_count).to eq 1
reblog.destroy
expect(subject.untrusted_reblogs_count).to eq 0
end
end
describe '#replies_count' do
it 'is the number of replies' do
Fabricate(:status, account: bob, thread: subject)
@ -369,6 +394,31 @@ RSpec.describe Status do
end
end
describe '#untrusted_favourites_count' do
before do
alice.update(domain: 'example.com')
subject.status_stat.tap do |status_stat|
status_stat.untrusted_favourites_count = 0
status_stat.save
end
subject.save
end
it 'is incremented by favorites' do
Fabricate(:favourite, account: bob, status: subject)
Fabricate(:favourite, account: alice, status: subject)
expect(subject.untrusted_favourites_count).to eq 2
end
it 'is decremented when favourite is removed' do
favourite = Fabricate(:favourite, account: bob, status: subject)
expect(subject.untrusted_favourites_count).to eq 1
favourite.destroy
expect(subject.untrusted_favourites_count).to eq 0
end
end
describe '#proper' do
it 'is itself for original statuses' do
expect(subject.proper).to eq subject

View file

@ -0,0 +1,23 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe StatusTrend do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
it { is_expected.to belong_to(:status).required }
end
describe '.locales' do
before do
Fabricate :status_trend, language: 'en'
Fabricate :status_trend, language: 'en'
Fabricate :status_trend, language: 'es'
end
it 'returns unique set of languages' do
expect(described_class.locales)
.to eq(['en', 'es'])
end
end
end

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe Tombstone do
describe 'Associations' do
it { is_expected.to belong_to(:account).required }
end
describe 'Validations' do
subject { Fabricate.build :tombstone }
it { is_expected.to validate_presence_of(:uri) }
end
end