debian-mirror-gitlab/spec/lib/gitlab/gl_repository/identifier_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.2 KiB
Ruby
Raw Normal View History

2020-06-23 00:09:42 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::GlRepository::Identifier do
2020-06-23 00:09:42 +05:30
let_it_be(:project) { create(:project) }
2022-04-04 11:22:00 +05:30
let_it_be(:personal_snippet) { create(:personal_snippet, author: project.first_owner) }
let_it_be(:project_snippet) { create(:project_snippet, project: project, author: project.first_owner) }
2020-06-23 00:09:42 +05:30
describe 'project repository' do
it_behaves_like 'parsing gl_repository identifier' do
let(:record_id) { project.id }
let(:identifier) { "project-#{record_id}" }
let(:expected_container) { project }
let(:expected_type) { Gitlab::GlRepository::PROJECT }
end
2020-07-28 23:09:34 +05:30
pending 'https://gitlab.com/gitlab-org/gitlab/-/issues/219192' do
it_behaves_like 'parsing gl_repository identifier' do
let(:record_id) { project.id }
let(:identifier) { "project-#{record_id}-code" }
let(:expected_container) { project }
let(:expected_type) { Gitlab::GlRepository::PROJECT }
end
end
it_behaves_like 'parsing gl_repository identifier' do
let(:identifier) { "project-1000000" }
let(:expected_container) { nil }
let(:expected_type) { Gitlab::GlRepository::PROJECT }
end
2020-06-23 00:09:42 +05:30
end
describe 'wiki' do
it_behaves_like 'parsing gl_repository identifier' do
let(:record_id) { project.id }
let(:identifier) { "wiki-#{record_id}" }
2021-01-03 14:25:43 +05:30
let(:expected_container) { project.wiki }
2020-06-23 00:09:42 +05:30
let(:expected_type) { Gitlab::GlRepository::WIKI }
end
2020-07-28 23:09:34 +05:30
it_behaves_like 'parsing gl_repository identifier' do
let(:record_id) { project.id }
let(:identifier) { "project-#{record_id}-wiki" }
2021-01-03 14:25:43 +05:30
let(:expected_container) { project.wiki }
2020-07-28 23:09:34 +05:30
let(:expected_type) { Gitlab::GlRepository::WIKI }
end
2020-06-23 00:09:42 +05:30
end
describe 'snippet' do
context 'when PersonalSnippet' do
it_behaves_like 'parsing gl_repository identifier' do
let(:record_id) { personal_snippet.id }
let(:identifier) { "snippet-#{record_id}" }
let(:expected_container) { personal_snippet }
let(:expected_type) { Gitlab::GlRepository::SNIPPET }
end
end
context 'when ProjectSnippet' do
it_behaves_like 'parsing gl_repository identifier' do
let(:record_id) { project_snippet.id }
let(:identifier) { "snippet-#{record_id}" }
let(:expected_container) { project_snippet }
let(:expected_type) { Gitlab::GlRepository::SNIPPET }
end
end
end
describe 'design' do
it_behaves_like 'parsing gl_repository identifier' do
let(:record_id) { project.id }
let(:identifier) { "design-#{project.id}" }
let(:expected_container) { project }
let(:expected_type) { Gitlab::GlRepository::DESIGN }
end
end
2020-07-28 23:09:34 +05:30
context 'when the format is incorrect' do
where(:identifier) do
[
'wiki-noid',
'foo-2',
'project-0',
'2-project',
'snippet-2-wiki',
'project-wibble-wiki',
'wiki-1-project',
'snippet',
2021-01-03 14:25:43 +05:30
'project-1-wiki-bar',
'project-1-project'
2020-07-28 23:09:34 +05:30
]
2020-06-23 00:09:42 +05:30
end
2020-07-28 23:09:34 +05:30
with_them do
it 'raises InvalidIdentifier' do
expect { described_class.parse(identifier) }.to raise_error(described_class::InvalidIdentifier)
end
2020-06-23 00:09:42 +05:30
end
end
end