Commit 9c12f527 authored by Markus Koller's avatar Markus Koller

Don't store full blob path in ES filename field

This verifies the changed indexer behaviour from
https://gitlab.com/gitlab-org/gitlab-elasticsearch-indexer/merge_requests/44

We're also renaming the blob-related code to use `path` rather than
`filename`, to be consistent with the `Path` field in the ES index,
and the intention of this code (which deals with full paths, rather
than just filenames).

This also removes the `Elasticsearch::Git::LiteBlob` class, which isn't
used anymore and a leftover from the Ruby indexer which was removed in
https://gitlab.com/gitlab-org/gitlab/merge_requests/15641
parent 17a7203c
......@@ -96,8 +96,9 @@ module SearchHelper
result
end
def search_blob_title(project, filename)
filename
# Overriden in EE
def search_blob_title(project, path)
path
end
def search_service
......
......@@ -2,6 +2,6 @@
- return unless project
- blob = parse_search_result(blob)
- blob_link = project_blob_path(project, tree_join(blob.ref, blob.filename))
- blob_link = project_blob_path(project, tree_join(blob.ref, blob.path))
= render partial: 'search/results/blob_data', locals: { blob: blob, project: project, file_name: blob.filename, blob_link: blob_link }
= render partial: 'search/results/blob_data', locals: { blob: blob, project: project, path: blob.path, blob_link: blob_link }
......@@ -4,7 +4,7 @@
= link_to blob_link do
%i.fa.fa-file
%strong
= search_blob_title(project, file_name)
= search_blob_title(project, path)
- if blob.data
.file-content.code.term{ data: { qa_selector: 'file_text_content' } }
= render 'shared/file_highlight', blob: blob, first_line_number: blob.startline
......@@ -2,4 +2,4 @@
- wiki_blob = parse_search_result(wiki_blob)
- wiki_blob_link = project_wiki_path(project, wiki_blob.basename)
= render partial: 'search/results/blob_data', locals: { blob: wiki_blob, project: project, file_name: wiki_blob.filename, blob_link: wiki_blob_link }
= render partial: 'search/results/blob_data', locals: { blob: wiki_blob, project: project, path: wiki_blob.path, blob_link: wiki_blob_link }
......@@ -299,6 +299,7 @@ Example response:
{
"basename": "home",
"data": "hello\n\nand bye\n\nend",
"path": "home.md",
"filename": "home.md",
"id": null,
"ref": "master",
......@@ -308,6 +309,8 @@ Example response:
]
```
**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]).
### Scope: commits **(STARTER)**
This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled.
......@@ -367,6 +370,7 @@ Example response:
{
"basename": "README",
"data": "```\n\n## Installation\n\nQuick start using the [pre-built",
"path": "README.md",
"filename": "README.md",
"id": null,
"ref": "master",
......@@ -376,6 +380,8 @@ Example response:
]
```
**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]).
### Scope: users
```bash
......@@ -633,6 +639,7 @@ Example response:
{
"basename": "home",
"data": "hello\n\nand bye\n\nend",
"path": "home.md",
"filename": "home.md",
"id": null,
"ref": "master",
......@@ -642,6 +649,8 @@ Example response:
]
```
**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]).
### Scope: commits **(STARTER)**
This scope is available only if [Elasticsearch](../integration/elasticsearch.md) is enabled.
......@@ -701,6 +710,7 @@ Example response:
{
"basename": "README",
"data": "```\n\n## Installation\n\nQuick start using the [pre-built",
"path": "README.md",
"filename": "README.md",
"id": null,
"ref": "master",
......@@ -710,6 +720,8 @@ Example response:
]
```
**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]).
### Scope: users
```bash
......@@ -981,6 +993,7 @@ Example response:
{
"basename": "home",
"data": "hello\n\nand bye\n\nend",
"path": "home.md",
"filename": "home.md",
"id": null,
"ref": "master",
......@@ -990,6 +1003,8 @@ Example response:
]
```
**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]).
### Scope: commits
```bash
......@@ -1051,6 +1066,7 @@ Example response:
{
"basename": "README",
"data": "```\n\n## Installation\n\nQuick start using the [pre-built",
"path": "README.md",
"filename": "README.md",
"id": null,
"ref": "master",
......@@ -1060,6 +1076,8 @@ Example response:
]
```
**Note:** `filename` is deprecated in favor of `path`. Both return the full path of the file inside the repository, but in the future `filename` will be only the file name and not the full path (see [this issue][gitlab-34521]).
### Scope: users
```bash
......@@ -1082,3 +1100,4 @@ Example response:
```
[ce-41763]: https://gitlab.com/gitlab-org/gitlab-foss/issues/41763
[gitlab-34521]: https://gitlab.com/gitlab-org/gitlab/issues/34521
......@@ -35,11 +35,11 @@ module EE
end
override :search_blob_title
def search_blob_title(project, file_name)
def search_blob_title(project, path)
if @project
file_name
path
else
(project.full_name + ': ' + content_tag(:i, file_name)).html_safe
(project.full_name + ': ' + content_tag(:i, path)).html_safe
end
end
......
---
title: Don't store full blob path in ES filename field
merge_request: 18470
author:
type: fixed
# frozen_string_literal: true
module Elasticsearch
module Git
class LiteBlob
include ::Gitlab::BlobHelper
include Elasticsearch::Git::EncoderHelper
attr_accessor :id, :name, :path, :size, :mode, :commit_id
attr_writer :data
def initialize(repo, raw_blob_hash)
@id = raw_blob_hash[:oid]
@blob = repo.lookup(@id)
@mode = (raw_blob_hash[:mode] || raw_blob_hash[:filemode]).to_s(8)
@size = @blob.size
@path = encode!(raw_blob_hash[:path])
@name = @path.split('/').last
end
def data
@data ||= encode!(@blob.content)
end
end
end
end
......@@ -114,9 +114,9 @@ module Gitlab
def self.parse_search_result(result)
ref = result["_source"]["blob"]["commit_sha"]
filename = result["_source"]["blob"]["path"]
extname = File.extname(filename)
basename = filename.sub(/#{extname}$/, '')
path = result["_source"]["blob"]["path"]
extname = File.extname(path)
basename = path.sub(/#{extname}$/, '')
content = result["_source"]["blob"]["content"]
project_id = result['_source']['project_id'].to_i
total_lines = content.lines.size
......@@ -151,7 +151,7 @@ module Gitlab
data = content.lines[from..to]
::Gitlab::Search::FoundBlob.new(
filename: filename,
path: path,
basename: basename,
ref: ref,
startline: from + 1,
......
......@@ -74,7 +74,7 @@ describe SearchHelper do
parsed_result = helper.parse_search_result(result)
expect(parsed_result.ref). to eq('b83d6e391c22777fca1ed3012fce84f633d7fed0')
expect(parsed_result.filename).to eq('files/ruby/popen.rb')
expect(parsed_result.path).to eq('files/ruby/popen.rb')
expect(parsed_result.startline).to eq(2)
expect(parsed_result.data).to include("Popen")
end
......
......@@ -100,7 +100,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
expect(parsed).to be_kind_of(::Gitlab::Search::FoundBlob)
expect(parsed).to have_attributes(
id: nil,
filename: 'path/file.ext',
path: 'path/file.ext',
basename: 'path/file',
ref: 'sha',
startline: 2,
......
......@@ -28,8 +28,16 @@ describe Repository, :elastic do
project = create :project, :repository
index!(project)
# Finds custom-highlighting/test.gitlab-custom
expect(project.repository.search('def | popen filename:test')[:blobs][:total_count]).to eq(1)
# Should not find anything, since filename doesn't match on path
expect(project.repository.search('def | popen filename:files')[:blobs][:total_count]).to eq(0)
# Finds files/ruby/popen.rb, files/markdown/ruby-style-guide.md, files/ruby/regex.rb, files/ruby/version_info.rb
expect(project.repository.search('def | popen path:ruby')[:blobs][:total_count]).to eq(4)
# Finds files/markdown/ruby-style-guide.md
expect(project.repository.search('def | popen extension:md')[:blobs][:total_count]).to eq(1)
end
......
......@@ -81,7 +81,7 @@ describe API::Search do
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(1)
expect(json_response.first['filename']).to eq('PROCESS.md')
expect(json_response.first['path']).to eq('PROCESS.md')
end
it 'by path' do
......@@ -90,7 +90,7 @@ describe API::Search do
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(1)
json_response.each do |file|
expect(file['filename']).to match(%r[/markdown/])
expect(file['path']).to match(%r[/markdown/])
end
end
......@@ -100,7 +100,7 @@ describe API::Search do
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(3)
json_response.each do |file|
expect(file['filename']).to match(/\A.+\.md\z/)
expect(file['path']).to match(/\A.+\.md\z/)
end
end
end
......
......@@ -1737,7 +1737,12 @@ module API
class Blob < Grape::Entity
expose :basename
expose :data
expose :filename
expose :path
# TODO: :filename was renamed to :path but both still return the full path,
# in the future we can only return the filename here without the leading
# directory path.
# https://gitlab.com/gitlab-org/gitlab/issues/34521
expose :filename, &:path
expose :id
expose :ref
expose :startline
......
......@@ -15,12 +15,12 @@ module Gitlab
def find(query)
query = Gitlab::Search::Query.new(query, encode_binary: true) do
filter :filename, matcher: ->(filter, blob) { blob.binary_filename =~ /#{filter[:regex_value]}$/i }
filter :path, matcher: ->(filter, blob) { blob.binary_filename =~ /#{filter[:regex_value]}/i }
filter :extension, matcher: ->(filter, blob) { blob.binary_filename =~ /\.#{filter[:regex_value]}$/i }
filter :filename, matcher: ->(filter, blob) { blob.binary_path =~ /#{filter[:regex_value]}$/i }
filter :path, matcher: ->(filter, blob) { blob.binary_path =~ /#{filter[:regex_value]}/i }
filter :extension, matcher: ->(filter, blob) { blob.binary_path =~ /\.#{filter[:regex_value]}$/i }
end
files = find_by_filename(query.term) + find_by_content(query.term)
files = find_by_path(query.term) + find_by_content(query.term)
files = query.filter_results(files) if query.filters.any?
......@@ -35,13 +35,14 @@ module Gitlab
end
end
def find_by_filename(query)
search_filenames(query).map do |filename|
Gitlab::Search::FoundBlob.new(blob_filename: filename, project: project, ref: ref, repository: repository)
def find_by_path(query)
search_paths(query).map do |path|
Gitlab::Search::FoundBlob.new(blob_path: path, project: project, ref: ref, repository: repository)
end
end
def search_filenames(query)
# Overriden in Gitlab::WikiFileFinder
def search_paths(query)
repository.search_files_by_name(query, ref)
end
end
......
......@@ -8,20 +8,20 @@ module Gitlab
include BlobLanguageFromGitAttributes
include Gitlab::Utils::StrongMemoize
attr_reader :project, :content_match, :blob_filename
attr_reader :project, :content_match, :blob_path
FILENAME_REGEXP = /\A(?<ref>[^:]*):(?<filename>[^\x00]*)\x00/.freeze
CONTENT_REGEXP = /^(?<ref>[^:]*):(?<filename>[^\x00]*)\x00(?<startline>\d+)\x00/.freeze
PATH_REGEXP = /\A(?<ref>[^:]*):(?<path>[^\x00]*)\x00/.freeze
CONTENT_REGEXP = /^(?<ref>[^:]*):(?<path>[^\x00]*)\x00(?<startline>\d+)\x00/.freeze
def self.preload_blobs(blobs)
to_fetch = blobs.select { |blob| blob.is_a?(self) && blob.blob_filename }
to_fetch = blobs.select { |blob| blob.is_a?(self) && blob.blob_path }
to_fetch.each { |blob| blob.fetch_blob }
end
def initialize(opts = {})
@id = opts.fetch(:id, nil)
@binary_filename = opts.fetch(:filename, nil)
@binary_path = opts.fetch(:path, nil)
@binary_basename = opts.fetch(:basename, nil)
@ref = opts.fetch(:ref, nil)
@startline = opts.fetch(:startline, nil)
......@@ -34,7 +34,7 @@ module Gitlab
# Allow those to just pass project_id instead.
@project_id = opts.fetch(:project_id, nil)
@content_match = opts.fetch(:content_match, nil)
@blob_filename = opts.fetch(:blob_filename, nil)
@blob_path = opts.fetch(:blob_path, nil)
@repository = opts.fetch(:repository, nil)
end
......@@ -50,16 +50,16 @@ module Gitlab
@startline ||= parsed_content[:startline]
end
# binary_filename is used for running filters on all matches,
# for grepped results (which use content_match), we get
# filename from the beginning of the grepped result which is faster
# then parsing whole snippet
def binary_filename
@binary_filename ||= content_match ? search_result_filename : parsed_content[:binary_filename]
# binary_path is used for running filters on all matches.
# For grepped results (which use content_match), we get
# the path from the beginning of the grepped result which is faster
# than parsing the whole snippet
def binary_path
@binary_path ||= content_match ? search_result_path : parsed_content[:binary_path]
end
def filename
@filename ||= encode_utf8(@binary_filename || parsed_content[:binary_filename])
def path
@path ||= encode_utf8(@binary_path || parsed_content[:binary_path])
end
def basename
......@@ -70,10 +70,6 @@ module Gitlab
@data ||= encode_utf8(@binary_data || parsed_content[:binary_data])
end
def path
filename
end
def project_id
@project_id || @project&.id
end
......@@ -83,16 +79,16 @@ module Gitlab
end
def fetch_blob
path = [ref, blob_filename]
missing_blob = { binary_filename: blob_filename }
path = [ref, blob_path]
missing_blob = { binary_path: blob_path }
BatchLoader.for(path).batch(default_value: missing_blob) do |refs, loader|
Gitlab::Git::Blob.batch(repository, refs, blob_size_limit: 1024).each do |blob|
# if the blob couldn't be fetched for some reason,
# show at least the blob filename
# show at least the blob path
data = {
id: blob.id,
binary_filename: blob.path,
binary_path: blob.path,
binary_basename: path_without_extension(blob.path),
ref: ref,
startline: 1,
......@@ -107,8 +103,8 @@ module Gitlab
private
def search_result_filename
content_match.match(FILENAME_REGEXP) { |matches| matches[:filename] }
def search_result_path
content_match.match(PATH_REGEXP) { |matches| matches[:path] }
end
def path_without_extension(path)
......@@ -119,7 +115,7 @@ module Gitlab
strong_memoize(:parsed_content) do
if content_match
parse_search_result
elsif blob_filename
elsif blob_path
fetch_blob
else
{}
......@@ -129,7 +125,7 @@ module Gitlab
def parse_search_result
ref = nil
filename = nil
path = nil
basename = nil
data = []
......@@ -138,17 +134,17 @@ module Gitlab
content_match.each_line.each_with_index do |line, index|
prefix ||= line.match(CONTENT_REGEXP)&.tap do |matches|
ref = matches[:ref]
filename = matches[:filename]
path = matches[:path]
startline = matches[:startline]
startline = startline.to_i - index
basename = path_without_extension(filename)
basename = path_without_extension(path)
end
data << line.sub(prefix.to_s, '')
end
{
binary_filename: filename,
binary_path: path,
binary_basename: basename,
ref: ref,
startline: startline,
......
......@@ -12,12 +12,12 @@ module Gitlab
private
def search_filenames(query)
def search_paths(query)
safe_query = Regexp.escape(query.tr(' ', '-'))
safe_query = Regexp.new(safe_query, Regexp::IGNORECASE)
filenames = repository.ls_files(ref)
paths = repository.ls_files(ref)
filenames.grep(safe_query)
paths.grep(safe_query)
end
end
end
......@@ -5,6 +5,7 @@
"properties" : {
"basename": { "type": "string" },
"data": { "type": "string" },
"path": { "type": ["string"] },
"filename": { "type": ["string"] },
"id": { "type": ["string", "null"] },
"project_id": { "type": "integer" },
......@@ -12,7 +13,7 @@
"startline": { "type": "integer" }
},
"required": [
"basename", "data", "filename", "id", "ref", "startline", "project_id"
"basename", "data", "path", "filename", "id", "ref", "startline", "project_id"
],
"additionalProperties": false
}
......
......@@ -6,11 +6,11 @@ describe Gitlab::FileFinder do
subject { described_class.new(project, project.default_branch) }
it_behaves_like 'file finder' do
let(:expected_file_by_name) { 'files/images/wm.svg' }
let(:expected_file_by_path) { 'files/images/wm.svg' }
let(:expected_file_by_content) { 'CHANGELOG' }
end
it 'filters by name' do
it 'filters by filename' do
results = subject.find('files filename:wm.svg')
expect(results.count).to eq(1)
......
......@@ -79,20 +79,20 @@ describe Gitlab::ProjectSearchResults do
end
it 'finds by name' do
expect(results.map(&:filename)).to include(expected_file_by_name)
expect(results.map(&:path)).to include(expected_file_by_path)
end
it "loads all blobs for filename matches in single batch" do
it "loads all blobs for path matches in single batch" do
expect(Gitlab::Git::Blob).to receive(:batch).once.and_call_original
expected = project.repository.search_files_by_name(query, 'master')
expect(results.map(&:filename)).to include(*expected)
expect(results.map(&:path)).to include(*expected)
end
it 'finds by content' do
blob = results.select { |result| result.filename == expected_file_by_content }.flatten.last
blob = results.select { |result| result.path == expected_file_by_content }.flatten.last
expect(blob.filename).to eq(expected_file_by_content)
expect(blob.path).to eq(expected_file_by_content)
end
end
......@@ -146,7 +146,7 @@ describe Gitlab::ProjectSearchResults do
let(:blob_type) { 'blobs' }
let(:disabled_project) { create(:project, :public, :repository, :repository_disabled) }
let(:private_project) { create(:project, :public, :repository, :repository_private) }
let(:expected_file_by_name) { 'files/images/wm.svg' }
let(:expected_file_by_path) { 'files/images/wm.svg' }
let(:expected_file_by_content) { 'CHANGELOG' }
end
......@@ -169,7 +169,7 @@ describe Gitlab::ProjectSearchResults do
let(:blob_type) { 'wiki_blobs' }
let(:disabled_project) { create(:project, :public, :wiki_repo, :wiki_disabled) }
let(:private_project) { create(:project, :public, :wiki_repo, :wiki_private) }
let(:expected_file_by_name) { 'Files/Title.md' }
let(:expected_file_by_path) { 'Files/Title.md' }
let(:expected_file_by_content) { 'CHANGELOG.md' }
end
......
......@@ -15,7 +15,6 @@ describe Gitlab::Search::FoundBlob do
is_expected.to be_an described_class
expect(subject.id).to be_nil
expect(subject.path).to eq('CHANGELOG')
expect(subject.filename).to eq('CHANGELOG')
expect(subject.basename).to eq('CHANGELOG')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(188)
......@@ -25,12 +24,12 @@ describe Gitlab::Search::FoundBlob do
it 'does not parse content if not needed' do
expect(subject).not_to receive(:parse_search_result)
expect(subject.project_id).to eq(project.id)
expect(subject.binary_filename).to eq('CHANGELOG')
expect(subject.binary_path).to eq('CHANGELOG')
end
it 'parses content only once when needed' do
expect(subject).to receive(:parse_search_result).once.and_call_original
expect(subject.filename).to eq('CHANGELOG')
expect(subject.path).to eq('CHANGELOG')
expect(subject.startline).to eq(188)
end
......@@ -38,7 +37,7 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:testdata/project::function1.yaml\x001\x00---\n" }
it 'returns a valid FoundBlob' do
expect(subject.filename).to eq('testdata/project::function1.yaml')
expect(subject.path).to eq('testdata/project::function1.yaml')
expect(subject.basename).to eq('testdata/project::function1')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1)
......@@ -50,7 +49,7 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:testdata/foo.txt\x001\x00blah:9:blah" }
it 'returns a valid FoundBlob' do
expect(subject.filename).to eq('testdata/foo.txt')
expect(subject.path).to eq('testdata/foo.txt')
expect(subject.basename).to eq('testdata/foo')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1)
......@@ -62,7 +61,7 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:testdata/foo.txt\x001\x00blah\x001\x00foo" }
it 'returns a valid FoundBlob' do
expect(subject.filename).to eq('testdata/foo.txt')
expect(subject.path).to eq('testdata/foo.txt')
expect(subject.basename).to eq('testdata/foo')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1)
......@@ -74,7 +73,7 @@ describe Gitlab::Search::FoundBlob do
let(:results) { project.repository.search_files_by_content('Role models', 'master') }
it 'returns a valid FoundBlob that ends with an empty line' do
expect(subject.filename).to eq('files/markdown/ruby-style-guide.md')
expect(subject.path).to eq('files/markdown/ruby-style-guide.md')
expect(subject.basename).to eq('files/markdown/ruby-style-guide')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1)
......@@ -87,7 +86,7 @@ describe Gitlab::Search::FoundBlob do
let(:results) { project.repository.search_files_by_content('файл', 'master') }
it 'returns results as UTF-8' do
expect(subject.filename).to eq('encoding/russian.rb')
expect(subject.path).to eq('encoding/russian.rb')
expect(subject.basename).to eq('encoding/russian')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1)
......@@ -99,7 +98,7 @@ describe Gitlab::Search::FoundBlob do
let(:results) { project.repository.search_files_by_content('webhook', 'master') }
it 'returns results as UTF-8' do
expect(subject.filename).to eq('encoding/テスト.txt')
expect(subject.path).to eq('encoding/テスト.txt')
expect(subject.basename).to eq('encoding/テスト')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(3)
......@@ -111,7 +110,7 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { (+"master:encoding/iso8859.txt\x001\x00\xC4\xFC\nmaster:encoding/iso8859.txt\x002\x00\nmaster:encoding/iso8859.txt\x003\x00foo\n").force_encoding(Encoding::ASCII_8BIT) }
it 'returns results as UTF-8' do
expect(subject.filename).to eq('encoding/iso8859.txt')
expect(subject.path).to eq('encoding/iso8859.txt')
expect(subject.basename).to eq('encoding/iso8859')
expect(subject.ref).to eq('master')
expect(subject.startline).to eq(1)
......@@ -124,7 +123,6 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:CONTRIBUTE.md\x005\x00- [Contribute to GitLab](#contribute-to-gitlab)\n" }
it { expect(subject.path).to eq('CONTRIBUTE.md') }
it { expect(subject.filename).to eq('CONTRIBUTE.md') }
it { expect(subject.basename).to eq('CONTRIBUTE') }
end
......@@ -132,7 +130,6 @@ describe Gitlab::Search::FoundBlob do
let(:search_result) { "master:a/b/c.md\x005\x00a b c\n" }
it { expect(subject.path).to eq('a/b/c.md') }
it { expect(subject.filename).to eq('a/b/c.md') }
it { expect(subject.basename).to eq('a/b/c') }
end
end
......@@ -141,7 +138,7 @@ describe Gitlab::Search::FoundBlob do
context 'when file is under directory' do
let(:path) { 'a/b/c.md' }
subject { described_class.new(blob_filename: path, project: project, ref: 'master') }
subject { described_class.new(blob_path: path, project: project, ref: 'master') }
before do
allow(Gitlab::Git::Blob).to receive(:batch).and_return([
......@@ -150,7 +147,6 @@ describe Gitlab::Search::FoundBlob do
end
it { expect(subject.path).to eq('a/b/c.md') }
it { expect(subject.filename).to eq('a/b/c.md') }
it { expect(subject.basename).to eq('a/b/c') }
context 'when filename has multiple extensions' do
......
......@@ -15,7 +15,7 @@ describe Gitlab::WikiFileFinder do
it_behaves_like 'file finder' do
subject { described_class.new(project, project.wiki.default_branch) }
let(:expected_file_by_name) { 'Files/Title.md' }
let(:expected_file_by_path) { 'Files/Title.md' }
let(:expected_file_by_content) { 'CHANGELOG.md' }
end
end
......
......@@ -436,6 +436,7 @@ describe API::Search do
expect(response).to have_gitlab_http_status(200)
expect(json_response.size).to eq(2)
expect(json_response.first['path']).to eq('PROCESS.md')
expect(json_response.first['filename']).to eq('PROCESS.md')
end
......
......@@ -4,19 +4,19 @@ shared_examples 'file finder' do
let(:query) { 'files' }
let(:search_results) { subject.find(query) }
it 'finds by name' do
blob = search_results.find { |blob| blob.filename == expected_file_by_name }
it 'finds by path' do
blob = search_results.find { |blob| blob.path == expected_file_by_path }
expect(blob.filename).to eq(expected_file_by_name)
expect(blob.path).to eq(expected_file_by_path)
expect(blob).to be_a(Gitlab::Search::FoundBlob)
expect(blob.ref).to eq(subject.ref)
expect(blob.data).not_to be_empty
end
it 'finds by content' do
blob = search_results.find { |blob| blob.filename == expected_file_by_content }
blob = search_results.find { |blob| blob.path == expected_file_by_content }
expect(blob.filename).to eq(expected_file_by_content)
expect(blob.path).to eq(expected_file_by_content)
expect(blob).to be_a(Gitlab::Search::FoundBlob)
expect(blob.ref).to eq(subject.ref)
expect(blob.data).not_to be_empty
......
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