report_notes_controller_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. require 'rails_helper'
  2. describe Admin::ReportNotesController do
  3. render_views
  4. let(:user) { Fabricate(:user, admin: true) }
  5. before do
  6. sign_in user, scope: :user
  7. end
  8. describe 'POST #create' do
  9. subject { post :create, params: params }
  10. let(:report) { Fabricate(:report, action_taken: action_taken, action_taken_by_account_id: account_id) }
  11. context 'when parameter is valid' do
  12. context 'when report is unsolved' do
  13. let(:action_taken) { false }
  14. let(:account_id) { nil }
  15. context 'when create_and_resolve flag is on' do
  16. let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_resolve: nil } }
  17. it 'creates a report note and resolves report' do
  18. expect { subject }.to change { ReportNote.count }.by(1)
  19. expect(report.reload).to be_action_taken
  20. expect(subject).to redirect_to admin_reports_path
  21. end
  22. end
  23. context 'when create_and_resolve flag is false' do
  24. let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
  25. it 'creates a report note and does not resolve report' do
  26. expect { subject }.to change { ReportNote.count }.by(1)
  27. expect(report.reload).not_to be_action_taken
  28. expect(subject).to redirect_to admin_report_path(report)
  29. end
  30. end
  31. end
  32. context 'when report is resolved' do
  33. let(:action_taken) { true }
  34. let(:account_id) { user.account.id }
  35. context 'when create_and_unresolve flag is on' do
  36. let(:params) { { report_note: { content: 'test content', report_id: report.id }, create_and_unresolve: nil } }
  37. it 'creates a report note and unresolves report' do
  38. expect { subject }.to change { ReportNote.count }.by(1)
  39. expect(report.reload).not_to be_action_taken
  40. expect(subject).to redirect_to admin_report_path(report)
  41. end
  42. end
  43. context 'when create_and_unresolve flag is false' do
  44. let(:params) { { report_note: { content: 'test content', report_id: report.id } } }
  45. it 'creates a report note and does not unresolve report' do
  46. expect { subject }.to change { ReportNote.count }.by(1)
  47. expect(report.reload).to be_action_taken
  48. expect(subject).to redirect_to admin_report_path(report)
  49. end
  50. end
  51. end
  52. end
  53. context 'when parameter is invalid' do
  54. let(:params) { { report_note: { content: '', report_id: report.id } } }
  55. let(:action_taken) { false }
  56. let(:account_id) { nil }
  57. it 'renders admin/reports/show' do
  58. expect(subject).to render_template 'admin/reports/show'
  59. end
  60. end
  61. end
  62. describe 'DELETE #destroy' do
  63. subject { delete :destroy, params: { id: report_note.id } }
  64. let!(:report_note) { Fabricate(:report_note) }
  65. it 'deletes note' do
  66. expect { subject }.to change { ReportNote.count }.by(-1)
  67. expect(subject).to redirect_to admin_report_path(report_note.report)
  68. end
  69. end
  70. end