Commit 5e198153 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch '341840-deployments-environments-displays-wrong-commit-refs-tags' into 'master'

Resolve "Deployments->Environments displays wrong commit refs/tags"

See merge request gitlab-org/gitlab!83558
parents f44a4fd0 aaa42af4
......@@ -26,7 +26,7 @@ class Environment < ApplicationRecord
has_many :self_managed_prometheus_alert_events, inverse_of: :environment
has_many :alert_management_alerts, class_name: 'AlertManagement::Alert', inverse_of: :environment
has_one :last_deployment, -> { success.distinct_on_environment }, class_name: 'Deployment', inverse_of: :environment
has_one :last_deployment, -> { Feature.enabled?(:env_last_deployment_by_finished_at) ? success.ordered : success.distinct_on_environment }, class_name: 'Deployment', inverse_of: :environment
has_one :last_visible_deployment, -> { visible.distinct_on_environment }, inverse_of: :environment, class_name: 'Deployment'
has_one :last_visible_deployable, through: :last_visible_deployment, source: 'deployable', source_type: 'CommitStatus', disable_joins: true
has_one :last_visible_pipeline, through: :last_visible_deployable, source: 'pipeline', disable_joins: true
......
---
name: env_last_deployment_by_finished_at
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/83558
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/357299
milestone: '14.10'
type: development
group: group::release
default_enabled: false
......@@ -698,10 +698,29 @@ RSpec.describe Environment, :use_clean_rails_memory_store_caching do
context 'when there is a deployment record with success status' do
let!(:deployment) { create(:deployment, :success, environment: environment) }
let!(:old_deployment) { create(:deployment, :success, environment: environment, finished_at: 2.days.ago) }
it 'returns the latest successful deployment' do
is_expected.to eq(deployment)
end
context 'env_last_deployment_by_finished_at feature flag' do
it 'when enabled it returns the deployment with the latest finished_at' do
stub_feature_flags(env_last_deployment_by_finished_at: true)
expect(old_deployment.finished_at < deployment.finished_at).to be_truthy
is_expected.to eq(deployment)
end
it 'when disabled it returns the deployment with the highest id' do
stub_feature_flags(env_last_deployment_by_finished_at: false)
expect(old_deployment.finished_at < deployment.finished_at).to be_truthy
is_expected.to eq(old_deployment)
end
end
end
end
end
......
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