summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/project_search_results_spec.rb
diff options
context:
space:
mode:
authorFrancisco Javier López <fjlopez@gitlab.com>2018-07-20 13:49:30 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-07-20 13:49:30 +0000
commit6354d55470990f2eb65e8934be9072d0ff7c441a (patch)
tree1828367d8853eb00831a013ccc2b5d79a014d157 /spec/lib/gitlab/project_search_results_spec.rb
parent1484ed412ec2b38098f437931b1062191e91f655 (diff)
downloadgitlab-ce-6354d55470990f2eb65e8934be9072d0ff7c441a.tar.gz
Fixing bug with wiki ref in ProjectSearchResults
Diffstat (limited to 'spec/lib/gitlab/project_search_results_spec.rb')
-rw-r--r--spec/lib/gitlab/project_search_results_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/lib/gitlab/project_search_results_spec.rb b/spec/lib/gitlab/project_search_results_spec.rb
index 767a3092c73..4a0dc3686ec 100644
--- a/spec/lib/gitlab/project_search_results_spec.rb
+++ b/spec/lib/gitlab/project_search_results_spec.rb
@@ -64,6 +64,49 @@ describe Gitlab::ProjectSearchResults do
end
end
+ shared_examples 'blob search repository ref' do |entity_type|
+ let(:query) { 'files' }
+ let(:file_finder) { double }
+ let(:project_branch) { 'project_branch' }
+
+ subject(:results) { described_class.new(user, project, query, repository_ref).objects(blob_type) }
+
+ before do
+ allow(entity).to receive(:default_branch).and_return(project_branch)
+ allow(file_finder).to receive(:find).and_return([])
+ end
+
+ context 'when repository_ref exists' do
+ let(:repository_ref) { 'ref_branch' }
+
+ it 'uses it' do
+ expect(Gitlab::FileFinder).to receive(:new).with(project, repository_ref).and_return(file_finder)
+
+ results
+ end
+ end
+
+ context 'when repository_ref is not present' do
+ let(:repository_ref) { nil }
+
+ it "uses #{entity_type} repository default reference" do
+ expect(Gitlab::FileFinder).to receive(:new).with(project, project_branch).and_return(file_finder)
+
+ results
+ end
+ end
+
+ context 'when repository_ref is blank' do
+ let(:repository_ref) { '' }
+
+ it "uses #{entity_type} repository default reference" do
+ expect(Gitlab::FileFinder).to receive(:new).with(project, project_branch).and_return(file_finder)
+
+ results
+ end
+ end
+ end
+
describe 'blob search' do
let(:project) { create(:project, :public, :repository) }
@@ -75,6 +118,11 @@ describe Gitlab::ProjectSearchResults do
let(:expected_file_by_content) { 'CHANGELOG' }
end
+ it_behaves_like 'blob search repository ref', 'project' do
+ let(:blob_type) { 'blobs' }
+ let(:entity) { project }
+ end
+
describe 'parsing results' do
let(:results) { project.repository.search_files_by_content('feature', 'master') }
let(:search_result) { results.first }
@@ -212,6 +260,11 @@ describe Gitlab::ProjectSearchResults do
let(:expected_file_by_name) { 'Files/Title.md' }
let(:expected_file_by_content) { 'CHANGELOG.md' }
end
+
+ it_behaves_like 'blob search repository ref', 'wiki' do
+ let(:blob_type) { 'wiki_blobs' }
+ let(:entity) { project.wiki }
+ end
end
it 'does not list issues on private projects' do