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:
-rw-r--r--spec/factories/ci/builds.rb4
-rw-r--r--spec/factories/ci/pipelines.rb4
-rw-r--r--spec/factories/ci/runners.rb5
-rw-r--r--spec/models/ci/build_spec.rb2
-rw-r--r--spec/models/ci/runner_spec.rb24
-rw-r--r--spec/services/ci/create_pipeline_service_spec.rb16
-rw-r--r--spec/services/ci/register_job_service_spec.rb38
-rw-r--r--spec/support/cycle_analytics_helpers.rb4
8 files changed, 67 insertions, 30 deletions
diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb
index bdc3e8acc07..25ec63de94a 100644
--- a/spec/factories/ci/builds.rb
+++ b/spec/factories/ci/builds.rb
@@ -231,9 +231,5 @@ FactoryGirl.define do
trait :protected do
protected true
end
-
- trait :unprotected do
- protected false
- end
end
end
diff --git a/spec/factories/ci/pipelines.rb b/spec/factories/ci/pipelines.rb
index 5b51f5898a3..e5ea6b41ea3 100644
--- a/spec/factories/ci/pipelines.rb
+++ b/spec/factories/ci/pipelines.rb
@@ -64,10 +64,6 @@ FactoryGirl.define do
trait :protected do
protected true
end
-
- trait :unprotected do
- protected false
- end
end
end
end
diff --git a/spec/factories/ci/runners.rb b/spec/factories/ci/runners.rb
index efd9b34fb3f..88bb755d068 100644
--- a/spec/factories/ci/runners.rb
+++ b/spec/factories/ci/runners.rb
@@ -5,6 +5,7 @@ FactoryGirl.define do
platform "darwin"
is_shared false
active true
+ access_level :not_protected
trait :online do
contacted_at Time.now
@@ -25,9 +26,5 @@ FactoryGirl.define do
trait :ref_protected do
access_level :ref_protected
end
-
- trait :not_protected do
- access_level :not_protected
- end
end
end
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 1f965cfbede..3fe3ec17d36 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -53,7 +53,7 @@ describe Ci::Build do
end
context 'when protected is false' do
- let!(:job) { create(:ci_build, :unprotected) }
+ let!(:job) { create(:ci_build) }
it { is_expected.not_to include(job) }
end
diff --git a/spec/models/ci/runner_spec.rb b/spec/models/ci/runner_spec.rb
index ca48372c5e2..2e686e515c5 100644
--- a/spec/models/ci/runner_spec.rb
+++ b/spec/models/ci/runner_spec.rb
@@ -255,7 +255,29 @@ describe Ci::Runner do
end
end
- context 'when runner is protected' do
+ context 'when access_level of runner is not_protected' do
+ before do
+ runner.not_protected!
+ end
+
+ context 'when build is protected' do
+ before do
+ build.protected = true
+ end
+
+ it { is_expected.to be_truthy }
+ end
+
+ context 'when build is unprotected' do
+ before do
+ build.protected = false
+ end
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
+ context 'when access_level of runner is ref_protected' do
before do
runner.ref_protected!
end
diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb
index 8b0573db846..49d7c663128 100644
--- a/spec/services/ci/create_pipeline_service_spec.rb
+++ b/spec/services/ci/create_pipeline_service_spec.rb
@@ -391,14 +391,16 @@ describe Ci::CreatePipelineService do
end
context 'when user is master' do
+ let(:pipeline) { execute_service }
+
before do
project.add_master(user)
end
- it 'creates a pipeline' do
- expect(execute_service).to be_persisted
+ it 'creates a protected pipeline' do
+ expect(pipeline).to be_persisted
+ expect(pipeline).to be_protected
expect(Ci::Pipeline.count).to eq(1)
- expect(Ci::Pipeline.last).to be_protected
end
end
@@ -469,12 +471,12 @@ describe Ci::CreatePipelineService do
let(:user) {}
let(:trigger) { create(:ci_trigger, owner: nil) }
let(:trigger_request) { create(:ci_trigger_request, trigger: trigger) }
+ let(:pipeline) { execute_service(trigger_request: trigger_request) }
- it 'creates a pipeline' do
- expect(execute_service(trigger_request: trigger_request))
- .to be_persisted
+ it 'creates an unprotected pipeline' do
+ expect(pipeline).to be_persisted
+ expect(pipeline).not_to be_protected
expect(Ci::Pipeline.count).to eq(1)
- expect(Ci::Pipeline.last).not_to be_protected
end
end
end
diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb
index 6f8ebf5d3ba..6bc3dadbc71 100644
--- a/spec/services/ci/register_job_service_spec.rb
+++ b/spec/services/ci/register_job_service_spec.rb
@@ -219,18 +219,30 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :not_protected, :specific) }
context 'when a job is protected' do
- let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) }
+ let!(:protected_job) { create(:ci_build, :protected, pipeline: pipeline) }
it 'picks the protected job' do
- expect(execute(specific_runner)).to eq(pending_build)
+ expect(execute(specific_runner)).to eq(protected_job)
end
end
context 'when a job is unprotected' do
- let!(:pending_build) { create(:ci_build, :unprotected, pipeline: pipeline) }
+ let!(:unprotected_job) { create(:ci_build, pipeline: pipeline) }
it 'picks the unprotected job' do
- expect(execute(specific_runner)).to eq(pending_build)
+ expect(execute(specific_runner)).to eq(unprotected_job)
+ end
+ end
+
+ context 'when protected attribute of a job is nil' do
+ let!(:legacy_job) { create(:ci_build, pipeline: pipeline) }
+
+ before do
+ legacy_job.update_attribute(:protected, nil)
+ end
+
+ it 'picks the legacy job' do
+ expect(execute(specific_runner)).to eq(legacy_job)
end
end
end
@@ -239,20 +251,32 @@ module Ci
let!(:specific_runner) { create(:ci_runner, :ref_protected, :specific) }
context 'when a job is protected' do
- let!(:pending_build) { create(:ci_build, :protected, pipeline: pipeline) }
+ let!(:protected_job) { create(:ci_build, :protected, pipeline: pipeline) }
it 'picks the protected job' do
- expect(execute(specific_runner)).to eq(pending_build)
+ expect(execute(specific_runner)).to eq(protected_job)
end
end
context 'when a job is unprotected' do
- let!(:unprotected_job) { create(:ci_build, :unprotected, pipeline: pipeline) }
+ let!(:unprotected_job) { create(:ci_build, pipeline: pipeline) }
it 'does not pick the unprotected job' do
expect(execute(specific_runner)).to be_nil
end
end
+
+ context 'when protected attribute of a job is nil' do
+ let!(:legacy_job) { create(:ci_build, pipeline: pipeline) }
+
+ before do
+ legacy_job.update_attribute(:protected, nil)
+ end
+
+ it 'does not pick the legacy job' do
+ expect(execute(specific_runner)).to be_nil
+ end
+ end
end
def execute(runner)
diff --git a/spec/support/cycle_analytics_helpers.rb b/spec/support/cycle_analytics_helpers.rb
index e6b66c4baed..934b4557ba2 100644
--- a/spec/support/cycle_analytics_helpers.rb
+++ b/spec/support/cycle_analytics_helpers.rb
@@ -81,7 +81,7 @@ module CycleAnalyticsHelpers
ref: 'master',
source: :push,
project: project,
- protected: true)
+ protected: false)
end
def new_dummy_job(environment)
@@ -95,7 +95,7 @@ module CycleAnalyticsHelpers
tag: false,
name: 'dummy',
pipeline: dummy_pipeline,
- protected: true)
+ protected: false)
end
end