diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/models/internal_id_spec.rb | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/models/internal_id_spec.rb')
-rw-r--r-- | spec/models/internal_id_spec.rb | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/spec/models/internal_id_spec.rb b/spec/models/internal_id_spec.rb index 751e8724872..07f62b9de55 100644 --- a/spec/models/internal_id_spec.rb +++ b/spec/models/internal_id_spec.rb @@ -6,8 +6,9 @@ RSpec.describe InternalId do let(:project) { create(:project) } let(:usage) { :issues } let(:issue) { build(:issue, project: project) } + let(:id_subject) { issue } let(:scope) { { project: project } } - let(:init) { ->(s) { s.project.issues.size } } + let(:init) { ->(issue, scope) { issue&.project&.issues&.size || Issue.where(**scope).count } } it_behaves_like 'having unique enum values' @@ -39,7 +40,7 @@ RSpec.describe InternalId do end describe '.generate_next' do - subject { described_class.generate_next(issue, scope, usage, init) } + subject { described_class.generate_next(id_subject, scope, usage, init) } context 'in the absence of a record' do it 'creates a record if not yet present' do @@ -88,6 +89,14 @@ RSpec.describe InternalId do expect(normalized).to eq((0..seq.size - 1).to_a) end + + context 'there are no instances to pass in' do + let(:id_subject) { Issue } + + it 'accepts classes instead' do + expect(subject).to eq(1) + end + end end describe '.reset' do @@ -130,7 +139,7 @@ RSpec.describe InternalId do describe '.track_greatest' do let(:value) { 9001 } - subject { described_class.track_greatest(issue, scope, usage, value, init) } + subject { described_class.track_greatest(id_subject, scope, usage, value, init) } context 'in the absence of a record' do it 'creates a record if not yet present' do @@ -166,6 +175,14 @@ RSpec.describe InternalId do expect(subject).to eq 10_001 end end + + context 'there are no instances to pass in' do + let(:id_subject) { Issue } + + it 'accepts classes instead' do + expect(subject).to eq(value) + end + end end describe '#increment_and_save!' do |