diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-11-03 08:59:29 +0000 |
---|---|---|
committer | Grzegorz Bizon <grzegorz@gitlab.com> | 2017-11-03 08:59:29 +0000 |
commit | 1796683b86a20b7e1bb33f32815350b3ccb83eb6 (patch) | |
tree | 48f4a67409902ede338b84c885951d1400471aad | |
parent | 78ef301c3dfae273bf034a9ffdfa67e2ff7391aa (diff) | |
parent | 0b18023c89864b7e38e4dc43cff9f8ad4017c044 (diff) | |
download | gitlab-ce-1796683b86a20b7e1bb33f32815350b3ccb83eb6.tar.gz |
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
-rw-r--r-- | app/models/environment.rb | 6 | ||||
-rw-r--r-- | changelogs/unreleased/sh-fix-environment-slug-generation.yml | 5 | ||||
-rw-r--r-- | spec/models/environment_spec.rb | 15 |
3 files changed, 25 insertions, 1 deletions
diff --git a/app/models/environment.rb b/app/models/environment.rb index e613d21add6..8d6b0a32c13 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -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: diff --git a/changelogs/unreleased/sh-fix-environment-slug-generation.yml b/changelogs/unreleased/sh-fix-environment-slug-generation.yml new file mode 100644 index 00000000000..8a9c670c52c --- /dev/null +++ b/changelogs/unreleased/sh-fix-environment-slug-generation.yml @@ -0,0 +1,5 @@ +--- +title: Avoid regenerating the ref path for the environment +merge_request: +author: +type: fixed diff --git a/spec/models/environment_spec.rb b/spec/models/environment_spec.rb index e1be23541e8..f75de0a0d88 100644 --- a/spec/models/environment_spec.rb +++ b/spec/models/environment_spec.rb @@ -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 |