2019-04-15 10:17:05 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-08 15:13:28 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe AbuseReportsController do
|
2016-01-04 23:59:42 +00: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 15:13:28 +00:00
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(reporter)
|
|
|
|
end
|
|
|
|
|
2017-06-27 20:43:02 +00: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
|
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
get :new, params: { user_id: user_id }
|
2017-06-27 20:43:02 +00:00
|
|
|
|
|
|
|
expect(response).to redirect_to root_path
|
2019-12-12 12:07:33 +00:00
|
|
|
expect(flash[:alert]).to eq(_('Cannot create the abuse report. The user has been deleted.'))
|
2017-06-27 20:43:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user has already been blocked' do
|
|
|
|
it 'redirects the reporter to the user\'s profile' do
|
|
|
|
user.block
|
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
get :new, params: { user_id: user.id }
|
2017-06-27 20:43:02 +00:00
|
|
|
|
|
|
|
expect(response).to redirect_to user
|
2019-12-12 12:07:33 +00:00
|
|
|
expect(flash[:alert]).to eq(_('Cannot create the abuse report. This user has been blocked.'))
|
2017-06-27 20:43:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-04 23:59:42 +00:00
|
|
|
describe 'POST create' do
|
|
|
|
context 'with valid attributes' do
|
|
|
|
it 'saves the abuse report' do
|
|
|
|
expect do
|
2018-12-17 22:52:17 +00:00
|
|
|
post :create, params: { abuse_report: attrs }
|
2016-01-04 23:59:42 +00:00
|
|
|
end.to change { AbuseReport.count }.by(1)
|
2015-10-18 09:58:53 +00:00
|
|
|
end
|
2015-10-08 15:13:28 +00:00
|
|
|
|
2016-01-04 23:59:42 +00:00
|
|
|
it 'calls notify' do
|
2019-11-07 15:06:33 +00:00
|
|
|
expect_next_instance_of(AbuseReport) do |instance|
|
|
|
|
expect(instance).to receive(:notify)
|
|
|
|
end
|
2015-11-30 14:12:31 +00:00
|
|
|
|
2018-12-17 22:52:17 +00:00
|
|
|
post :create, params: { abuse_report: attrs }
|
2015-11-30 14:12:31 +00:00
|
|
|
end
|
|
|
|
|
2016-01-04 23:59:42 +00:00
|
|
|
it 'redirects back to the reported user' do
|
2018-12-17 22:52:17 +00:00
|
|
|
post :create, params: { abuse_report: attrs }
|
2015-10-18 09:58:53 +00:00
|
|
|
|
2016-01-04 23:59:42 +00:00
|
|
|
expect(response).to redirect_to user
|
2015-10-18 09:58:53 +00:00
|
|
|
end
|
2016-01-04 23:59:42 +00:00
|
|
|
end
|
2015-10-18 09:58:53 +00:00
|
|
|
|
2016-01-04 23:59:42 +00:00
|
|
|
context 'with invalid attributes' do
|
|
|
|
it 'renders new' do
|
|
|
|
attrs.delete(:user_id)
|
2018-12-17 22:52:17 +00:00
|
|
|
post :create, params: { abuse_report: attrs }
|
2015-10-18 09:58:53 +00:00
|
|
|
|
2016-01-04 23:59:42 +00:00
|
|
|
expect(response).to render_template(:new)
|
2015-10-18 09:58:53 +00:00
|
|
|
end
|
2015-10-08 15:13:28 +00:00
|
|
|
end
|
|
|
|
end
|
2015-10-18 09:58:53 +00:00
|
|
|
end
|