actions_controller_spec.rb 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. require 'rails_helper'
  2. describe Admin::Reports::ActionsController do
  3. render_views
  4. let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  5. before do
  6. sign_in user, scope: :user
  7. end
  8. describe 'POST #preview' do
  9. let(:report) { Fabricate(:report) }
  10. before do
  11. post :preview, params: { report_id: report.id, action => '' }
  12. end
  13. context 'when the action is "suspend"' do
  14. let(:action) { 'suspend' }
  15. it 'returns http success' do
  16. expect(response).to have_http_status(200)
  17. end
  18. end
  19. context 'when the action is "silence"' do
  20. let(:action) { 'silence' }
  21. it 'returns http success' do
  22. expect(response).to have_http_status(200)
  23. end
  24. end
  25. context 'when the action is "delete"' do
  26. let(:action) { 'delete' }
  27. it 'returns http success' do
  28. expect(response).to have_http_status(200)
  29. end
  30. end
  31. context 'when the action is "mark_as_sensitive"' do
  32. let(:action) { 'mark_as_sensitive' }
  33. it 'returns http success' do
  34. expect(response).to have_http_status(200)
  35. end
  36. end
  37. end
  38. describe 'POST #create' do
  39. let(:target_account) { Fabricate(:account) }
  40. let(:statuses) { [Fabricate(:status, account: target_account), Fabricate(:status, account: target_account)] }
  41. let!(:media) { Fabricate(:media_attachment, account: target_account, status: statuses[0]) }
  42. let(:report) { Fabricate(:report, target_account: target_account, status_ids: statuses.map(&:id)) }
  43. let(:text) { 'hello' }
  44. shared_examples 'common behavior' do
  45. it 'closes the report' do
  46. expect { subject }.to change { report.reload.action_taken? }.from(false).to(true)
  47. end
  48. it 'creates a strike with the expected text' do
  49. expect { subject }.to change { report.target_account.strikes.count }.by(1)
  50. expect(report.target_account.strikes.last.text).to eq text
  51. end
  52. it 'redirects' do
  53. subject
  54. expect(response).to redirect_to(admin_reports_path)
  55. end
  56. end
  57. shared_examples 'all action types' do
  58. context 'when the action is "suspend"' do
  59. let(:action) { 'suspend' }
  60. it_behaves_like 'common behavior'
  61. it 'suspends the target account' do
  62. expect { subject }.to change { report.target_account.reload.suspended? }.from(false).to(true)
  63. end
  64. end
  65. context 'when the action is "silence"' do
  66. let(:action) { 'silence' }
  67. it_behaves_like 'common behavior'
  68. it 'suspends the target account' do
  69. expect { subject }.to change { report.target_account.reload.silenced? }.from(false).to(true)
  70. end
  71. end
  72. context 'when the action is "delete"' do
  73. let(:action) { 'delete' }
  74. it_behaves_like 'common behavior'
  75. end
  76. context 'when the action is "mark_as_sensitive"' do
  77. let(:action) { 'mark_as_sensitive' }
  78. let(:statuses) { [media_attached_status, media_attached_deleted_status] }
  79. let!(:status) { Fabricate(:status, account: target_account) }
  80. let(:media_attached_status) { Fabricate(:status, account: target_account) }
  81. let!(:media_attachment) { Fabricate(:media_attachment, account: target_account, status: media_attached_status) }
  82. let(:media_attached_deleted_status) { Fabricate(:status, account: target_account, deleted_at: 1.day.ago) }
  83. let!(:media_attachment2) { Fabricate(:media_attachment, account: target_account, status: media_attached_deleted_status) }
  84. let(:last_media_attached_status) { Fabricate(:status, account: target_account) }
  85. let!(:last_media_attachment) { Fabricate(:media_attachment, account: target_account, status: last_media_attached_status) }
  86. let!(:last_status) { Fabricate(:status, account: target_account) }
  87. it_behaves_like 'common behavior'
  88. it 'marks the non-deleted as sensitive' do
  89. subject
  90. expect(media_attached_status.reload.sensitive).to eq true
  91. end
  92. end
  93. end
  94. context 'action as submit button' do
  95. subject { post :create, params: { report_id: report.id, text: text, action => '' } }
  96. it_behaves_like 'all action types'
  97. end
  98. context 'action as submit button' do
  99. subject { post :create, params: { report_id: report.id, text: text, moderation_action: action } }
  100. it_behaves_like 'all action types'
  101. end
  102. end
  103. end