diff options
author | ThibG <thib@sitedethib.com> | 2019-01-02 20:03:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-02 20:03:32 +0100 |
commit | 0acd51acdc1e670bf57f58671cb8e30743782c63 (patch) | |
tree | f5ff0b5c3b1e8fd94691264f2bc147e5fa233ecb /spec/validators/follow_limit_validator_spec.rb | |
parent | b300948526d967aaf5608c93546ee0d54940c0ef (diff) | |
parent | e77ceb1b29547ed89b4110b3cc3edc9ac325b620 (diff) |
Merge pull request #878 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'spec/validators/follow_limit_validator_spec.rb')
-rw-r--r-- | spec/validators/follow_limit_validator_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/validators/follow_limit_validator_spec.rb b/spec/validators/follow_limit_validator_spec.rb new file mode 100644 index 000000000..cc8fbb631 --- /dev/null +++ b/spec/validators/follow_limit_validator_spec.rb @@ -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 |