Commit 2c1f7cca authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix register_build_service tests

parent 6abca128
...@@ -41,6 +41,10 @@ module Ci ...@@ -41,6 +41,10 @@ module Ci
query: "%#{query.try(:downcase)}%") query: "%#{query.try(:downcase)}%")
end end
def gl_projects_ids
projects.select(:gitlab_id)
end
def set_default_values def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank? self.token = SecureRandom.hex(15) if self.token.blank?
end end
......
...@@ -8,10 +8,10 @@ module Ci ...@@ -8,10 +8,10 @@ module Ci
builds = builds =
if current_runner.shared? if current_runner.shared?
# don't run projects which have not enables shared runners # don't run projects which have not enables shared runners
builds.includes(:project).where(ci_projects: { shared_runners_enabled: true }) builds.joins(commit: {gl_project: :gitlab_ci_project}).where(ci_projects: {shared_runners_enabled: true})
else else
# do run projects which are only assigned to this runner # do run projects which are only assigned to this runner
builds.where(project_id: current_runner.projects) builds.joins(:commit).where(ci_commits: {gl_project_id: current_runner.gl_projects_ids})
end end
builds = builds.order('created_at ASC') builds = builds.order('created_at ASC')
...@@ -19,7 +19,7 @@ module Ci ...@@ -19,7 +19,7 @@ module Ci
build = builds.find do |build| build = builds.find do |build|
(build.tag_list - current_runner.tag_list).empty? (build.tag_list - current_runner.tag_list).empty?
end end
if build if build
# In case when 2 runners try to assign the same build, second runner will be declined # In case when 2 runners try to assign the same build, second runner will be declined
......
...@@ -3,15 +3,15 @@ require 'spec_helper' ...@@ -3,15 +3,15 @@ require 'spec_helper'
module Ci module Ci
describe RegisterBuildService do describe RegisterBuildService do
let!(:service) { RegisterBuildService.new } let!(:service) { RegisterBuildService.new }
let!(:project) { FactoryGirl.create :ci_project } let!(:gl_project) { FactoryGirl.create :empty_project }
let!(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project } let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit } let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit }
let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) } let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) } let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
before do before do
specific_runner.assign_to(project) gl_project.ensure_ci_project
specific_runner.assign_to(gl_project.gitlab_ci_project)
end end
describe :execute do describe :execute do
...@@ -48,8 +48,7 @@ module Ci ...@@ -48,8 +48,7 @@ module Ci
context 'allow shared runners' do context 'allow shared runners' do
before do before do
project.shared_runners_enabled = true gl_project.gitlab_ci_project.update(shared_runners_enabled: true)
project.save
end end
context 'shared runner' do context 'shared runner' do
......
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