summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTomasz Maczukin <tomasz@maczukin.pl>2016-01-29 15:40:25 +0100
committerTomasz Maczukin <tomasz@maczukin.pl>2016-02-19 13:18:46 +0100
commitd42ced44d9f2ddeae5a76d60273a59d7253ca2b2 (patch)
tree82742396a4dea2588e822a6ab9c4c9975f674778 /spec
parent128be3c0103f601b2c80f3489646e57e202f6327 (diff)
downloadgitlab-ce-d42ced44d9f2ddeae5a76d60273a59d7253ca2b2.tar.gz
Add feature to enable/disable runner in project
Diffstat (limited to 'spec')
-rw-r--r--spec/requests/api/runners_spec.rb102
1 files changed, 102 insertions, 0 deletions
diff --git a/spec/requests/api/runners_spec.rb b/spec/requests/api/runners_spec.rb
index e5c837d051b..9ffa59dac07 100644
--- a/spec/requests/api/runners_spec.rb
+++ b/spec/requests/api/runners_spec.rb
@@ -9,6 +9,7 @@ describe API::API, api: true do
let!(:project) { create(:project, creator_id: user.id) }
let!(:project2) { create(:project, creator_id: user.id) }
let!(:master) { create(:project_member, user: user, project: project, access_level: ProjectMember::MASTER) }
+ let!(:master2) { create(:project_member, user: user, project: project2, access_level: ProjectMember::MASTER) }
let!(:developer) { create(:project_member, user: user2, project: project, access_level: ProjectMember::REPORTER) }
let!(:shared_runner) { create(:ci_shared_runner, tag_list: ['mysql', 'ruby'], active: true) }
let!(:specific_runner) { create(:ci_specific_runner, tag_list: ['mysql', 'ruby']) }
@@ -275,4 +276,105 @@ describe API::API, api: true do
end
end
end
+
+ describe 'PUT /projects/:id/runners/:runner_id' do
+ context 'authorized user' do
+ it 'should enable specific runner' do
+ expect do
+ put api("/projects/#{project.id}/runners/#{specific_runner2.id}", user)
+ end.to change{ project.runners.count }.by(+1)
+ expect(response.status).to eq(200)
+ end
+
+ it 'should avoid changes when enabling already enabled runner' do
+ expect do
+ put api("/projects/#{project.id}/runners/#{specific_runner.id}", user)
+ end.to change{ project.runners.count }.by(0)
+ expect(response.status).to eq(200)
+ end
+
+ it 'should not enable shared runner' do
+ put api("/projects/#{project.id}/runners/#{shared_runner.id}", user)
+
+ expect(response.status).to eq(403)
+ end
+
+ context 'user is admin' do
+ it 'should enable any specific runner' do
+ expect do
+ put api("/projects/#{project.id}/runners/#{unused_specific_runner.id}", admin)
+ end.to change{ project.runners.count }.by(+1)
+ expect(response.status).to eq(200)
+ end
+ end
+
+ context 'user is not admin' do
+ it 'should not enable runner without access to' do
+ put api("/projects/#{project.id}/runners/#{unused_specific_runner.id}", user)
+
+ expect(response.status).to eq(403)
+ end
+ end
+ end
+
+ context 'authorized user without permissions' do
+ it 'should not enable runner' do
+ put api("/projects/#{project.id}/runners/#{specific_runner2.id}", user2)
+
+ expect(response.status).to eq(403)
+ end
+ end
+
+ context 'unauthorized user' do
+ it 'should not enable runner' do
+ put api("/projects/#{project.id}/runners/#{specific_runner2.id}")
+
+ expect(response.status).to eq(401)
+ end
+ end
+ end
+
+ describe 'DELETE /projects/:id/runners/:runner_id' do
+ context 'authorized user' do
+ context 'when runner have more than one associated projects' do
+ it "should disable project's runner" do
+ expect do
+ delete api("/projects/#{project.id}/runners/#{two_projects_runner.id}", user)
+ end.to change{ project.runners.count }.by(-1)
+ expect(response.status).to eq(200)
+ end
+ end
+
+ context 'when runner have one associated projects' do
+ it "should not disable project's runner" do
+ expect do
+ delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user)
+ end.to change{ project.runners.count }.by(0)
+ expect(response.status).to eq(403)
+ end
+ end
+
+ it 'should return 404 is runner is not found' do
+ delete api("/projects/#{project.id}/runners/9999", user)
+
+ expect(response.status).to eq(404)
+ end
+ end
+
+ context 'authorized user without permissions' do
+ it "should not disable project's runner" do
+ delete api("/projects/#{project.id}/runners/#{specific_runner.id}", user2)
+
+ expect(response.status).to eq(403)
+ end
+ end
+
+ context 'unauthorized user' do
+ it "should not disable project's runner" do
+ delete api("/projects/#{project.id}/runners/#{specific_runner.id}")
+
+ expect(response.status).to eq(401)
+ end
+ end
+ end
end