reports_controller_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Api::V1::ReportsController, type: :controller do
  4. render_views
  5. let(:user) { Fabricate(:user, account: Fabricate(:account, username: 'alice')) }
  6. let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
  7. before do
  8. allow(controller).to receive(:doorkeeper_token) { token }
  9. end
  10. describe 'POST #create' do
  11. let(:scopes) { 'write:reports' }
  12. let!(:status) { Fabricate(:status) }
  13. let!(:admin) { Fabricate(:user, admin: true) }
  14. before do
  15. allow(AdminMailer).to receive(:new_report).and_return(double('email', deliver_later: nil))
  16. post :create, params: { status_ids: [status.id], account_id: status.account.id, comment: 'reasons' }
  17. end
  18. it 'creates a report' do
  19. expect(status.reload.account.targeted_reports).not_to be_empty
  20. expect(response).to have_http_status(200)
  21. end
  22. it 'sends e-mails to admins' do
  23. expect(AdminMailer).to have_received(:new_report).with(admin.account, Report)
  24. end
  25. end
  26. end