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:
authorKamil Trzcinski <ayufan@ayufan.eu>2017-09-06 22:00:34 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2017-09-06 22:00:34 +0300
commit632f6ba267bc09a658defc3721d2b52de05cf7e6 (patch)
treee486d01082cab7ba12cca31831fe6f6dd37f1d88 /spec/models/ci
parent5941f3a7e8628e8792c9dbfad07f9b4d6ba7fb2e (diff)
Add tests to cover all introduced changes
Diffstat (limited to 'spec/models/ci')
-rw-r--r--spec/models/ci/build_spec.rb24
-rw-r--r--spec/models/ci/pipeline_spec.rb73
2 files changed, 76 insertions, 21 deletions
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 08d22f166e4..c2c9f1c12d1 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -1688,6 +1688,30 @@ describe Ci::Build do
{ key: 'secret', value: 'value', public: false }])
end
end
+
+ context 'when using auto devops' do
+ context 'and is enabled' do
+ before do
+ project.create_auto_devops!(enabled: true, domain: 'example.com')
+ end
+
+ it "includes AUTO_DEVOPS_DOMAIN" do
+ is_expected.to include(
+ { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true })
+ end
+ end
+
+ context 'and is disabled' do
+ before do
+ project.create_auto_devops!(enabled: false, domain: 'example.com')
+ end
+
+ it "includes AUTO_DEVOPS_DOMAIN" do
+ is_expected.not_to include(
+ { key: 'AUTO_DEVOPS_DOMAIN', value: 'example.com', public: true })
+ end
+ end
+ end
end
describe 'state transition: any => [:pending]' do
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 8b36fffd808..95da97b7bc5 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -799,31 +799,64 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '#detect_ci_yaml_file' do
- context 'when the repo has a config file' do
- it 'returns that configuration' do
- allow(pipeline.project.repository).to receive(:gitlab_ci_yml_for)
- .and_return('config')
+ describe '#set_config_source' do
+ context 'on object initialisation' do
+ context 'when pipelines does not contain needed data' do
+ let(:pipeline) do
+ Ci::Pipeline.new
+ end
- expect(pipeline.detect_ci_yaml_file).to be_a(String)
- expect(pipeline.repository_source?).to be(true)
+ it 'defines source to be unknown' do
+ expect(pipeline).to be_unknown_source
+ end
end
- end
- context 'when the repo does not have a config file' do
- let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
+ context 'when pipeline contains all needed data' do
+ let(:pipeline) do
+ Ci::Pipeline.new(
+ project: project,
+ sha: '1234',
+ ref: 'master',
+ source: :push)
+ end
- context 'auto devops enabled' do
- before do
- allow_any_instance_of(ApplicationSetting)
- .to receive(:auto_devops_enabled?) { true }
+ context 'when the repository has a config file' do
+ before do
+ allow(project.repository).to receive(:gitlab_ci_yml_for)
+ .and_return('config')
+ end
+
+ it 'defines source to be from repository' do
+ expect(pipeline).to be_repository_source
+ end
+
+ context 'when loading an object' do
+ let(:new_pipeline) { Ci::Pipeline.find(pipeline.id) }
+
+ it 'does not redefine the source' do
+ # force to overwrite the source
+ pipeline.unknown_source!
+
+ expect(new_pipeline).to be_unknown_source
+ end
+ end
end
- it 'returns the implied ci file' do
- allow(pipeline.project).to receive(:ci_config_path) { 'custom' }
+ context 'when the repository does not have a config file' do
+ let(:implied_yml) { Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps').content }
- expect(pipeline.detect_ci_yaml_file).to eq(implied_yml)
- expect(pipeline.auto_devops_source?).to be(true)
+ context 'auto devops enabled' do
+ before do
+ stub_application_setting(auto_devops_enabled: true)
+ allow(project).to receive(:ci_config_path) { 'custom' }
+ end
+
+ it 'defines source to be auto devops' do
+ subject
+
+ expect(pipeline).to be_auto_devops_source
+ end
+ end
end
end
end
@@ -870,13 +903,11 @@ describe Ci::Pipeline, :mailer do
context 'when the source is auto_devops_source' do
before do
+ stub_application_setting(auto_devops_enabled: true)
pipeline.auto_devops_source!
end
it 'finds the implied config' do
- allow_any_instance_of(ApplicationSetting)
- .to receive(:auto_devops_enabled?) { true }
-
expect(pipeline.ci_yaml_file).to eq(implied_yml)
expect(pipeline.yaml_errors).to be_nil
end