Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-06-01 17:52:01 +0300
committerLin Jen-Shin <godfat@godfat.org>2017-06-01 17:52:01 +0300
commit7193108c9314a50287184f4d2b21d0f8ec12f65f (patch)
treebb889473590928604a5e3a598d0159f424c18859 /spec/models/ci
parentdb17e6ad8fe4e91f13fe9028a162236faad7f214 (diff)
Merge all environment url methods, introduce ensure_persisted_environment
To make sure that we're accessing the same instance, so ending up with `env.external` = `env.external_url` shall be fine.
Diffstat (limited to 'spec/models/ci')
-rw-r--r--spec/models/ci/build_spec.rb63
1 files changed, 38 insertions, 25 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 5a5702e5e8d..586acfacff8 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -427,8 +427,8 @@ describe Ci::Build, :models do
end
end
- describe '#expanded_environment_url' do
- subject { job.expanded_environment_url }
+ describe '#environment_url' do
+ subject { job.environment_url }
context 'when yaml environment uses $CI_COMMIT_REF_NAME' do
let(:job) do
@@ -453,31 +453,10 @@ describe Ci::Build, :models do
context 'when yaml environment does not have url' do
let(:job) { create(:ci_build, environment: 'staging') }
- it { is_expected.to be_nil }
- end
- end
-
- describe '#ci_environment_url' do
- subject { job.ci_environment_url }
-
- let!(:environment) do
- create(:environment, project: job.project, name: job.environment)
- end
-
- context 'when yaml environment has url' do
- let(:job) do
- create(:ci_build,
- ref: 'master',
- environment: 'staging',
- options: { environment: { url: 'http://review/$CI_COMMIT_REF_NAME' } })
+ let!(:environment) do
+ create(:environment, project: job.project, name: job.environment)
end
- it { is_expected.to eq('http://review/master') }
- end
-
- context 'when yaml environment does not have url' do
- let(:job) { create(:ci_build, environment: 'staging') }
-
it 'returns the external_url from persisted environment' do
is_expected.to eq(environment.external_url)
end
@@ -975,6 +954,40 @@ describe Ci::Build, :models do
it { is_expected.to eq(environment) }
end
+
+ context 'when there is not environment' do
+ it { is_expected.to be_nil }
+ end
+ end
+
+ describe '#ensure_persisted_environment' do
+ subject { job.ensure_persisted_environment }
+
+ let(:job) do
+ create(:ci_build,
+ ref: 'master',
+ environment: 'staging/$CI_COMMIT_REF_NAME')
+ end
+
+ context 'when there is no environment' do
+ it 'creates one by the expanded name' do
+ expect do
+ expect(subject.name).to eq('staging/master')
+ end.to change { Environment.count }.by(1)
+ end
+ end
+
+ context 'when there is already an environment' do
+ let!(:environment) do
+ create(:environment, project: job.project, name: 'staging/master')
+ end
+
+ it 'returns the existing environment' do
+ expect do
+ expect(subject).to eq(environment)
+ end.to change { Environment.count }.by(0)
+ end
+ end
end
describe '#play' do