diff options
| author | Andreas Brandl <abrandl@gitlab.com> | 2018-03-16 13:34:08 +0100 |
|---|---|---|
| committer | Andreas Brandl <abrandl@gitlab.com> | 2018-03-16 13:35:27 +0100 |
| commit | fb6d6fce5a4d0fd833dc1cd231dd284a6c89471a (patch) | |
| tree | cd60653ee507ae673a6da8a12ebd731bf449f525 /spec | |
| parent | bc3fc8ec3eec74876a0e2125248c27cde153e32b (diff) | |
| download | gitlab-ce-fb6d6fce5a4d0fd833dc1cd231dd284a6c89471a.tar.gz | |
Address review comments.
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/models/internal_id_spec.rb | 6 | ||||
| -rw-r--r-- | spec/support/shared_examples/models/atomic_internal_id_spec.rb | 8 |
2 files changed, 10 insertions, 4 deletions
diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb index ef6db2daa95..40d777c46cc 100644 --- a/spec/models/internal_id_spec.rb +++ b/spec/models/internal_id_spec.rb @@ -41,10 +41,11 @@ describe InternalId do end it 'generates a strictly monotone, gapless sequence' do - seq = (0..rand(1000)).map do + seq = (0..rand(100)).map do described_class.generate_next(issue, scope, usage, init) end normalized = seq.map { |i| i - seq.min } + expect(normalized).to eq((0..seq.size - 1).to_a) end @@ -58,6 +59,7 @@ describe InternalId do it 'calculates next internal ids on the fly' do val = rand(1..100) + expect(init).to receive(:call).with(issue).and_return(val) expect(subject).to eq(val + 1) end @@ -70,11 +72,13 @@ describe InternalId do it 'returns incremented iid' do value = id.last_value + expect(subject).to eq(value + 1) end it 'saves the record' do subject + expect(id.changed?).to be_falsey 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 671aa314bd6..144af4fc475 100644 --- a/spec/support/shared_examples/models/atomic_internal_id_spec.rb +++ b/spec/support/shared_examples/models/atomic_internal_id_spec.rb @@ -24,14 +24,16 @@ shared_examples_for 'AtomicInternalId' do it 'calls InternalId.generate_next and sets internal id attribute' do iid = rand(1..1000) + expect(InternalId).to receive(:generate_next).with(instance, scope_attrs, usage, any_args).and_return(iid) subject - expect(instance.public_send(internal_id_attribute)).to eq(iid) # rubocop:disable GitlabSecurity/PublicSend + expect(instance.public_send(internal_id_attribute)).to eq(iid) end it 'does not overwrite an existing internal id' do - instance.public_send("#{internal_id_attribute}=", 4711) # rubocop:disable GitlabSecurity/PublicSend - expect { subject }.not_to change { instance.public_send(internal_id_attribute) } # rubocop:disable GitlabSecurity/PublicSend + instance.public_send("#{internal_id_attribute}=", 4711) + + expect { subject }.not_to change { instance.public_send(internal_id_attribute) } end end end |
