diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-17 03:09:59 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-17 03:09:59 +0000 |
commit | e4f83735edac4909ea540472c34afcd4d359f252 (patch) | |
tree | 4552716142c900194e4143850d16aed781812c80 /spec/models/project_spec.rb | |
parent | 0da14b212b7f7e73114e437a671f39f2b7e758fd (diff) | |
download | gitlab-ce-e4f83735edac4909ea540472c34afcd4d359f252.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/models/project_spec.rb')
-rw-r--r-- | spec/models/project_spec.rb | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index ebadbb617fc..7eb02749f72 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1661,6 +1661,45 @@ RSpec.describe Project, factory_default: :keep do end end + describe '.find_by_url' do + subject { described_class.find_by_url(url) } + + let_it_be(:project) { create(:project) } + + before do + stub_config_setting(host: 'gitlab.com') + end + + context 'url is internal' do + let(:url) { "https://#{Gitlab.config.gitlab.host}/#{path}" } + + context 'path is recognised as a project path' do + let(:path) { project.full_path } + + it { is_expected.to eq(project) } + + it 'returns nil if the path detection throws an error' do + expect(Rails.application.routes).to receive(:recognize_path).with(url) { raise ActionController::RoutingError, 'test' } + + expect { subject }.not_to raise_error(ActionController::RoutingError) + expect(subject).to be_nil + end + end + + context 'path is not a project path' do + let(:path) { 'probably/missing.git' } + + it { is_expected.to be_nil } + end + end + + context 'url is external' do + let(:url) { "https://foo.com/bar/baz.git" } + + it { is_expected.to be_nil } + end + end + context 'repository storage by default' do let(:project) { build(:project) } |