diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/lib/gitlab/global_id_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/lib/gitlab/global_id_spec.rb')
-rw-r--r-- | spec/lib/gitlab/global_id_spec.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/spec/lib/gitlab/global_id_spec.rb b/spec/lib/gitlab/global_id_spec.rb index 719743ed5dc..3fc18858eee 100644 --- a/spec/lib/gitlab/global_id_spec.rb +++ b/spec/lib/gitlab/global_id_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Gitlab::GlobalId do +RSpec.describe Gitlab::GlobalId do describe '.build' do let_it_be(:object) { create(:issue) } @@ -34,4 +34,37 @@ describe Gitlab::GlobalId do expect { described_class.build }.to raise_error(URI::InvalidComponentError) end end + + describe '.as_global_id' do + let(:project) { build_stubbed(:project) } + + it 'is the identify function on GlobalID instances' do + gid = project.to_global_id + + expect(described_class.as_global_id(gid)).to eq(gid) + end + + it 'wraps URI::GID in GlobalID' do + uri = described_class.build(model_name: 'Foo', id: 1) + + expect(described_class.as_global_id(uri)).to eq(GlobalID.new(uri)) + end + + it 'cannot coerce Integers without a model name' do + expect { described_class.as_global_id(1) } + .to raise_error(described_class::CoerceError, 'Cannot coerce Integer') + end + + it 'can coerce Integers with a model name' do + uri = described_class.build(model_name: 'Foo', id: 1) + + expect(described_class.as_global_id(1, model_name: 'Foo')).to eq(GlobalID.new(uri)) + end + + it 'rejects any other value' do + [:symbol, 'string', nil, [], {}, project].each do |value| + expect { described_class.as_global_id(value) }.to raise_error(described_class::CoerceError) + end + end + end end |