mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-25 23:13:33 +00:00
Add specs for FollowLimitValidator (#9655)
This commit is contained in:
parent
05edec6917
commit
fb08039de5
51
spec/validators/follow_limit_validator_spec.rb
Normal file
51
spec/validators/follow_limit_validator_spec.rb
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
# 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 }
|
||||||
|
|
||||||
|
context 'follow.account.nil? || !follow.account.local?' do
|
||||||
|
let(:_nil) { true }
|
||||||
|
|
||||||
|
it 'not calls errors.add' do
|
||||||
|
expect(errors).not_to have_received(:add).with(:base, any_args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context '!(follow.account.nil? || !follow.account.local?)' do
|
||||||
|
let(:_nil) { false }
|
||||||
|
let(:local) { true }
|
||||||
|
|
||||||
|
context 'limit_reached?' do
|
||||||
|
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
|
||||||
|
|
||||||
|
context '!limit_reached?' do
|
||||||
|
let(:limit_reached) { false }
|
||||||
|
|
||||||
|
it 'not calls errors.add' do
|
||||||
|
expect(errors).not_to have_received(:add).with(:base, any_args)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue