2019-11-07 22:06:48 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-28 12:52:09 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe ::Gitlab::GlRepository do
|
2017-04-28 12:52:09 -04:00
|
|
|
describe '.parse' do
|
2020-01-27 10:08:51 -05:00
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
2020-03-04 19:07:49 -05:00
|
|
|
let_it_be(:snippet) { create(:personal_snippet) }
|
2017-04-28 12:52:09 -04:00
|
|
|
|
|
|
|
it 'parses a project gl_repository' do
|
2020-03-04 19:07:49 -05:00
|
|
|
expect(described_class.parse("project-#{project.id}")).to eq([project, project, Gitlab::GlRepository::PROJECT])
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
|
2020-05-28 05:08:05 -04:00
|
|
|
it 'parses a project wiki gl_repository' do
|
2020-10-05 11:08:56 -04:00
|
|
|
expect(described_class.parse("wiki-#{project.id}")).to eq([project.wiki, project, Gitlab::GlRepository::WIKI])
|
2020-03-04 19:07:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'parses a snippet gl_repository' do
|
|
|
|
expect(described_class.parse("snippet-#{snippet.id}")).to eq([snippet, nil, Gitlab::GlRepository::SNIPPET])
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
|
2020-05-04 02:10:10 -04:00
|
|
|
it 'parses a design gl_repository' do
|
|
|
|
expect(described_class.parse("design-#{project.id}")).to eq([project, project, Gitlab::GlRepository::DESIGN])
|
|
|
|
end
|
|
|
|
|
2020-01-27 10:08:51 -05:00
|
|
|
it 'throws an argument error on an invalid gl_repository type' do
|
2017-04-28 12:52:09 -04:00
|
|
|
expect { described_class.parse("badformat-#{project.id}") }.to raise_error(ArgumentError)
|
|
|
|
end
|
2020-01-27 10:08:51 -05:00
|
|
|
|
|
|
|
it 'throws an argument error on an invalid gl_repository id' do
|
|
|
|
expect { described_class.parse("project-foo") }.to raise_error(ArgumentError)
|
|
|
|
end
|
2017-04-28 12:52:09 -04:00
|
|
|
end
|
|
|
|
end
|