2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-24 23:41:18 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-05-04 03:49:53 +00:00
|
|
|
RSpec.describe StatusPin do
|
2024-10-28 07:34:58 +00:00
|
|
|
describe 'Validations' do
|
|
|
|
subject { Fabricate.build :status_pin }
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with an account pinning statuses' do
|
|
|
|
subject { Fabricate.build :status_pin, account: account }
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
let(:account) { Fabricate(:account) }
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with a self-owned status' do
|
|
|
|
let(:status) { Fabricate(:status, account: account) }
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
it { is_expected.to allow_value(status).for(:status) }
|
|
|
|
end
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with a status from someone else' do
|
|
|
|
let(:status) { Fabricate(:status) }
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
it { is_expected.to_not allow_value(status).for(:status).against(:base) }
|
|
|
|
end
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with a reblog status' do
|
|
|
|
let(:status) { Fabricate(:status, reblog: Fabricate(:status, account: account)) }
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
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) }
|
2017-08-24 23:41:18 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
it { is_expected.to_not allow_value(status).for(:status).against(:base) }
|
|
|
|
end
|
2017-08-24 23:41:18 +00:00
|
|
|
end
|
2018-04-12 18:36:02 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with a validator pin limit' do
|
2023-11-20 09:07:25 +00:00
|
|
|
before { stub_const('StatusPinValidator::PIN_LIMIT', 2) }
|
2018-04-12 18:36:02 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with a local account at the limit' do
|
|
|
|
let(:account) { Fabricate :account }
|
2023-11-20 09:07:25 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
before { Fabricate.times(StatusPinValidator::PIN_LIMIT, :status_pin, account: account) }
|
2023-11-20 09:07:25 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
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) }
|
2018-04-12 18:36:02 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
it { is_expected.to allow_value(account).for(:account) }
|
2018-04-12 18:36:02 +00:00
|
|
|
end
|
2024-10-28 07:34:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'Callbacks' do
|
|
|
|
describe 'Invalidating status via policy' do
|
|
|
|
subject { Fabricate :status_pin, status: Fabricate(:status, account: account), account: account }
|
2018-04-12 18:36:02 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with a local account that owns the status and has a policy' do
|
|
|
|
let(:account) { Fabricate :account, domain: nil }
|
2018-04-12 18:36:02 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
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
|
2018-04-12 18:36:02 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
context 'with a remote account' do
|
|
|
|
let(:account) { Fabricate :account, domain: 'host.example' }
|
2018-04-12 18:36:02 +00:00
|
|
|
|
2024-10-28 07:34:58 +00:00
|
|
|
it 'does not call the invalidator on destroy' do
|
|
|
|
expect { subject.destroy }
|
|
|
|
.to_not change(account, :updated_at)
|
|
|
|
end
|
2018-04-12 18:36:02 +00:00
|
|
|
end
|
|
|
|
end
|
2017-08-24 23:41:18 +00:00
|
|
|
end
|
|
|
|
end
|