status_pin_validator_spec.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe StatusPinValidator, type: :validator do
  4. describe '#validate' do
  5. before do
  6. subject.validate(pin)
  7. end
  8. let(:pin) { double(account: account, errors: errors, status: status, account_id: pin_account_id) }
  9. let(:status) { double(reblog?: reblog, account_id: status_account_id, visibility: visibility, direct_visibility?: visibility == 'direct') }
  10. let(:account) { double(status_pins: status_pins, local?: local) }
  11. let(:status_pins) { double(count: count) }
  12. let(:errors) { double(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 '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 '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 'if 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 'pin.account.status_pins.count > 4 && pin.account.local?' do
  39. let(:count) { 5 }
  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