mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-22 22:15:23 +01:00
Don't stub SUT in FollowLimitValidator
spec (#27760)
This commit is contained in:
parent
5c328ae674
commit
c03bd2a238
5 changed files with 62 additions and 34 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe BlacklistedEmailValidator, type: :validator do
|
RSpec.describe BlacklistedEmailValidator do
|
||||||
describe '#validate' do
|
describe '#validate' do
|
||||||
subject { described_class.new.validate(user); errors }
|
subject { described_class.new.validate(user); errors }
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe DisallowedHashtagsValidator, type: :validator do
|
RSpec.describe DisallowedHashtagsValidator do
|
||||||
let(:disallowed_tags) { [] }
|
let(:disallowed_tags) { [] }
|
||||||
|
|
||||||
describe '#validate' do
|
describe '#validate' do
|
||||||
|
|
|
@ -2,48 +2,76 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe FollowLimitValidator, type: :validator do
|
RSpec.describe FollowLimitValidator do
|
||||||
describe '#validate' do
|
describe '#validate' do
|
||||||
|
context 'with a nil account' do
|
||||||
|
it 'does not add validation errors to base' do
|
||||||
|
follow = Fabricate.build(:follow, account: nil)
|
||||||
|
|
||||||
|
follow.valid?
|
||||||
|
|
||||||
|
expect(follow.errors[:base]).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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'))
|
||||||
|
|
||||||
|
follow.valid?
|
||||||
|
|
||||||
|
expect(follow.errors[:base]).to be_empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a local account' do
|
||||||
|
let(:account) { Account.new }
|
||||||
|
|
||||||
|
context 'when the followers count is under the limit' do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(described_class).to receive(:limit_reached?).with(account) do
|
allow(account).to receive(:following_count).and_return(described_class::LIMIT - 100)
|
||||||
limit_reached
|
|
||||||
end
|
end
|
||||||
|
|
||||||
described_class.new.validate(follow)
|
it 'does not add validation errors to base' do
|
||||||
end
|
follow = Fabricate.build(:follow, account: account)
|
||||||
|
|
||||||
let(:follow) { instance_double(Follow, account: account, errors: errors) }
|
follow.valid?
|
||||||
let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
|
|
||||||
let(:account) { instance_double(Account, nil?: _nil, local?: local, following_count: 0, followers_count: 0) }
|
|
||||||
let(:_nil) { true }
|
|
||||||
let(:local) { false }
|
|
||||||
|
|
||||||
context 'with follow.account.nil? || !follow.account.local?' do
|
expect(follow.errors[:base]).to be_empty
|
||||||
let(:_nil) { true }
|
|
||||||
|
|
||||||
it 'not calls errors.add' do
|
|
||||||
expect(errors).to_not have_received(:add).with(:base, any_args)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with !(follow.account.nil? || !follow.account.local?)' do
|
context 'when the following count is over the limit' do
|
||||||
let(:_nil) { false }
|
before do
|
||||||
let(:local) { true }
|
allow(account).to receive(:following_count).and_return(described_class::LIMIT + 100)
|
||||||
|
end
|
||||||
|
|
||||||
context 'when limit_reached?' do
|
context 'when the followers count is low' do
|
||||||
let(:limit_reached) { true }
|
before do
|
||||||
|
allow(account).to receive(:followers_count).and_return(10)
|
||||||
|
end
|
||||||
|
|
||||||
it 'calls errors.add' do
|
it 'adds validation errors to base' do
|
||||||
expect(errors).to have_received(:add)
|
follow = Fabricate.build(:follow, account: account)
|
||||||
.with(:base, I18n.t('users.follow_limit_reached', limit: FollowLimitValidator::LIMIT))
|
|
||||||
|
follow.valid?
|
||||||
|
|
||||||
|
expect(follow.errors[:base]).to include(I18n.t('users.follow_limit_reached', limit: FollowLimitValidator::LIMIT))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with !limit_reached?' do
|
context 'when the followers count is high' do
|
||||||
let(:limit_reached) { false }
|
before do
|
||||||
|
allow(account).to receive(:followers_count).and_return(100_000)
|
||||||
|
end
|
||||||
|
|
||||||
it 'not calls errors.add' do
|
it 'does not add validation errors to base' do
|
||||||
expect(errors).to_not have_received(:add).with(:base, any_args)
|
follow = Fabricate.build(:follow, account: account)
|
||||||
|
|
||||||
|
follow.valid?
|
||||||
|
|
||||||
|
expect(follow.errors[:base]).to be_empty
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe PollValidator, type: :validator do
|
RSpec.describe PollValidator do
|
||||||
describe '#validate' do
|
describe '#validate' do
|
||||||
before do
|
before do
|
||||||
validator.validate(poll)
|
validator.validate(poll)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe StatusPinValidator, type: :validator do
|
RSpec.describe StatusPinValidator do
|
||||||
describe '#validate' do
|
describe '#validate' do
|
||||||
before do
|
before do
|
||||||
subject.validate(pin)
|
subject.validate(pin)
|
||||||
|
|
Loading…
Reference in a new issue