2015-10-08 11:13:28 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AbuseReportsController do
|
2016-01-04 18:59:42 -05:00
|
|
|
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-08 11:13:28 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(reporter)
|
|
|
|
end
|
|
|
|
|
2017-06-27 16:43:02 -04:00
|
|
|
describe 'GET new' do
|
|
|
|
context 'when the user has already been deleted' do
|
|
|
|
it 'redirects the reporter to root_path' do
|
|
|
|
user_id = user.id
|
|
|
|
user.destroy
|
|
|
|
|
|
|
|
get :new, { user_id: user_id }
|
|
|
|
|
|
|
|
expect(response).to redirect_to root_path
|
|
|
|
expect(flash[:alert]).to eq('Cannot create the abuse report. The user has been deleted.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has already been blocked' do
|
|
|
|
it 'redirects the reporter to the user\'s profile' do
|
|
|
|
user.block
|
|
|
|
|
|
|
|
get :new, { user_id: user.id }
|
|
|
|
|
|
|
|
expect(response).to redirect_to user
|
|
|
|
expect(flash[:alert]).to eq('Cannot create the abuse report. This user has been blocked.')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
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-18 05:58:53 -04:00
|
|
|
end
|
2015-10-08 11:13:28 -04:00
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
it 'calls notify' do
|
|
|
|
expect_any_instance_of(AbuseReport).to receive(:notify)
|
2015-11-30 09:12:31 -05:00
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
post :create, abuse_report: attrs
|
2015-11-30 09:12:31 -05:00
|
|
|
end
|
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
it 'redirects back to the reported user' do
|
|
|
|
post :create, abuse_report: attrs
|
2015-10-18 05:58:53 -04:00
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
expect(response).to redirect_to user
|
2015-10-18 05:58:53 -04:00
|
|
|
end
|
2016-01-04 18:59:42 -05:00
|
|
|
end
|
2015-10-18 05:58:53 -04:00
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
context 'with invalid attributes' do
|
|
|
|
it 'renders new' do
|
|
|
|
attrs.delete(:user_id)
|
|
|
|
post :create, abuse_report: attrs
|
2015-10-18 05:58:53 -04:00
|
|
|
|
2016-01-04 18:59:42 -05:00
|
|
|
expect(response).to render_template(:new)
|
2015-10-18 05:58:53 -04:00
|
|
|
end
|
2015-10-08 11:13:28 -04:00
|
|
|
end
|
|
|
|
end
|
2015-10-18 05:58:53 -04:00
|
|
|
end
|