diff options
author | Kamil TrzciĆski <ayufan@ayufan.eu> | 2018-05-28 17:58:46 +0200 |
---|---|---|
committer | Dylan Griffith <dyl.griffith@gmail.com> | 2018-05-31 10:56:41 +0200 |
commit | c0c5f896b79635343d3651b40bcb875413ceedd9 (patch) | |
tree | 92b9573ded4705d1e6611dccc0cbe4d36d942403 /spec | |
parent | 47c11248636ede9b50bc3b6b4ac5de850ed3e0a9 (diff) | |
download | gitlab-ce-c0c5f896b79635343d3651b40bcb875413ceedd9.tar.gz |
Bring back deleted specs
Diffstat (limited to 'spec')
-rw-r--r-- | spec/factories/ci/runners.rb | 8 | ||||
-rw-r--r-- | spec/models/ci/runner_spec.rb | 6 | ||||
-rw-r--r-- | spec/requests/api/runners_spec.rb | 33 |
3 files changed, 42 insertions, 5 deletions
diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb index c698b74c578..6fb621b5e51 100644 --- a/spec/factories/ci/runners.rb +++ b/spec/factories/ci/runners.rb @@ -36,6 +36,14 @@ FactoryBot.define do end end + trait :without_projects do + # we use that to create invalid runner: + # the one without projects + after(:create) do |runner, evaluator| + runner.runner_projects.delete_all + end + end + trait :inactive do active false end diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb index cd60e67cc01..f8d590e4776 100644 --- a/spec/models/ci/runner_spec.rb +++ b/spec/models/ci/runner_spec.rb @@ -766,11 +766,7 @@ describe Ci::Runner do end describe 'project runner without projects is destroyable' do - subject { create(:ci_runner, :project) } - - before do - subject.runner_projects.delete_all - end + subject { create(:ci_runner, :project, :without_projects) } it 'does not have projects' do expect(subject.runner_projects).to be_empty diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb index cc326ff6484..0c7937feed6 100644 --- a/spec/requests/api/runners_spec.rb +++ b/spec/requests/api/runners_spec.rb @@ -128,6 +128,18 @@ describe API::Runners do end context 'when runner is not shared' do + context 'when unused runner is present' do + let!(:unused_project_runner) { create(:ci_runner, :project, :without_projects) } + + it 'deletes unused runner' do + expect do + delete api("/runners/#{unused_project_runner.id}", admin) + + expect(response).to have_gitlab_http_status(204) + end.to change { Ci::Runner.specific.count }.by(-1) + end + end + it "returns runner's details" do get api("/runners/#{project_runner.id}", admin) @@ -561,6 +573,17 @@ describe API::Runners do end context 'user is admin' do + context 'when project runner is used' do + let!(:new_project_runner) { create(:ci_runner, :project) } + + it 'enables any specific runner' do + expect do + post api("/projects/#{project.id}/runners", admin), runner_id: new_project_runner.id + end.to change { project.runners.count }.by(+1) + expect(response).to have_gitlab_http_status(201) + end + end + it 'enables a shared runner' do expect do post api("/projects/#{project.id}/runners", admin), runner_id: shared_runner.id @@ -578,6 +601,16 @@ describe API::Runners do end end + context 'user is not admin' do + let!(:new_project_runner) { create(:ci_runner, :project) } + + it 'does not enable runner without access to' do + post api("/projects/#{project.id}/runners", user), runner_id: new_project_runner.id + + expect(response).to have_gitlab_http_status(403) + end + end + context 'authorized user without permissions' do it 'does not enable runner' do post api("/projects/#{project.id}/runners", user2) |