statuses_controller_spec.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.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: true }
  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. status.media_attachments << Fabricate(:media_attachment, type: :image, account: status.account)
  38. status.save!
  39. status.snapshot!(at_time: status.created_at, rate_limit: false)
  40. status.update!(text: 'Hello, this is an edited post')
  41. status.snapshot!(rate_limit: false)
  42. get :show, params: { account_id: account.id, id: status.id }
  43. end
  44. it 'returns http success' do
  45. expect(response).to have_http_status(200)
  46. end
  47. end
  48. describe 'POST #batch' do
  49. subject { post :batch, params: { :account_id => account.id, action => '', :admin_status_batch_action => { status_ids: status_ids } } }
  50. let(:status_ids) { [media_attached_status.id] }
  51. shared_examples 'when action is report' do
  52. let(:action) { 'report' }
  53. it 'creates a report and redirects to report page' do
  54. subject
  55. expect(Report.last)
  56. .to have_attributes(
  57. target_account_id: eq(account.id),
  58. status_ids: eq(status_ids)
  59. )
  60. expect(response).to redirect_to(admin_report_path(Report.last.id))
  61. end
  62. end
  63. it_behaves_like 'when action is report'
  64. context 'when the moderator is blocked by the author' do
  65. before do
  66. account.block!(user.account)
  67. end
  68. it_behaves_like 'when action is report'
  69. end
  70. end
  71. end