Merge branch 'sh-fix-environment-write-ref' into 'master'

Fix the writing of invalid environment refs

Closes #39182

See merge request gitlab-org/gitlab-ce!14993
This commit is contained in:
Grzegorz Bizon 2017-10-24 09:22:21 +00:00
commit 3dcdd4a1e8
3 changed files with 16 additions and 1 deletions

View File

@ -110,7 +110,7 @@ class Environment < ActiveRecord::Base
end
def ref_path
"refs/#{Repository::REF_ENVIRONMENTS}/#{Shellwords.shellescape(name)}"
"refs/#{Repository::REF_ENVIRONMENTS}/#{generate_slug}"
end
def formatted_external_url

View File

@ -0,0 +1,5 @@
---
title: Fix the writing of invalid environment refs
merge_request:
author:
type: fixed

View File

@ -575,6 +575,16 @@ describe Environment do
end
end
describe '#ref_path' do
subject(:environment) do
create(:environment, name: 'staging / review-1')
end
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
end
describe '#external_url_for' do
let(:source_path) { 'source/file.html' }
let(:sha) { RepoHelpers.sample_commit.id }