diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-04-16 14:18:39 +0300 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-04-16 14:18:39 +0300 |
commit | 4fcee58636259e523a0e1b85e2090160a3938496 (patch) | |
tree | 02c6031f12ab2129fdd0e7686a6541b9c4a66cef /spec/lib | |
parent | 218b55dec9b0bc8926ded62a4f046fbea2c78cf3 (diff) | |
parent | c4e4258721ae08718a69d73e5046119e4db2f5ef (diff) |
Merge branch 'ab-45247-project-lookups-validation' into 'master'
Validate project path prior to hitting the database.
Closes #45247
See merge request gitlab-org/gitlab-ce!18322
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/api/helpers_spec.rb | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/spec/lib/api/helpers_spec.rb b/spec/lib/api/helpers_spec.rb index 3c4deba4712..58a49124ce6 100644 --- a/spec/lib/api/helpers_spec.rb +++ b/spec/lib/api/helpers_spec.rb @@ -3,6 +3,48 @@ require 'spec_helper' describe API::Helpers do subject { Class.new.include(described_class).new } + describe '#find_project' do + let(:project) { create(:project) } + + shared_examples 'project finder' do + context 'when project exists' do + it 'returns requested project' do + expect(subject.find_project(existing_id)).to eq(project) + end + + it 'returns nil' do + expect(subject.find_project(non_existing_id)).to be_nil + end + end + end + + context 'when ID is used as an argument' do + let(:existing_id) { project.id } + let(:non_existing_id) { (Project.maximum(:id) || 0) + 1 } + + it_behaves_like 'project finder' + end + + context 'when PATH is used as an argument' do + let(:existing_id) { project.full_path } + let(:non_existing_id) { 'something/else' } + + it_behaves_like 'project finder' + + context 'with an invalid PATH' do + let(:non_existing_id) { 'undefined' } # path without slash + + it_behaves_like 'project finder' + + it 'does not hit the database' do + expect(Project).not_to receive(:find_by_full_path) + + subject.find_project(non_existing_id) + end + end + end + end + describe '#find_namespace' do let(:namespace) { create(:namespace) } |