2022-03-02 08:16:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
RSpec.describe Admin::RunnerProjectsController, feature_category: :runner_fleet do
|
2022-03-02 08:16:31 +05:30
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:project) { create(:project, group: group) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
sign_in(create(:admin))
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#create' do
|
|
|
|
let(:project_id) { project.path }
|
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
subject(:send_create) do
|
2022-03-02 08:16:31 +05:30
|
|
|
post :create, params: {
|
|
|
|
namespace_id: group.path,
|
|
|
|
project_id: project_id,
|
|
|
|
runner_project: { runner_id: project_runner.id }
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
context 'when assigning to another project' do
|
|
|
|
let(:project_runner) { create(:ci_runner, :project, projects: [source_project]) }
|
|
|
|
let(:source_project) { create(:project) }
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
it 'redirects to the admin runner edit page' do
|
2022-05-07 20:08:51 +05:30
|
|
|
send_create
|
2022-03-02 08:16:31 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(flash[:success]).to be_present
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
expect(response).to redirect_to edit_admin_runner_url(project_runner)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
context 'when assigning to same project' do
|
|
|
|
let(:project_runner) { create(:ci_runner, :project, projects: [project]) }
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
it 'redirects to the admin runner edit page' do
|
2022-05-07 20:08:51 +05:30
|
|
|
send_create
|
2022-03-02 08:16:31 +05:30
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
expect(flash[:alert]).to be_present
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
expect(response).to redirect_to edit_admin_runner_url(project_runner)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
context 'when assigning to an unknown project' do
|
2022-03-02 08:16:31 +05:30
|
|
|
let_it_be(:project_runner) { create(:ci_runner, :project, projects: [project]) }
|
|
|
|
|
|
|
|
let(:project_id) { 0 }
|
|
|
|
|
|
|
|
it 'shows 404 for unknown project' do
|
2022-05-07 20:08:51 +05:30
|
|
|
send_create
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#destroy' do
|
|
|
|
let_it_be(:project_runner) { create(:ci_runner, :project, projects: [project]) }
|
|
|
|
|
|
|
|
let(:project_id) { project.path }
|
|
|
|
|
|
|
|
subject(:send_destroy) do
|
|
|
|
delete :destroy, params: {
|
|
|
|
namespace_id: group.path,
|
|
|
|
project_id: project_id,
|
|
|
|
id: runner_project_id
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
context 'when unassigning runner from project' do
|
2022-05-07 20:08:51 +05:30
|
|
|
let(:runner_project_id) { project_runner.runner_projects.last.id }
|
|
|
|
|
|
|
|
it 'redirects to the admin runner edit page' do
|
|
|
|
send_destroy
|
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:redirect)
|
|
|
|
expect(response).to redirect_to edit_admin_runner_url(project_runner)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-09 08:55:56 +05:30
|
|
|
context 'when unassigning from unknown project' do
|
2022-05-07 20:08:51 +05:30
|
|
|
let(:runner_project_id) { 0 }
|
|
|
|
|
|
|
|
it 'shows 404 for unknown project runner relationship' do
|
|
|
|
send_destroy
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
expect(response).to have_gitlab_http_status(:not_found)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|