diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2019-03-22 16:51:15 +0100 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2019-04-16 11:22:23 +0200 |
commit | fb07863693affd1d34f66847bd81a2a9f5ef81a2 (patch) | |
tree | 161fc48e7584a829293fa13cedd241f3734060d8 /spec/models/internal_id_spec.rb | |
parent | ef82859d7d8ea70b29f600193fc18bdf5aea895e (diff) | |
download | gitlab-ce-fb07863693affd1d34f66847bd81a2a9f5ef81a2.tar.gz |
Rewind IID on Ci::Pipelinesrewind-iid-on-pipelines
If no pipeline is created we currently have IID gap.
This is due to fact that we generate IID not on save,
but rather ahead of time. This results, us,
losing IIDs.
Diffstat (limited to 'spec/models/internal_id_spec.rb')
-rw-r--r-- | spec/models/internal_id_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb index ff2382838ae..0ed4e146caa 100644 --- a/spec/models/internal_id_spec.rb +++ b/spec/models/internal_id_spec.rb @@ -107,6 +107,57 @@ describe InternalId do end end + describe '.reset' do + subject { described_class.reset(issue, scope, usage, value) } + + context 'in the absence of a record' do + let(:value) { 2 } + + it 'does not revert back the value' do + expect { subject }.not_to change { described_class.count } + expect(subject).to be_falsey + end + end + + context 'when valid iid is used to reset' do + let!(:value) { generate_next } + + context 'and iid is a latest one' do + it 'does rewind and next generated value is the same' do + expect(subject).to be_truthy + expect(generate_next).to eq(value) + end + end + + context 'and iid is not a latest one' do + it 'does not rewind' do + generate_next + + expect(subject).to be_falsey + expect(generate_next).to be > value + end + end + + def generate_next + described_class.generate_next(issue, scope, usage, init) + end + end + + context 'with an insufficient schema version' do + let(:value) { 2 } + + before do + described_class.reset_column_information + # Project factory will also call the current_version + expect(ActiveRecord::Migrator).to receive(:current_version).twice.and_return(InternalId::REQUIRED_SCHEMA_VERSION - 1) + end + + it 'does not reset any of the iids' do + expect(subject).to be_falsey + end + end + end + describe '.track_greatest' do let(:value) { 9001 } subject { described_class.track_greatest(issue, scope, usage, value, init) } |