BigW Consortium Gitlab

abuse_reports_controller_spec.rb 1 KB
Newer Older
1 2 3
require 'spec_helper'

describe AbuseReportsController do
4 5 6 7 8 9 10
  let(:reporter) { create(:user) }
  let(:user)     { create(:user) }
  let(:attrs) do
    attributes_for(:abuse_report) do |hash|
      hash[:user_id] = user.id
    end
  end
11 12 13 14 15

  before do
    sign_in(reporter)
  end

16 17 18 19 20 21
  describe 'POST create' do
    context 'with valid attributes' do
      it 'saves the abuse report' do
        expect do
          post :create, abuse_report: attrs
        end.to change { AbuseReport.count }.by(1)
Douwe Maan committed
22
      end
23

24 25
      it 'calls notify' do
        expect_any_instance_of(AbuseReport).to receive(:notify)
Valery Sizov committed
26

27
        post :create, abuse_report: attrs
Valery Sizov committed
28 29
      end

30 31
      it 'redirects back to the reported user' do
        post :create, abuse_report: attrs
Douwe Maan committed
32

33
        expect(response).to redirect_to user
Douwe Maan committed
34
      end
35
    end
Douwe Maan committed
36

37 38 39 40
    context 'with invalid attributes' do
      it 'renders new' do
        attrs.delete(:user_id)
        post :create, abuse_report: attrs
Douwe Maan committed
41

42
        expect(response).to render_template(:new)
Douwe Maan committed
43
      end
44 45
    end
  end
Douwe Maan committed
46
end