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

Fix register_build_service tests

parent 6abca128
......@@ -41,6 +41,10 @@ module Ci
query: "%#{query.try(:downcase)}%")
end
def gl_projects_ids
projects.select(:gitlab_id)
end
def set_default_values
self.token = SecureRandom.hex(15) if self.token.blank?
end
......
......@@ -8,10 +8,10 @@ module Ci
builds =
if current_runner.shared?
# 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
# 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
builds = builds.order('created_at ASC')
......
......@@ -3,15 +3,15 @@ require 'spec_helper'
module Ci
describe RegisterBuildService do
let!(:service) { RegisterBuildService.new }
let!(:project) { FactoryGirl.create :ci_project }
let!(:gl_project) { FactoryGirl.create :empty_project, gitlab_ci_project: project }
let!(:gl_project) { FactoryGirl.create :empty_project }
let!(:commit) { FactoryGirl.create :ci_commit, gl_project: gl_project }
let!(:pending_build) { FactoryGirl.create :ci_build, commit: commit }
let!(:shared_runner) { FactoryGirl.create(:ci_runner, is_shared: true) }
let!(:specific_runner) { FactoryGirl.create(:ci_runner, is_shared: false) }
before do
specific_runner.assign_to(project)
gl_project.ensure_ci_project
specific_runner.assign_to(gl_project.gitlab_ci_project)
end
describe :execute do
......@@ -48,8 +48,7 @@ module Ci
context 'allow shared runners' do
before do
project.shared_runners_enabled = true
project.save
gl_project.gitlab_ci_project.update(shared_runners_enabled: true)
end
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