logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

reported_statuses_controller_spec.rb (2479B)


  1. require 'rails_helper'
  2. describe Admin::ReportedStatusesController do
  3. render_views
  4. let(:user) { Fabricate(:user, admin: true) }
  5. let(:report) { Fabricate(:report, status_ids: [status.id]) }
  6. let(:status) { Fabricate(:status) }
  7. before do
  8. sign_in user, scope: :user
  9. end
  10. describe 'POST #create' do
  11. subject do
  12. -> { post :create, params: { report_id: report, form_status_batch: { action: action, status_ids: status_ids } } }
  13. end
  14. let(:action) { 'nsfw_on' }
  15. let(:status_ids) { [status.id] }
  16. let(:status) { Fabricate(:status, sensitive: !sensitive) }
  17. let(:sensitive) { true }
  18. let!(:media_attachment) { Fabricate(:media_attachment, status: status) }
  19. context 'updates sensitive column to true' do
  20. it 'updates sensitive column' do
  21. is_expected.to change {
  22. status.reload.sensitive
  23. }.from(false).to(true)
  24. end
  25. end
  26. context 'updates sensitive column to false' do
  27. let(:action) { 'nsfw_off' }
  28. let(:sensitive) { false }
  29. it 'updates sensitive column' do
  30. is_expected.to change {
  31. status.reload.sensitive
  32. }.from(true).to(false)
  33. end
  34. end
  35. it 'redirects to report page' do
  36. subject.call
  37. expect(response).to redirect_to(admin_report_path(report))
  38. end
  39. end
  40. describe 'PATCH #update' do
  41. subject do
  42. -> { patch :update, params: { report_id: report, id: status, status: { sensitive: sensitive } } }
  43. end
  44. let(:status) { Fabricate(:status, sensitive: !sensitive) }
  45. let(:sensitive) { true }
  46. context 'updates sensitive column to true' do
  47. it 'updates sensitive column' do
  48. is_expected.to change {
  49. status.reload.sensitive
  50. }.from(false).to(true)
  51. end
  52. end
  53. context 'updates sensitive column to false' do
  54. let(:sensitive) { false }
  55. it 'updates sensitive column' do
  56. is_expected.to change {
  57. status.reload.sensitive
  58. }.from(true).to(false)
  59. end
  60. end
  61. it 'redirects to report page' do
  62. subject.call
  63. expect(response).to redirect_to(admin_report_path(report))
  64. end
  65. end
  66. describe 'DELETE #destroy' do
  67. it 'removes a status' do
  68. allow(RemovalWorker).to receive(:perform_async)
  69. delete :destroy, params: { report_id: report, id: status }
  70. expect(response).to have_http_status(:success)
  71. expect(RemovalWorker).
  72. to have_received(:perform_async).with(status.id)
  73. end
  74. end
  75. end