2018-12-29 07:24:52 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
RSpec.describe FollowLimitValidator do
|
2018-12-29 07:24:52 +00:00
|
|
|
describe '#validate' do
|
2023-11-08 12:49:46 +00:00
|
|
|
context 'with a nil account' do
|
|
|
|
it 'does not add validation errors to base' do
|
|
|
|
follow = Fabricate.build(:follow, account: nil)
|
|
|
|
|
|
|
|
follow.valid?
|
2018-12-29 07:24:52 +00:00
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
expect(follow.errors[:base]).to be_empty
|
|
|
|
end
|
2018-12-29 07:24:52 +00:00
|
|
|
end
|
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
context 'with a non-local account' do
|
|
|
|
it 'does not add validation errors to base' do
|
|
|
|
follow = Fabricate.build(:follow, account: Account.new(domain: 'host.example'))
|
2018-12-29 07:24:52 +00:00
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
follow.valid?
|
2018-12-29 07:24:52 +00:00
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
expect(follow.errors[:base]).to be_empty
|
2018-12-29 07:24:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
context 'with a local account' do
|
|
|
|
let(:account) { Account.new }
|
|
|
|
|
|
|
|
context 'when the followers count is under the limit' do
|
|
|
|
before do
|
|
|
|
allow(account).to receive(:following_count).and_return(described_class::LIMIT - 100)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not add validation errors to base' do
|
|
|
|
follow = Fabricate.build(:follow, account: account)
|
2018-12-29 07:24:52 +00:00
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
follow.valid?
|
2018-12-29 07:24:52 +00:00
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
expect(follow.errors[:base]).to be_empty
|
2018-12-29 07:24:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
context 'when the following count is over the limit' do
|
|
|
|
before do
|
|
|
|
allow(account).to receive(:following_count).and_return(described_class::LIMIT + 100)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the followers count is low' do
|
|
|
|
before do
|
|
|
|
allow(account).to receive(:followers_count).and_return(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'adds validation errors to base' do
|
|
|
|
follow = Fabricate.build(:follow, account: account)
|
|
|
|
|
|
|
|
follow.valid?
|
|
|
|
|
|
|
|
expect(follow.errors[:base]).to include(I18n.t('users.follow_limit_reached', limit: FollowLimitValidator::LIMIT))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the followers count is high' do
|
|
|
|
before do
|
|
|
|
allow(account).to receive(:followers_count).and_return(100_000)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not add validation errors to base' do
|
|
|
|
follow = Fabricate.build(:follow, account: account)
|
|
|
|
|
|
|
|
follow.valid?
|
2018-12-29 07:24:52 +00:00
|
|
|
|
2023-11-08 12:49:46 +00:00
|
|
|
expect(follow.errors[:base]).to be_empty
|
|
|
|
end
|
2018-12-29 07:24:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|