statuses_controller_spec.rb 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Admin::StatusesController do
  4. render_views
  5. let(:user) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) }
  6. let(:account) { Fabricate(:account) }
  7. let!(:status) { Fabricate(:status, account: account) }
  8. let(:media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
  9. let!(:media_attachment) { Fabricate(:media_attachment, account: account, status: media_attached_status) }
  10. let(:last_media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
  11. let!(:last_media_attachment) { Fabricate(:media_attachment, account: account, status: last_media_attached_status) }
  12. let!(:last_status) { Fabricate(:status, account: account) }
  13. let(:sensitive) { true }
  14. before do
  15. sign_in user, scope: :user
  16. end
  17. describe 'GET #index' do
  18. context 'with a valid account' do
  19. before do
  20. get :index, params: { account_id: account.id }
  21. end
  22. it 'returns http success' do
  23. expect(response).to have_http_status(200)
  24. end
  25. end
  26. context 'when filtering by media' do
  27. before do
  28. get :index, params: { account_id: account.id, media: '1' }
  29. end
  30. it 'returns http success' do
  31. expect(response).to have_http_status(200)
  32. end
  33. end
  34. end
  35. describe 'GET #show' do
  36. before do
  37. get :show, params: { account_id: account.id, id: status.id }
  38. end
  39. it 'returns http success' do
  40. expect(response).to have_http_status(200)
  41. end
  42. end
  43. describe 'POST #batch' do
  44. subject { post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } }
  45. let(:status_ids) { [media_attached_status.id] }
  46. shared_examples 'when action is report' do
  47. let(:action) { 'report' }
  48. it 'creates a report' do
  49. subject
  50. report = Report.last
  51. expect(report.target_account_id).to eq account.id
  52. expect(report.status_ids).to eq status_ids
  53. end
  54. it 'redirects to report page' do
  55. subject
  56. expect(response).to redirect_to(admin_report_path(Report.last.id))
  57. end
  58. end
  59. it_behaves_like 'when action is report'
  60. context 'when the moderator is blocked by the author' do
  61. before do
  62. account.block!(user.account)
  63. end
  64. it_behaves_like 'when action is report'
  65. end
  66. end
  67. end