1
0

follow_limit_validator_spec.rb 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe FollowLimitValidator do
  4. describe '#validate' do
  5. context 'with a nil account' do
  6. it 'does not add validation errors to base' do
  7. follow = Fabricate.build(:follow, account: nil)
  8. follow.valid?
  9. expect(follow.errors[:base]).to be_empty
  10. end
  11. end
  12. context 'with a non-local account' do
  13. it 'does not add validation errors to base' do
  14. follow = Fabricate.build(:follow, account: Account.new(domain: 'host.example'))
  15. follow.valid?
  16. expect(follow.errors[:base]).to be_empty
  17. end
  18. end
  19. context 'with a local account' do
  20. let(:account) { Account.new }
  21. context 'when the followers count is under the limit' do
  22. before do
  23. allow(account).to receive(:following_count).and_return(described_class::LIMIT - 100)
  24. end
  25. it 'does not add validation errors to base' do
  26. follow = Fabricate.build(:follow, account: account)
  27. follow.valid?
  28. expect(follow.errors[:base]).to be_empty
  29. end
  30. end
  31. context 'when the following count is over the limit' do
  32. before do
  33. allow(account).to receive(:following_count).and_return(described_class::LIMIT + 100)
  34. end
  35. context 'when the followers count is low' do
  36. before do
  37. allow(account).to receive(:followers_count).and_return(10)
  38. end
  39. it 'adds validation errors to base' do
  40. follow = Fabricate.build(:follow, account: account)
  41. follow.valid?
  42. expect(follow.errors[:base]).to include(I18n.t('users.follow_limit_reached', limit: described_class::LIMIT))
  43. end
  44. end
  45. context 'when the followers count is high' do
  46. before do
  47. allow(account).to receive(:followers_count).and_return(100_000)
  48. end
  49. it 'does not add validation errors to base' do
  50. follow = Fabricate.build(:follow, account: account)
  51. follow.valid?
  52. expect(follow.errors[:base]).to be_empty
  53. end
  54. end
  55. end
  56. end
  57. end
  58. end