summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2018-06-01 15:37:36 +0900
committerShinya Maeda <shinya@gitlab.com>2018-06-01 15:37:36 +0900
commitc754b6937c8077304386b3a6b37233e52eacdb3e (patch)
treeddc8c45a500d64d4f33ec12d11d5a79a20427ccd
parentf7f60ab54ab69fb4d0c3a43406a9809edab7d762 (diff)
downloadgitlab-ce-c754b6937c8077304386b3a6b37233e52eacdb3e.tar.gz
Clean up presence validation spec
-rw-r--r--spec/models/ci/pipeline_spec.rb3
-rw-r--r--spec/support/shared_examples/models/atomic_internal_id_spec.rb28
2 files changed, 20 insertions, 11 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 7d28f2eb86b..e03c068b88e 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -36,13 +36,12 @@ describe Ci::Pipeline, :mailer do
end
describe 'modules' do
- it_behaves_like 'AtomicInternalId' do
+ it_behaves_like 'AtomicInternalId', validate_presence: false do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:ci_pipeline) }
let(:scope) { :project }
let(:scope_attrs) { { project: instance.project } }
let(:usage) { :ci_pipelines }
- let(:allow_nil) { true }
end
end
diff --git a/spec/support/shared_examples/models/atomic_internal_id_spec.rb b/spec/support/shared_examples/models/atomic_internal_id_spec.rb
index a05279364f2..d0cd8da67e1 100644
--- a/spec/support/shared_examples/models/atomic_internal_id_spec.rb
+++ b/spec/support/shared_examples/models/atomic_internal_id_spec.rb
@@ -1,8 +1,6 @@
require 'spec_helper'
-shared_examples_for 'AtomicInternalId' do
- let(:allow_nil) { false }
-
+shared_examples_for 'AtomicInternalId' do |validate_presence: true|
describe '.has_internal_id' do
describe 'Module inclusion' do
subject { described_class }
@@ -12,18 +10,30 @@ shared_examples_for 'AtomicInternalId' do
describe 'Validation' do
before do
- allow_any_instance_of(described_class).to receive(:"ensure_#{scope}_#{internal_id_attribute}!") {}
- end
+ allow_any_instance_of(described_class).to receive(:"ensure_#{scope}_#{internal_id_attribute}!")
- it 'validates presence' do
instance.valid?
+ end
- if allow_nil
- expect(instance.errors[internal_id_attribute]).to be_empty
- else
+ context 'when presence validattion is required' do
+ before do
+ skip unless validate_presence
+ end
+
+ it 'validates presence' do
expect(instance.errors[internal_id_attribute]).to include("can't be blank")
end
end
+
+ context 'when presence validattion is not required' do
+ before do
+ skip if validate_presence
+ end
+
+ it 'does not validate presence' do
+ expect(instance.errors[internal_id_attribute]).to be_empty
+ end
+ end
end
describe 'Creating an instance' do