Commit 0eeb4bed authored by Lin Jen-Shin's avatar Lin Jen-Shin

Introduced Ci::Runner.specific_for for getting specific runners:

for a particular project.
parent 4f7f3258
......@@ -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
......
......@@ -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
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment