Commit b51e7347 authored by James Fargher's avatar James Fargher

Merge branch 'fix-pipeline-environments-finder' into 'master'

Fix environments query for pipeline

See merge request gitlab-org/gitlab!76189
parents 3f7be75b 85dcd0a9
......@@ -958,7 +958,7 @@ module Ci
.limit(100)
.pluck(:expanded_environment_name)
Environment.where(project: project, name: expanded_environment_names).with_deployments
Environment.where(project: project, name: expanded_environment_names).with_deployment(sha)
else
environment_ids = self_and_descendants.joins(:deployments).select(:'deployments.environment_id')
......
......@@ -89,7 +89,6 @@ class Environment < ApplicationRecord
scope :for_project, -> (project) { where(project_id: project) }
scope :for_tier, -> (tier) { where(tier: tier).where.not(tier: nil) }
scope :with_deployments, -> { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id')) }
scope :with_deployment, -> (sha) { where('EXISTS (?)', Deployment.select(1).where('deployments.environment_id = environments.id').where(sha: sha)) }
scope :unfoldered, -> { where(environment_type: nil) }
scope :with_rank, -> do
......
......@@ -3205,11 +3205,21 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
context 'when pipeline is not child nor parent' do
let_it_be(:pipeline) { create(:ci_pipeline, :created) }
let_it_be(:build) { create(:ci_build, :with_deployment, :deploy_to_production, pipeline: pipeline) }
let_it_be(:build, refind: true) { create(:ci_build, :with_deployment, :deploy_to_production, pipeline: pipeline) }
it 'returns just the pipeline environment' do
expect(subject).to contain_exactly(build.deployment.environment)
end
context 'when deployment SHA is not matched' do
before do
build.deployment.update!(sha: 'old-sha')
end
it 'does not return environments' do
expect(subject).to be_empty
end
end
end
context 'when an associated environment does not have deployments' 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