Merge branch 'sh-fix-environment-slug-generation' into 'master'
Avoid regenerating the ref path for the environment Closes #39752 See merge request gitlab-org/gitlab-ce!15167
This commit is contained in:
commit
1796683b86
3 changed files with 25 additions and 1 deletions
|
@ -110,7 +110,7 @@ class Environment < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def ref_path
|
||||
"refs/#{Repository::REF_ENVIRONMENTS}/#{generate_slug}"
|
||||
"refs/#{Repository::REF_ENVIRONMENTS}/#{slug}"
|
||||
end
|
||||
|
||||
def formatted_external_url
|
||||
|
@ -164,6 +164,10 @@ class Environment < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def slug
|
||||
super.presence || generate_slug
|
||||
end
|
||||
|
||||
# An environment name is not necessarily suitable for use in URLs, DNS
|
||||
# or other third-party contexts, so provide a slugified version. A slug has
|
||||
# the following properties:
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Avoid regenerating the ref path for the environment
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -547,6 +547,15 @@ describe Environment do
|
|||
|
||||
expect(environment.slug).to eq(original_slug)
|
||||
end
|
||||
|
||||
it "regenerates the slug if nil" do
|
||||
environment = build(:environment, slug: nil)
|
||||
|
||||
new_slug = environment.slug
|
||||
|
||||
expect(new_slug).not_to be_nil
|
||||
expect(environment.slug).to eq(new_slug)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#generate_slug' do
|
||||
|
@ -583,6 +592,12 @@ describe Environment do
|
|||
it 'returns a path that uses the slug and does not have spaces' do
|
||||
expect(environment.ref_path).to start_with('refs/environments/staging-review-1-')
|
||||
end
|
||||
|
||||
it "doesn't change when the slug is nil initially" do
|
||||
environment.slug = nil
|
||||
|
||||
expect(environment.ref_path).to eq(environment.ref_path)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#external_url_for' do
|
||||
|
|
Loading…
Reference in a new issue