follow_limit_validator_spec.rb 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FollowLimitValidator, type: :validator do
  4. describe '#validate' do
  5. before do
  6. allow_any_instance_of(described_class).to receive(:limit_reached?).with(account) do
  7. limit_reached
  8. end
  9. described_class.new.validate(follow)
  10. end
  11. let(:follow) { double(account: account, errors: errors) }
  12. let(:errors) { double(add: nil) }
  13. let(:account) { double(nil?: _nil, local?: local, following_count: 0, followers_count: 0) }
  14. let(:_nil) { true }
  15. let(:local) { false }
  16. context 'follow.account.nil? || !follow.account.local?' do
  17. let(:_nil) { true }
  18. it 'not calls errors.add' do
  19. expect(errors).not_to have_received(:add).with(:base, any_args)
  20. end
  21. end
  22. context '!(follow.account.nil? || !follow.account.local?)' do
  23. let(:_nil) { false }
  24. let(:local) { true }
  25. context 'limit_reached?' do
  26. let(:limit_reached) { true }
  27. it 'calls errors.add' do
  28. expect(errors).to have_received(:add)
  29. .with(:base, I18n.t('users.follow_limit_reached', limit: FollowLimitValidator::LIMIT))
  30. end
  31. end
  32. context '!limit_reached?' do
  33. let(:limit_reached) { false }
  34. it 'not calls errors.add' do
  35. expect(errors).not_to have_received(:add).with(:base, any_args)
  36. end
  37. end
  38. end
  39. end
  40. end