Commit d5b883e1 authored by Sean McGivern's avatar Sean McGivern

Merge branch '1567-fix-blob-highlighting-in-search' into 'master'

Resolve "Elasticsearch: Highlighting in the code results does not work"

Closes #1567

See merge request !1564
parents 37a1fd6d 44571af0
---
title: Fix blob highlighting in search
merge_request: 10420
author:
......@@ -95,7 +95,7 @@ module Gitlab
data = content.lines[from..to]
OpenStruct.new(
::Gitlab::SearchResults::FoundBlob.new(
filename: filename,
basename: basename,
ref: ref,
......
......@@ -62,7 +62,7 @@ module Gitlab
data << line.sub(ref, '').sub(filename, '').sub(/^:-\d+-/, '').sub(/^::\d+:/, '')
end
OpenStruct.new(
FoundBlob.new(
filename: filename,
basename: basename,
ref: ref,
......
module Gitlab
class SearchResults
class FoundBlob
attr_reader :id, :filename, :basename, :ref, :startline, :data
def initialize(opts = {})
@id = opts.fetch(:id, nil)
@filename = opts.fetch(:filename, nil)
@basename = opts.fetch(:basename, nil)
@ref = opts.fetch(:ref, nil)
@startline = opts.fetch(:startline, nil)
@data = opts.fetch(:data, nil)
end
def path
filename
end
def no_highlighting?
false
end
end
attr_reader :current_user, :query
# Limit search results by passed projects
......
......@@ -45,12 +45,14 @@ feature 'Global elastic search', feature: true do
it "finds files" do
visit dashboard_projects_path
fill_in "search", with: "def"
fill_in "search", with: "application.js"
click_button "Go"
select_filter("Code")
expect(page).to have_selector('.file-content .code')
expect(page).to have_selector("span.line[lang='javascript']")
end
end
......
......@@ -119,13 +119,15 @@ describe "Search", feature: true do
visit namespace_project_path(project.namespace, project)
page.within '.search' do
fill_in 'search', with: 'def'
fill_in 'search', with: 'application.js'
click_button 'Go'
end
click_link "Code"
expect(page).to have_selector('.file-content .code')
expect(page).to have_selector("span.line[lang='javascript']")
end
end
......
......@@ -42,8 +42,10 @@ describe Gitlab::ProjectSearchResults, lib: true do
subject { described_class.parse_search_result(search_result) }
it "returns a valid OpenStruct object" do
is_expected.to be_an OpenStruct
it "returns a valid FoundBlob" do
is_expected.to be_an Gitlab::SearchResults::FoundBlob
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')
......@@ -54,6 +56,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
context "when filename has extension" do
let(:search_result) { "master:CONTRIBUTE.md:5:- [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
......@@ -61,6 +64,7 @@ describe Gitlab::ProjectSearchResults, lib: true do
context "when file under directory" do
let(:search_result) { "master:a/b/c.md:5:a 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
......
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