2020-07-23 05:09:18 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Projects::IncidentsController do
|
2020-10-01 11:10:05 -04:00
|
|
|
let_it_be_with_refind(:project) { create(:project) }
|
2020-07-23 05:09:18 -04:00
|
|
|
let_it_be(:developer) { create(:user) }
|
|
|
|
let_it_be(:guest) { create(:user) }
|
2020-10-01 11:10:05 -04:00
|
|
|
let_it_be(:anonymous) { nil }
|
2020-07-23 05:09:18 -04:00
|
|
|
|
|
|
|
before_all do
|
|
|
|
project.add_guest(guest)
|
2020-09-30 17:10:09 -04:00
|
|
|
project.add_developer(developer)
|
2020-07-23 05:09:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-01 11:10:05 -04:00
|
|
|
before do
|
|
|
|
sign_in(user) if user
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { make_request }
|
|
|
|
|
|
|
|
shared_examples 'not found' do
|
|
|
|
include_examples 'returning response status', :not_found
|
|
|
|
end
|
|
|
|
|
|
|
|
shared_examples 'login required' do
|
|
|
|
it 'redirects to the login page' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to redirect_to(new_user_session_path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-07-23 05:09:18 -04:00
|
|
|
describe 'GET #index' do
|
|
|
|
def make_request
|
2020-10-01 11:10:05 -04:00
|
|
|
get :index, params: project_params
|
2020-07-23 05:09:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-01 11:10:05 -04:00
|
|
|
let(:user) { developer }
|
|
|
|
|
|
|
|
it 'shows the page' do
|
|
|
|
subject
|
2020-09-30 17:10:09 -04:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:index)
|
|
|
|
end
|
|
|
|
|
2020-10-01 11:10:05 -04:00
|
|
|
context 'when user is unauthorized' do
|
|
|
|
let(:user) { anonymous }
|
|
|
|
|
|
|
|
it_behaves_like 'login required'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a guest' do
|
|
|
|
let(:user) { guest }
|
|
|
|
|
|
|
|
it 'shows the page' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:index)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'GET #show' do
|
|
|
|
def make_request
|
|
|
|
get :show, params: project_params(id: resource)
|
|
|
|
end
|
|
|
|
|
|
|
|
let_it_be(:resource) { create(:incident, project: project) }
|
|
|
|
let(:user) { developer }
|
|
|
|
|
|
|
|
it 'renders incident page' do
|
|
|
|
subject
|
2020-07-23 05:09:18 -04:00
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
2020-10-01 11:10:05 -04:00
|
|
|
expect(response).to render_template(:show)
|
|
|
|
|
|
|
|
expect(assigns(:incident)).to be_present
|
|
|
|
expect(assigns(:incident).author.association(:status)).to be_loaded
|
|
|
|
expect(assigns(:issue)).to be_present
|
|
|
|
expect(assigns(:noteable)).to eq(assigns(:incident))
|
2020-07-23 05:09:18 -04:00
|
|
|
end
|
|
|
|
|
2020-10-01 11:10:05 -04:00
|
|
|
context 'with non existing id' do
|
|
|
|
let(:resource) { non_existing_record_id }
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
|
|
|
end
|
2020-07-23 05:09:18 -04:00
|
|
|
|
2020-10-01 11:10:05 -04:00
|
|
|
context 'for issue' do
|
|
|
|
let_it_be(:resource) { create(:issue, project: project) }
|
|
|
|
|
|
|
|
it_behaves_like 'not found'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is a guest' do
|
|
|
|
let(:user) { guest }
|
|
|
|
|
|
|
|
it 'shows the page' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:ok)
|
|
|
|
expect(response).to render_template(:show)
|
2020-07-23 05:09:18 -04:00
|
|
|
end
|
|
|
|
end
|
2020-10-01 11:10:05 -04:00
|
|
|
|
|
|
|
context 'when unauthorized' do
|
|
|
|
let(:user) { anonymous }
|
|
|
|
|
|
|
|
it_behaves_like 'login required'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def project_params(opts = {})
|
|
|
|
opts.reverse_merge(namespace_id: project.namespace, project_id: project)
|
2020-07-23 05:09:18 -04:00
|
|
|
end
|
|
|
|
end
|