summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-06-02 18:41:26 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-06-09 16:00:24 +0800
commit0eeb4bed497e5f6ba2af558869803432bee65f74 (patch)
tree77b67ed24b39dd3e5af07aaaf1b764960c37c56f
parent4f7f3258c18dfc207b838401f5ed71a3197eb22d (diff)
downloadgitlab-ce-0eeb4bed497e5f6ba2af558869803432bee65f74.tar.gz
Introduced Ci::Runner.specific_for for getting specific runners:
for a particular project.
-rw-r--r--app/controllers/projects/runners_controller.rb3
-rw-r--r--app/models/ci/runner.rb4
-rw-r--r--spec/models/ci/runner_spec.rb54
3 files changed, 59 insertions, 2 deletions
diff --git a/app/controllers/projects/runners_controller.rb b/app/controllers/projects/runners_controller.rb
index 0b4fa572501..bc4c5bd4575 100644
--- a/app/controllers/projects/runners_controller.rb
+++ b/app/controllers/projects/runners_controller.rb
@@ -7,8 +7,7 @@ class Projects::RunnersController < Projects::ApplicationController
def index
@runners = project.runners.ordered
@specific_runners = current_user.ci_authorized_runners.
- where.not(id: project.runners).
- ordered.page(params[:page]).per(20)
+ specific_for(project).ordered.page(params[:page]).per(20)
@shared_runners = Ci::Runner.shared.active
@shared_runners_count = @shared_runners.count(:all)
end
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index d61a8c00634..5c42c94e4dc 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -26,6 +26,10 @@ module Ci
.where("ci_runner_projects.gl_project_id = :project_id OR ci_runners.is_shared = true", project_id: project_id)
end
+ scope :specific_for, ->(project) do
+ where(locked: false).where.not(id: project.runners).specific
+ end
+
validate :tag_constraints
acts_as_taggable
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index 5d04d8ffcff..0d7ce5a020a 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -112,6 +112,60 @@ describe Ci::Runner, models: true do
end
end
+ describe :specific_for do
+ let(:runner) { create(:ci_runner) }
+ let(:project) { create(:project) }
+ let(:another_project) { create(:project) }
+
+ before { project.runners << runner }
+
+ context 'with shared runners' do
+ before { runner.update(is_shared: true) }
+
+ context 'should not give owned runner' do
+ subject { Ci::Runner.specific_for(project) }
+
+ it { is_expected.to be_empty }
+ end
+
+ context 'should not give shared runner' do
+ subject { Ci::Runner.specific_for(another_project) }
+
+ it { is_expected.to be_empty }
+ end
+ end
+
+ context 'with unlocked runner' do
+ context 'should not give owned runner' do
+ subject { Ci::Runner.specific_for(project) }
+
+ it { is_expected.to be_empty }
+ end
+
+ context 'should give a specific runner' do
+ subject { Ci::Runner.specific_for(another_project) }
+
+ it { is_expected.to contain_exactly(runner) }
+ end
+ end
+
+ context 'with locked runner' do
+ before { runner.update(locked: true) }
+
+ context 'should not give owned runner' do
+ subject { Ci::Runner.specific_for(project) }
+
+ it { is_expected.to be_empty }
+ end
+
+ context 'should not give a locked runner' do
+ subject { Ci::Runner.specific_for(another_project) }
+
+ it { is_expected.to be_empty }
+ end
+ end
+ end
+
describe "belongs_to_one_project?" do
it "returns false if there are two projects runner assigned to" do
runner = FactoryGirl.create(:ci_runner)