2018-12-29 02:24:52 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe FollowLimitValidator, type: :validator do
|
|
|
|
describe '#validate' do
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:limit_reached?).with(account) do
|
|
|
|
limit_reached
|
|
|
|
end
|
|
|
|
|
|
|
|
described_class.new.validate(follow)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:follow) { double(account: account, errors: errors) }
|
|
|
|
let(:errors) { double(add: nil) }
|
|
|
|
let(:account) { double(nil?: _nil, local?: local, following_count: 0, followers_count: 0) }
|
|
|
|
let(:_nil) { true }
|
|
|
|
let(:local) { false }
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with follow.account.nil? || !follow.account.local?' do
|
2018-12-29 02:24:52 -05:00
|
|
|
let(:_nil) { true }
|
|
|
|
|
|
|
|
it 'not calls errors.add' do
|
2023-02-19 20:33:27 -05:00
|
|
|
expect(errors).to_not have_received(:add).with(:base, any_args)
|
2018-12-29 02:24:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with !(follow.account.nil? || !follow.account.local?)' do
|
2018-12-29 02:24:52 -05:00
|
|
|
let(:_nil) { false }
|
|
|
|
let(:local) { true }
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'when limit_reached?' do
|
2018-12-29 02:24:52 -05:00
|
|
|
let(:limit_reached) { true }
|
|
|
|
|
|
|
|
it 'calls errors.add' do
|
|
|
|
expect(errors).to have_received(:add)
|
|
|
|
.with(:base, I18n.t('users.follow_limit_reached', limit: FollowLimitValidator::LIMIT))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-03 23:49:08 -04:00
|
|
|
context 'with !limit_reached?' do
|
2018-12-29 02:24:52 -05:00
|
|
|
let(:limit_reached) { false }
|
|
|
|
|
|
|
|
it 'not calls errors.add' do
|
2023-02-19 20:33:27 -05:00
|
|
|
expect(errors).to_not have_received(:add).with(:base, any_args)
|
2018-12-29 02:24:52 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|