Commit 87ee772f authored by Valery Sizov's avatar Valery Sizov

Fix default_branch in lib/gitlab/elastic/project_search_results.rb

parent 1238b5e0
......@@ -6,8 +6,7 @@
- blob = parse_search_result(blob)
- file_name = blob.filename
- ref = @search_results.repository_ref
- blob_link = namespace_project_blob_path(project.namespace, project, tree_join(ref, file_name))
- blob_link = namespace_project_blob_path(project.namespace, project, tree_join(blob.ref, file_name))
.blob-result
.file-holder
.file-title
......@@ -19,6 +18,6 @@
- else
#{project.name_with_namespace}:
%i= file_name
- if blob
- if blob.data
.file-content.code.term
= render 'shared/file_highlight', blob: blob, first_line_number: blob.startline, blob_link: blob_link
......@@ -9,12 +9,7 @@ module Gitlab
def initialize(current_user, query, project_id, repository_ref = nil)
@current_user = current_user
@project = Project.find(project_id)
@repository_ref = if repository_ref.present?
repository_ref
else
nil
end
@repository_ref = repository_ref.presence || project.default_branch
@query = query
@public_and_internal_projects = false
end
......@@ -121,7 +116,7 @@ module Gitlab
end
def root_ref?
!repository_ref || project.root_ref?(repository_ref)
project.root_ref?(repository_ref)
end
end
end
......
......@@ -23,7 +23,7 @@ module Gitlab
end
project.repository.search_files_by_name(query, ref).first(BATCH_SIZE).each do |filename|
results << [filename, nil] unless found_file_names.include?(filename)
results << [filename, OpenStruct.new(ref: ref)] unless found_file_names.include?(filename)
end
results.sort_by(&:first)
......
......@@ -19,7 +19,7 @@ describe Gitlab::Elastic::ProjectSearchResults, lib: true do
subject(:results) { described_class.new(user, query, project.id, '') }
it { expect(results.project).to eq(project) }
it { expect(results.repository_ref).to be_nil }
it { expect(results.repository_ref).to eq('master') }
it { expect(results.query).to eq('hello world') }
end
......
......@@ -5,9 +5,10 @@ describe Gitlab::FileFinder do
let(:finder) { described_class.new(project, 'master') }
it 'finds files by name' do
result = finder.find('CHANGELOG').first
filename, blob = finder.find('CHANGELOG').first
expect(result).to match_array(['CHANGELOG', nil])
expect(filename).to eq('CHANGELOG')
expect(blob.ref).to eq('master')
end
it 'finds files by content' do
......
......@@ -25,11 +25,12 @@ describe Gitlab::ProjectSearchResults, lib: true do
let(:results) { described_class.new(user, project, 'files').objects('blobs') }
it 'finds by name' do
expect(results).to include(["files/images/wm.svg", nil])
blob = results.select { |result| result.first == 'files/images/wm.svg' }.flatten.last
expect(blob).to be_a(OpenStruct)
end
it 'finds by content' do
blob = results.select { |result| result.first == "CHANGELOG" }.flatten.last
blob = results.select { |result| result.first == 'CHANGELOG' }.flatten.last
expect(blob.filename).to eq("CHANGELOG")
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment