use .owned_or_shared for #assignable_for?

instead of having the explicit logic duplicated from the scope we can
use the scope instead.
This commit is contained in:
Alexis Reigel 2017-10-04 17:11:53 +02:00
parent d588adff1a
commit 8d61d33d37
No known key found for this signature in database
GPG key ID: 55ADA7C7B683B329
2 changed files with 22 additions and 4 deletions

View file

@ -227,7 +227,7 @@ module Ci
end
def assignable_for?(project_id)
is_shared? || projects.exists?(id: project_id)
self.class.owned_or_shared(project_id).where(id: self.id).any?
end
def accepting_tags?(build)

View file

@ -236,6 +236,13 @@ describe Ci::Runner do
build.project.runners << runner
end
context 'a different runner' do
it 'cannot handle builds' do
other_runner = create :ci_runner
expect(other_runner.can_pick?(build)).to be_falsey
end
end
context 'when runner does not have tags' do
it 'can handle builds without tags' do
expect(runner.can_pick?(build)).to be_truthy
@ -277,7 +284,7 @@ describe Ci::Runner do
context 'when runner cannot pick untagged jobs' do
before do
runner.run_untagged = false
runner.update_attributes!(run_untagged: false)
end
it 'cannot handle builds without tags' do
@ -290,7 +297,7 @@ describe Ci::Runner do
context 'when runner is shared' do
before do
runner.is_shared = true
runner.update_attributes!(is_shared: true)
build.project.runners = []
end
@ -300,7 +307,7 @@ describe Ci::Runner do
context 'when runner is locked' do
before do
runner.locked = true
runner.update_attributes!(locked: true)
end
it 'can handle builds' do
@ -325,6 +332,17 @@ describe Ci::Runner do
expect(runner.can_pick?(build)).to be_falsey
end
end
context 'when runner is assigned to a group' do
before do
build.project.runners = []
runner.groups << create(:group, projects: [build.project])
end
it 'can handle builds' do
expect(runner.can_pick?(build)).to be_truthy
end
end
end
context 'when access_level of runner is not_protected' do