Commit 82a49d0f authored by Shinya Maeda's avatar Shinya Maeda

Clarify scope for AtomicInternalId shared spec

parent 1e76f289
...@@ -39,6 +39,7 @@ describe Ci::Pipeline, :mailer do ...@@ -39,6 +39,7 @@ describe Ci::Pipeline, :mailer do
it_behaves_like 'AtomicInternalId' do it_behaves_like 'AtomicInternalId' 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_attrs) { { project: instance.project } } let(:scope_attrs) { { project: instance.project } }
let(:usage) { :ci_pipelines } let(:usage) { :ci_pipelines }
let(:allow_nil) { true } let(:allow_nil) { true }
......
...@@ -20,6 +20,7 @@ describe Deployment do ...@@ -20,6 +20,7 @@ describe Deployment do
it_behaves_like 'AtomicInternalId' do it_behaves_like 'AtomicInternalId' do
let(:internal_id_attribute) { :iid } let(:internal_id_attribute) { :iid }
let(:instance) { build(:deployment) } let(:instance) { build(:deployment) }
let(:scope) { :project }
let(:scope_attrs) { { project: instance.project } } let(:scope_attrs) { { project: instance.project } }
let(:usage) { :deployments } let(:usage) { :deployments }
end end
......
...@@ -17,6 +17,7 @@ describe Issue do ...@@ -17,6 +17,7 @@ describe Issue do
it_behaves_like 'AtomicInternalId' do it_behaves_like 'AtomicInternalId' do
let(:internal_id_attribute) { :iid } let(:internal_id_attribute) { :iid }
let(:instance) { build(:issue) } let(:instance) { build(:issue) }
let(:scope) { :project }
let(:scope_attrs) { { project: instance.project } } let(:scope_attrs) { { project: instance.project } }
let(:usage) { :issues } let(:usage) { :issues }
end end
......
...@@ -25,6 +25,7 @@ describe MergeRequest do ...@@ -25,6 +25,7 @@ describe MergeRequest do
it_behaves_like 'AtomicInternalId' do it_behaves_like 'AtomicInternalId' do
let(:internal_id_attribute) { :iid } let(:internal_id_attribute) { :iid }
let(:instance) { build(:merge_request) } let(:instance) { build(:merge_request) }
let(:scope) { :target_project }
let(:scope_attrs) { { project: instance.target_project } } let(:scope_attrs) { { project: instance.target_project } }
let(:usage) { :merge_requests } let(:usage) { :merge_requests }
end end
......
...@@ -6,6 +6,7 @@ describe Milestone do ...@@ -6,6 +6,7 @@ describe Milestone do
it_behaves_like 'AtomicInternalId' do it_behaves_like 'AtomicInternalId' do
let(:internal_id_attribute) { :iid } let(:internal_id_attribute) { :iid }
let(:instance) { build(:milestone, project: build(:project), group: nil) } let(:instance) { build(:milestone, project: build(:project), group: nil) }
let(:scope) { :project }
let(:scope_attrs) { { project: instance.project } } let(:scope_attrs) { { project: instance.project } }
let(:usage) { :milestones } let(:usage) { :milestones }
end end
...@@ -15,6 +16,7 @@ describe Milestone do ...@@ -15,6 +16,7 @@ describe Milestone do
it_behaves_like 'AtomicInternalId' do it_behaves_like 'AtomicInternalId' do
let(:internal_id_attribute) { :iid } let(:internal_id_attribute) { :iid }
let(:instance) { build(:milestone, project: nil, group: build(:group)) } let(:instance) { build(:milestone, project: nil, group: build(:group)) }
let(:scope) { :group }
let(:scope_attrs) { { namespace: instance.group } } let(:scope_attrs) { { namespace: instance.group } }
let(:usage) { :milestones } let(:usage) { :milestones }
end end
......
...@@ -12,16 +12,16 @@ shared_examples_for 'AtomicInternalId' do ...@@ -12,16 +12,16 @@ 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_attrs.keys.first}_#{internal_id_attribute}!") {} allow_any_instance_of(described_class).to receive(:"ensure_#{scope}_#{internal_id_attribute}!") {}
end end
it 'validates presence' do it 'validates presence' do
instance.valid? instance.valid?
if allow_nil if allow_nil
expect(instance.errors[:iid]).to be_empty expect(instance.errors[internal_id_attribute]).to be_empty
else else
expect(instance.errors[:iid]).to include("can't be blank") expect(instance.errors[internal_id_attribute]).to include("can't be blank")
end end
end end
end end
......
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