statuses_controller_spec.rb 2.1 KB

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