2015-10-24 18:46:33 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AbuseReportsController do
|
2016-01-14 18:37:52 +05:30
|
|
|
let(:reporter) { create(:user) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:attrs) do
|
|
|
|
attributes_for(:abuse_report) do |hash|
|
|
|
|
hash[:user_id] = user.id
|
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(reporter)
|
|
|
|
end
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
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)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
it 'calls notify' do
|
|
|
|
expect_any_instance_of(AbuseReport).to receive(:notify)
|
2015-12-23 02:04:40 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
post :create, abuse_report: attrs
|
2015-12-23 02:04:40 +05:30
|
|
|
end
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
it 'redirects back to the reported user' do
|
|
|
|
post :create, abuse_report: attrs
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
expect(response).to redirect_to user
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
2016-01-14 18:37:52 +05:30
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
context 'with invalid attributes' do
|
|
|
|
it 'renders new' do
|
|
|
|
attrs.delete(:user_id)
|
|
|
|
post :create, abuse_report: attrs
|
2015-10-24 18:46:33 +05:30
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
expect(response).to render_template(:new)
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|