diff options
author | Sean McGivern <sean@gitlab.com> | 2019-04-16 11:34:41 +0000 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-04-16 11:34:41 +0000 |
commit | 28263f3cb7254bafc2d27b18bb846677e417226f (patch) | |
tree | 82f43516566fa4cac24ce6ef66dc9059953d355d /spec/models | |
parent | ba684aecd7bddd755743bec818df046115e017b7 (diff) | |
parent | fb07863693affd1d34f66847bd81a2a9f5ef81a2 (diff) | |
download | gitlab-ce-28263f3cb7254bafc2d27b18bb846677e417226f.tar.gz |
Merge branch 'rewind-iid-on-pipelines' into 'master'
Rewind iid on pipelines
Closes #59362
See merge request gitlab-org/gitlab-ce!26490
Diffstat (limited to 'spec/models')
-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) } |