2018-12-28 18:09:32 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-11-08 21:49:46 +09:00
|
|
|
RSpec.describe StatusPinValidator do
|
2018-12-28 18:09:32 +09:00
|
|
|
describe '#validate' do
|
|
|
|
before do
|
|
|
|
subject.validate(pin)
|
|
|
|
end
|
|
|
|
|
2023-06-22 21:55:22 +09:00
|
|
|
let(:pin) { instance_double(StatusPin, account: account, errors: errors, status: status, account_id: pin_account_id) }
|
|
|
|
let(:status) { instance_double(Status, reblog?: reblog, account_id: status_account_id, visibility: visibility, direct_visibility?: visibility == 'direct') }
|
|
|
|
let(:account) { instance_double(Account, status_pins: status_pins, local?: local) }
|
|
|
|
let(:status_pins) { instance_double(Array, count: count) }
|
|
|
|
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
2018-12-28 18:09:32 +09:00
|
|
|
let(:pin_account_id) { 1 }
|
|
|
|
let(:status_account_id) { 1 }
|
|
|
|
let(:visibility) { 'public' }
|
|
|
|
let(:local) { false }
|
|
|
|
let(:reblog) { false }
|
|
|
|
let(:count) { 0 }
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
context 'when pin.status.reblog?' do
|
2018-12-28 18:09:32 +09:00
|
|
|
let(:reblog) { true }
|
|
|
|
|
|
|
|
it 'calls errors.add' do
|
|
|
|
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.reblog'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
context 'when pin.account_id != pin.status.account_id' do
|
2018-12-28 18:09:32 +09:00
|
|
|
let(:pin_account_id) { 1 }
|
|
|
|
let(:status_account_id) { 2 }
|
|
|
|
|
|
|
|
it 'calls errors.add' do
|
|
|
|
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.ownership'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
context 'when pin.status.direct_visibility?' do
|
2022-01-17 08:49:55 +09:00
|
|
|
let(:visibility) { 'direct' }
|
2018-12-28 18:09:32 +09:00
|
|
|
|
|
|
|
it 'calls errors.add' do
|
2022-01-17 08:49:55 +09:00
|
|
|
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.direct'))
|
2018-12-28 18:09:32 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-04 12:49:08 +09:00
|
|
|
context 'when pin.account.status_pins.count > 4 && pin.account.local?' do
|
2018-12-28 18:09:32 +09:00
|
|
|
let(:count) { 5 }
|
|
|
|
let(:local) { true }
|
|
|
|
|
|
|
|
it 'calls errors.add' do
|
|
|
|
expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.limit'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|