status_pin_validator_spec.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe StatusPinValidator do
  4. describe '#validate' do
  5. before do
  6. subject.validate(pin)
  7. end
  8. let(:pin) { instance_double(StatusPin, account: account, errors: errors, status: status, account_id: pin_account_id) }
  9. let(:status) { instance_double(Status, reblog?: reblog, account_id: status_account_id, visibility: visibility, direct_visibility?: visibility == 'direct') }
  10. let(:account) { instance_double(Account, status_pins: status_pins, local?: local) }
  11. let(:status_pins) { instance_double(Array, count: count) }
  12. let(:errors) { instance_double(ActiveModel::Errors, add: nil) }
  13. let(:pin_account_id) { 1 }
  14. let(:status_account_id) { 1 }
  15. let(:visibility) { 'public' }
  16. let(:local) { false }
  17. let(:reblog) { false }
  18. let(:count) { 0 }
  19. context 'when pin.status.reblog?' do
  20. let(:reblog) { true }
  21. it 'calls errors.add' do
  22. expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.reblog'))
  23. end
  24. end
  25. context 'when pin.account_id != pin.status.account_id' do
  26. let(:pin_account_id) { 1 }
  27. let(:status_account_id) { 2 }
  28. it 'calls errors.add' do
  29. expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.ownership'))
  30. end
  31. end
  32. context 'when pin.status.direct_visibility?' do
  33. let(:visibility) { 'direct' }
  34. it 'calls errors.add' do
  35. expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.direct'))
  36. end
  37. end
  38. context 'when pin account is local and has too many pins' do
  39. let(:count) { described_class::PIN_LIMIT + 1 }
  40. let(:local) { true }
  41. it 'calls errors.add' do
  42. expect(errors).to have_received(:add).with(:base, I18n.t('statuses.pin_errors.limit'))
  43. end
  44. end
  45. end
  46. end