Commit c754b693 authored by Shinya Maeda's avatar Shinya Maeda

Clean up presence validation spec

parent f7f60ab5
...@@ -36,13 +36,12 @@ describe Ci::Pipeline, :mailer do ...@@ -36,13 +36,12 @@ describe Ci::Pipeline, :mailer do
end end
describe 'modules' do describe 'modules' do
it_behaves_like 'AtomicInternalId' do it_behaves_like 'AtomicInternalId', validate_presence: false do
let(:internal_id_attribute) { :iid } let(:internal_id_attribute) { :iid }
let(:instance) { build(:ci_pipeline) } let(:instance) { build(:ci_pipeline) }
let(:scope) { :project } let(:scope) { :project }
let(:scope_attrs) { { project: instance.project } } let(:scope_attrs) { { project: instance.project } }
let(:usage) { :ci_pipelines } let(:usage) { :ci_pipelines }
let(:allow_nil) { true }
end end
end end
......
require 'spec_helper' require 'spec_helper'
shared_examples_for 'AtomicInternalId' do shared_examples_for 'AtomicInternalId' do |validate_presence: true|
let(:allow_nil) { false }
describe '.has_internal_id' do describe '.has_internal_id' do
describe 'Module inclusion' do describe 'Module inclusion' do
subject { described_class } subject { described_class }
...@@ -12,18 +10,30 @@ shared_examples_for 'AtomicInternalId' do ...@@ -12,18 +10,30 @@ shared_examples_for 'AtomicInternalId' do
describe 'Validation' do describe 'Validation' do
before do before do
allow_any_instance_of(described_class).to receive(:"ensure_#{scope}_#{internal_id_attribute}!") {} allow_any_instance_of(described_class).to receive(:"ensure_#{scope}_#{internal_id_attribute}!")
end
it 'validates presence' do
instance.valid? instance.valid?
end
if allow_nil context 'when presence validattion is required' do
expect(instance.errors[internal_id_attribute]).to be_empty before do
else skip unless validate_presence
end
it 'validates presence' do
expect(instance.errors[internal_id_attribute]).to include("can't be blank") expect(instance.errors[internal_id_attribute]).to include("can't be blank")
end end
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 end
describe 'Creating an instance' do describe 'Creating an instance' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment