Welcome to mirror list, hosted at ThFree Co, Russian Federation.

global_id_spec.rb « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 719743ed5dc2f410e9e536b81388f08b992d6348 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

require 'spec_helper'

describe Gitlab::GlobalId do
  describe '.build' do
    let_it_be(:object) { create(:issue) }

    it 'returns a standard GlobalId if only object is passed' do
      expect(described_class.build(object).to_s).to eq(object.to_global_id.to_s)
    end

    it 'returns a GlobalId from params' do
      expect(described_class.build(model_name: 'MyModel', id: 'myid').to_s).to eq(
        'gid://gitlab/MyModel/myid'
      )
    end

    it 'returns a GlobalId from object and `id` param' do
      expect(described_class.build(object, id: 'myid').to_s).to eq(
        'gid://gitlab/Issue/myid'
      )
    end

    it 'returns a GlobalId from object and `model_name` param' do
      expect(described_class.build(object, model_name: 'MyModel').to_s).to eq(
        "gid://gitlab/MyModel/#{object.id}"
      )
    end

    it 'returns an error if model_name and id are not able to be determined' do
      expect { described_class.build(id: 'myid') }.to raise_error(URI::InvalidComponentError)
      expect { described_class.build(model_name: 'MyModel') }.to raise_error(URI::InvalidComponentError)
      expect { described_class.build }.to raise_error(URI::InvalidComponentError)
    end
  end
end