2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::GlRepository::RepoType do
|
2020-03-13 15:44:24 +05:30
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:personal_snippet) { create(:personal_snippet, author: project.owner) }
|
|
|
|
let_it_be(:project_snippet) { create(:project_snippet, project: project, author: project.owner) }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:project_path) { project.repository.full_path }
|
|
|
|
let(:wiki_path) { project.wiki.repository.full_path }
|
2020-05-24 23:13:21 +05:30
|
|
|
let(:design_path) { project.design_repository.full_path }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:personal_snippet_path) { "snippets/#{personal_snippet.id}" }
|
|
|
|
let(:project_snippet_path) { "#{project.full_path}/snippets/#{project_snippet.id}" }
|
2019-07-07 11:18:12 +05:30
|
|
|
|
|
|
|
describe Gitlab::GlRepository::PROJECT do
|
|
|
|
it_behaves_like 'a repo type' do
|
|
|
|
let(:expected_id) { project.id.to_s }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:expected_identifier) { "project-#{expected_id}" }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:expected_suffix) { '' }
|
|
|
|
let(:expected_container) { project }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:expected_repository) { expected_container.repository }
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'knows its type' do
|
2020-04-08 14:13:33 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class).not_to be_wiki
|
|
|
|
expect(described_class).to be_project
|
|
|
|
expect(described_class).not_to be_snippet
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class).not_to be_design
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks if repository path is valid' do
|
2020-04-08 14:13:33 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class.valid?(project_path)).to be_truthy
|
|
|
|
expect(described_class.valid?(wiki_path)).to be_truthy
|
|
|
|
expect(described_class.valid?(personal_snippet_path)).to be_truthy
|
|
|
|
expect(described_class.valid?(project_snippet_path)).to be_truthy
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class.valid?(design_path)).to be_truthy
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Gitlab::GlRepository::WIKI do
|
|
|
|
it_behaves_like 'a repo type' do
|
|
|
|
let(:expected_id) { project.id.to_s }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:expected_identifier) { "wiki-#{expected_id}" }
|
2020-03-13 15:44:24 +05:30
|
|
|
let(:expected_suffix) { '.wiki' }
|
|
|
|
let(:expected_container) { project }
|
2020-04-08 14:13:33 +05:30
|
|
|
let(:expected_repository) { expected_container.wiki.repository }
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
it 'knows its type' do
|
2020-04-08 14:13:33 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class).to be_wiki
|
|
|
|
expect(described_class).not_to be_project
|
|
|
|
expect(described_class).not_to be_snippet
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class).not_to be_design
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks if repository path is valid' do
|
2020-04-08 14:13:33 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class.valid?(project_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(wiki_path)).to be_truthy
|
|
|
|
expect(described_class.valid?(personal_snippet_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(project_snippet_path)).to be_falsey
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class.valid?(design_path)).to be_falsey
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe Gitlab::GlRepository::SNIPPET do
|
|
|
|
context 'when PersonalSnippet' do
|
|
|
|
it_behaves_like 'a repo type' do
|
|
|
|
let(:expected_id) { personal_snippet.id.to_s }
|
|
|
|
let(:expected_identifier) { "snippet-#{expected_id}" }
|
|
|
|
let(:expected_suffix) { '' }
|
|
|
|
let(:expected_repository) { personal_snippet.repository }
|
|
|
|
let(:expected_container) { personal_snippet }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'knows its type' do
|
2020-04-08 14:13:33 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class).to be_snippet
|
|
|
|
expect(described_class).not_to be_wiki
|
|
|
|
expect(described_class).not_to be_project
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class).not_to be_design
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks if repository path is valid' do
|
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class.valid?(project_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(wiki_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(personal_snippet_path)).to be_truthy
|
|
|
|
expect(described_class.valid?(project_snippet_path)).to be_truthy
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class.valid?(design_path)).to be_falsey
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when ProjectSnippet' do
|
|
|
|
it_behaves_like 'a repo type' do
|
|
|
|
let(:expected_id) { project_snippet.id.to_s }
|
|
|
|
let(:expected_identifier) { "snippet-#{expected_id}" }
|
|
|
|
let(:expected_suffix) { '' }
|
|
|
|
let(:expected_repository) { project_snippet.repository }
|
|
|
|
let(:expected_container) { project_snippet }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'knows its type' do
|
2020-04-08 14:13:33 +05:30
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class).to be_snippet
|
|
|
|
expect(described_class).not_to be_wiki
|
|
|
|
expect(described_class).not_to be_project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks if repository path is valid' do
|
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class.valid?(project_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(wiki_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(personal_snippet_path)).to be_truthy
|
|
|
|
expect(described_class.valid?(project_snippet_path)).to be_truthy
|
2020-05-24 23:13:21 +05:30
|
|
|
expect(described_class.valid?(design_path)).to be_falsey
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
describe Gitlab::GlRepository::DESIGN do
|
|
|
|
it_behaves_like 'a repo type' do
|
|
|
|
let(:expected_identifier) { "design-#{project.id}" }
|
|
|
|
let(:expected_id) { project.id.to_s }
|
|
|
|
let(:expected_suffix) { '.design' }
|
|
|
|
let(:expected_repository) { project.design_repository }
|
|
|
|
let(:expected_container) { project }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'knows its type' do
|
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class).to be_design
|
|
|
|
expect(described_class).not_to be_project
|
|
|
|
expect(described_class).not_to be_wiki
|
|
|
|
expect(described_class).not_to be_snippet
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'checks if repository path is valid' do
|
|
|
|
aggregate_failures do
|
|
|
|
expect(described_class.valid?(design_path)).to be_truthy
|
|
|
|
expect(described_class.valid?(project_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(wiki_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(personal_snippet_path)).to be_falsey
|
|
|
|
expect(described_class.valid?(project_snippet_path)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|