statuses_search_spec.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Account::StatusesSearch do
  4. let(:account) { Fabricate(:account, indexable: indexable) }
  5. before do
  6. allow(Chewy).to receive(:enabled?).and_return(true)
  7. end
  8. describe '#enqueue_update_public_statuses_index' do
  9. before do
  10. allow(account).to receive(:enqueue_add_to_public_statuses_index)
  11. allow(account).to receive(:enqueue_remove_from_public_statuses_index)
  12. end
  13. context 'when account is indexable' do
  14. let(:indexable) { true }
  15. it 'enqueues add_to_public_statuses_index and not to remove_from_public_statuses_index' do
  16. account.enqueue_update_public_statuses_index
  17. expect(account).to have_received(:enqueue_add_to_public_statuses_index)
  18. expect(account).to_not have_received(:enqueue_remove_from_public_statuses_index)
  19. end
  20. end
  21. context 'when account is not indexable' do
  22. let(:indexable) { false }
  23. it 'enqueues remove_from_public_statuses_index and not to add_to_public_statuses_index' do
  24. account.enqueue_update_public_statuses_index
  25. expect(account).to have_received(:enqueue_remove_from_public_statuses_index)
  26. expect(account).to_not have_received(:enqueue_add_to_public_statuses_index)
  27. end
  28. end
  29. end
  30. describe '#enqueue_add_to_public_statuses_index' do
  31. let(:indexable) { true }
  32. let(:worker) { AddToPublicStatusesIndexWorker }
  33. before do
  34. allow(worker).to receive(:perform_async)
  35. end
  36. it 'enqueues AddToPublicStatusesIndexWorker' do
  37. account.enqueue_add_to_public_statuses_index
  38. expect(worker).to have_received(:perform_async).with(account.id)
  39. end
  40. end
  41. describe '#enqueue_remove_from_public_statuses_index' do
  42. let(:indexable) { false }
  43. let(:worker) { RemoveFromPublicStatusesIndexWorker }
  44. before do
  45. allow(worker).to receive(:perform_async)
  46. end
  47. it 'enqueues RemoveFromPublicStatusesIndexWorker' do
  48. account.enqueue_remove_from_public_statuses_index
  49. expect(worker).to have_received(:perform_async).with(account.id)
  50. end
  51. end
  52. end