~cytrogen/masto-fe

ref: 685270f3f7ea6d4a8a48ec641e8fdfd9fc2e2d7f masto-fe/spec/validators/follow_limit_validator_spec.rb -rw-r--r-- 1.5 KiB
685270f3 — Claire [Glitch] Fix clicking “Explore” or “Live feeds” column headers to scroll in advanced mode 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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)  { instance_double(Follow, account: account, errors: errors) }
    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
      let(:_nil)    { true }

      it 'not calls errors.add' do
        expect(errors).to_not have_received(:add).with(:base, any_args)
      end
    end

    context 'with !(follow.account.nil? || !follow.account.local?)' do
      let(:_nil)    { false }
      let(:local)   { true }

      context 'when 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 'with !limit_reached?' do
        let(:limit_reached) { false }

        it 'not calls errors.add' do
          expect(errors).to_not have_received(:add).with(:base, any_args)
        end
      end
    end
  end
end