status_batch_spec.rb 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. require 'rails_helper'
  2. describe Form::StatusBatch do
  3. let(:form) { Form::StatusBatch.new(action: action, status_ids: status_ids) }
  4. let(:status) { Fabricate(:status) }
  5. describe 'with nsfw action' do
  6. let(:status_ids) { [status.id, nonsensitive_status.id, sensitive_status.id] }
  7. let(:nonsensitive_status) { Fabricate(:status, sensitive: false) }
  8. let(:sensitive_status) { Fabricate(:status, sensitive: true) }
  9. let!(:shown_media_attachment) { Fabricate(:media_attachment, status: nonsensitive_status) }
  10. let!(:hidden_media_attachment) { Fabricate(:media_attachment, status: sensitive_status) }
  11. context 'nsfw_on' do
  12. let(:action) { 'nsfw_on' }
  13. it { expect(form.save).to be true }
  14. it { expect { form.save }.to change { nonsensitive_status.reload.sensitive }.from(false).to(true) }
  15. it { expect { form.save }.not_to change { sensitive_status.reload.sensitive } }
  16. it { expect { form.save }.not_to change { status.reload.sensitive } }
  17. end
  18. context 'nsfw_off' do
  19. let(:action) { 'nsfw_off' }
  20. it { expect(form.save).to be true }
  21. it { expect { form.save }.to change { sensitive_status.reload.sensitive }.from(true).to(false) }
  22. it { expect { form.save }.not_to change { nonsensitive_status.reload.sensitive } }
  23. it { expect { form.save }.not_to change { status.reload.sensitive } }
  24. end
  25. end
  26. describe 'with delete action' do
  27. let(:status_ids) { [status.id] }
  28. let(:action) { 'delete' }
  29. let!(:another_status) { Fabricate(:status) }
  30. before do
  31. allow(RemovalWorker).to receive(:perform_async)
  32. end
  33. it 'call RemovalWorker' do
  34. form.save
  35. expect(RemovalWorker).to have_received(:perform_async).with(status.id, immediate: true)
  36. end
  37. it 'do not call RemovalWorker' do
  38. form.save
  39. expect(RemovalWorker).not_to have_received(:perform_async).with(another_status.id, immediate: true)
  40. end
  41. end
  42. end