statuses_controller_spec.rb 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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(:last_media_attached_status) { Fabricate(:status, account: account, sensitive: !sensitive) }
  10. let(:sensitive) { true }
  11. before do
  12. _last_media_attachment = Fabricate(:media_attachment, account: account, status: last_media_attached_status)
  13. _last_status = Fabricate(:status, account: account)
  14. _media_attachment = Fabricate(:media_attachment, account: account, status: media_attached_status)
  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 and redirects to report page' do
  49. subject
  50. expect(Report.last)
  51. .to have_attributes(
  52. target_account_id: eq(account.id),
  53. status_ids: eq(status_ids)
  54. )
  55. expect(response).to redirect_to(admin_report_path(Report.last.id))
  56. end
  57. end
  58. it_behaves_like 'when action is report'
  59. context 'when the moderator is blocked by the author' do
  60. before do
  61. account.block!(user.account)
  62. end
  63. it_behaves_like 'when action is report'
  64. end
  65. end
  66. end