Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
00f94399
Commit
00f94399
authored
Sep 22, 2020
by
Zack Cuddy
Committed by
Michael Kozono
Sep 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Global Search - Bold Issue Search Term
This adds a method to bold the search term on the issues results page.
parent
1f859f89
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
139 additions
and
38 deletions
+139
-38
app/controllers/projects/settings/ci_cd_controller.rb
app/controllers/projects/settings/ci_cd_controller.rb
+6
-0
app/controllers/search_controller.rb
app/controllers/search_controller.rb
+1
-0
app/helpers/blob_helper.rb
app/helpers/blob_helper.rb
+0
-6
app/helpers/search_helper.rb
app/helpers/search_helper.rb
+7
-0
app/services/search_service.rb
app/services/search_service.rb
+4
-0
app/views/projects/settings/ci_cd/_badge.html.haml
app/views/projects/settings/ci_cd/_badge.html.haml
+3
-3
app/views/search/results/_issue.html.haml
app/views/search/results/_issue.html.haml
+5
-3
changelogs/unreleased/244427-bold-search-term-issues.yml
changelogs/unreleased/244427-bold-search-term-issues.yml
+5
-0
ee/lib/elastic/latest/application_class_proxy.rb
ee/lib/elastic/latest/application_class_proxy.rb
+7
-1
ee/lib/gitlab/elastic/search_results.rb
ee/lib/gitlab/elastic/search_results.rb
+19
-0
ee/lib/gitlab/elastic/snippet_search_results.rb
ee/lib/gitlab/elastic/snippet_search_results.rb
+4
-0
ee/spec/lib/gitlab/elastic/search_results_spec.rb
ee/spec/lib/gitlab/elastic/search_results_spec.rb
+37
-11
ee/spec/lib/gitlab/elastic/snippet_search_results_spec.rb
ee/spec/lib/gitlab/elastic/snippet_search_results_spec.rb
+7
-0
lib/gitlab/search_results.rb
lib/gitlab/search_results.rb
+5
-0
spec/features/projects/badges/list_spec.rb
spec/features/projects/badges/list_spec.rb
+4
-4
spec/helpers/blob_helper_spec.rb
spec/helpers/blob_helper_spec.rb
+0
-10
spec/lib/gitlab/search_results_spec.rb
spec/lib/gitlab/search_results_spec.rb
+19
-0
spec/lib/gitlab/snippet_search_results_spec.rb
spec/lib/gitlab/snippet_search_results_spec.rb
+6
-0
No files found.
app/controllers/projects/settings/ci_cd_controller.rb
View file @
00f94399
...
@@ -11,6 +11,8 @@ module Projects
...
@@ -11,6 +11,8 @@ module Projects
push_frontend_feature_flag
(
:ci_key_autocomplete
,
default_enabled:
true
)
push_frontend_feature_flag
(
:ci_key_autocomplete
,
default_enabled:
true
)
end
end
helper_method
:highlight_badge
def
show
def
show
end
end
...
@@ -50,6 +52,10 @@ module Projects
...
@@ -50,6 +52,10 @@ module Projects
private
private
def
highlight_badge
(
name
,
content
,
language
=
nil
)
Gitlab
::
Highlight
.
highlight
(
name
,
content
,
language:
language
)
end
def
update_params
def
update_params
params
.
require
(
:project
).
permit
(
*
permitted_project_params
)
params
.
require
(
:project
).
permit
(
*
permitted_project_params
)
end
end
...
...
app/controllers/search_controller.rb
View file @
00f94399
...
@@ -38,6 +38,7 @@ class SearchController < ApplicationController
...
@@ -38,6 +38,7 @@ class SearchController < ApplicationController
@show_snippets
=
search_service
.
show_snippets?
@show_snippets
=
search_service
.
show_snippets?
@search_results
=
search_service
.
search_results
@search_results
=
search_service
.
search_results
@search_objects
=
search_service
.
search_objects
(
preload_method
)
@search_objects
=
search_service
.
search_objects
(
preload_method
)
@search_highlight
=
search_service
.
search_highlight
render_commits
if
@scope
==
'commits'
render_commits
if
@scope
==
'commits'
eager_load_user_status
if
@scope
==
'users'
eager_load_user_status
if
@scope
==
'users'
...
...
app/helpers/blob_helper.rb
View file @
00f94399
# frozen_string_literal: true
# frozen_string_literal: true
module
BlobHelper
module
BlobHelper
def
highlight
(
file_name
,
file_content
,
language:
nil
,
plain:
false
)
highlighted
=
Gitlab
::
Highlight
.
highlight
(
file_name
,
file_content
,
plain:
plain
,
language:
language
)
raw
%(<pre class="code highlight"><code>#{highlighted}</code></pre>)
end
def
no_highlight_files
def
no_highlight_files
%w(credits changelog news copying copyright license authors)
%w(credits changelog news copying copyright license authors)
end
end
...
...
app/helpers/search_helper.rb
View file @
00f94399
...
@@ -294,6 +294,13 @@ module SearchHelper
...
@@ -294,6 +294,13 @@ module SearchHelper
sanitize
(
html
,
tags:
%w(a p ol ul li pre code)
)
sanitize
(
html
,
tags:
%w(a p ol ul li pre code)
)
end
end
def
simple_search_highlight_and_truncate
(
text
,
phrase
,
options
=
{})
truncate_length
=
options
.
delete
(
:length
)
{
200
}
text
=
truncate
(
text
,
length:
truncate_length
)
phrase
=
phrase
.
split
highlight
(
text
,
phrase
,
options
)
end
def
show_user_search_tab?
def
show_user_search_tab?
return
false
if
Feature
.
disabled?
(
:users_search
,
default_enabled:
true
)
return
false
if
Feature
.
disabled?
(
:users_search
,
default_enabled:
true
)
...
...
app/services/search_service.rb
View file @
00f94399
...
@@ -65,6 +65,10 @@ class SearchService
...
@@ -65,6 +65,10 @@ class SearchService
@search_objects
||=
redact_unauthorized_results
(
search_results
.
objects
(
scope
,
page:
params
[
:page
],
per_page:
per_page
,
preload_method:
preload_method
))
@search_objects
||=
redact_unauthorized_results
(
search_results
.
objects
(
scope
,
page:
params
[
:page
],
per_page:
per_page
,
preload_method:
preload_method
))
end
end
def
search_highlight
search_results
.
highlight_map
(
scope
)
end
private
private
def
per_page
def
per_page
...
...
app/views/projects/settings/ci_cd/_badge.html.haml
View file @
00f94399
...
@@ -15,18 +15,18 @@
...
@@ -15,18 +15,18 @@
.col-md-2.text-center
.col-md-2.text-center
Markdown
Markdown
.col-md-10.code.js-syntax-highlight
.col-md-10.code.js-syntax-highlight
=
highlight
(
'.md'
,
badge
.
to_markdown
,
language:
'markdown'
)
=
highlight
_badge
(
'.md'
,
badge
.
to_markdown
,
language:
'markdown'
)
.row
.row
%hr
%hr
.row
.row
.col-md-2.text-center
.col-md-2.text-center
HTML
HTML
.col-md-10.code.js-syntax-highlight
.col-md-10.code.js-syntax-highlight
=
highlight
(
'.html'
,
badge
.
to_html
,
language:
'html'
)
=
highlight
_badge
(
'.html'
,
badge
.
to_html
,
language:
'html'
)
.row
.row
%hr
%hr
.row
.row
.col-md-2.text-center
.col-md-2.text-center
AsciiDoc
AsciiDoc
.col-md-10.code.js-syntax-highlight
.col-md-10.code.js-syntax-highlight
=
highlight
(
'.adoc'
,
badge
.
to_asciidoc
)
=
highlight
_badge
(
'.adoc'
,
badge
.
to_asciidoc
)
app/views/search/results/_issue.html.haml
View file @
00f94399
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
%span
.term.str-truncated.gl-font-weight-bold.gl-ml-2
=
issue
.
title
%span
.term.str-truncated.gl-font-weight-bold.gl-ml-2
=
issue
.
title
.gl-text-gray-500.gl-my-3
.gl-text-gray-500.gl-my-3
=
sprintf
(
s_
(
' %{project_name}#%{issue_iid} · opened %{issue_created} by %{author}'
),
{
project_name:
issue
.
project
.
full_name
,
issue_iid:
issue
.
iid
,
issue_created:
time_ago_with_tooltip
(
issue
.
created_at
,
placement:
'bottom'
),
author:
link_to_member
(
@project
,
issue
.
author
,
avatar:
false
)
}).
html_safe
=
sprintf
(
s_
(
' %{project_name}#%{issue_iid} · opened %{issue_created} by %{author}'
),
{
project_name:
issue
.
project
.
full_name
,
issue_iid:
issue
.
iid
,
issue_created:
time_ago_with_tooltip
(
issue
.
created_at
,
placement:
'bottom'
),
author:
link_to_member
(
@project
,
issue
.
author
,
avatar:
false
)
}).
html_safe
-
if
issue
.
description
.
present?
.description.term.col-sm-10.gl-px-0
.description.term.col-sm-10.gl-px-0
-
if
search_service
.
use_elasticsearch?
&&
@search_highlight
[
issue
.
id
]
&
.
description
.
present?
=
truncate
(
issue
.
description
,
length:
200
)
=
Truncato
.
truncate
(
@search_highlight
[
issue
.
id
].
description
.
first
,
count_tags:
false
,
count_tail:
false
,
max_length:
200
).
html_safe
-
elsif
issue
.
description
.
present?
=
simple_search_highlight_and_truncate
(
issue
.
description
,
@search_term
,
highlighter:
'<span class="gl-text-black-normal gl-font-weight-bold">\1</span>'
)
changelogs/unreleased/244427-bold-search-term-issues.yml
0 → 100644
View file @
00f94399
---
title
:
Global Search - Bold Issue's Search Term
merge_request
:
41411
author
:
type
:
changed
ee/lib/elastic/latest/application_class_proxy.rb
View file @
00f94399
...
@@ -44,7 +44,13 @@ module Elastic
...
@@ -44,7 +44,13 @@ module Elastic
memo
[
field
.
to_sym
]
=
{}
memo
[
field
.
to_sym
]
=
{}
end
end
{
fields:
es_fields
}
# Adding number_of_fragments: 0 to not split results into snippets. This way controllers can decide how to handle the highlighted data.
{
fields:
es_fields
,
number_of_fragments:
0
,
pre_tags:
[
'<span class="gl-text-black-normal gl-font-weight-bold">'
],
post_tags:
[
'</span>'
]
}
end
end
def
basic_query_hash
(
fields
,
query
)
def
basic_query_hash
(
fields
,
query
)
...
...
ee/lib/gitlab/elastic/search_results.rb
View file @
00f94399
...
@@ -46,6 +46,25 @@ module Gitlab
...
@@ -46,6 +46,25 @@ module Gitlab
end
end
end
end
# Pull the highlight attribute out of Elasticsearch results
# and map it to the result id
def
highlight_map
(
scope
)
results
=
case
scope
when
'projects'
projects
when
'issues'
issues
when
'merge_requests'
merge_requests
when
'milestones'
milestones
when
'notes'
notes
end
results
.
to_h
{
|
x
|
[
x
[
:_source
][
:id
],
x
[
:highlight
]]
}
if
results
.
present?
end
def
formatted_count
(
scope
)
def
formatted_count
(
scope
)
case
scope
case
scope
when
'projects'
when
'projects'
...
...
ee/lib/gitlab/elastic/snippet_search_results.rb
View file @
00f94399
...
@@ -16,6 +16,10 @@ module Gitlab
...
@@ -16,6 +16,10 @@ module Gitlab
limited_snippet_titles_count
limited_snippet_titles_count
end
end
def
highlight_map
(
scope
)
snippet_titles
.
to_h
{
|
x
|
[
x
[
:_source
][
:id
],
x
[
:highlight
]]
}
end
private
private
def
snippet_titles
def
snippet_titles
...
...
ee/spec/lib/gitlab/elastic/search_results_spec.rb
View file @
00f94399
...
@@ -12,6 +12,32 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -12,6 +12,32 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
let
(
:project_2
)
{
create
(
:project
,
:public
,
:repository
,
:wiki_repo
)
}
let
(
:project_2
)
{
create
(
:project
,
:public
,
:repository
,
:wiki_repo
)
}
let
(
:limit_project_ids
)
{
[
project_1
.
id
]
}
let
(
:limit_project_ids
)
{
[
project_1
.
id
]
}
describe
'#highlight_map'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:results
)
{
described_class
.
new
(
user
,
'hello world'
,
limit_project_ids
)
}
where
(
:scope
,
:results_method
,
:expected
)
do
'projects'
|
:projects
|
{
1
=>
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
}
'milestones'
|
:milestones
|
{
1
=>
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
}
'notes'
|
:notes
|
{
1
=>
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
}
'issues'
|
:issues
|
{
1
=>
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
}
'merge_requests'
|
:merge_requests
|
{
1
=>
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
}
'blobs'
|
nil
|
nil
'wiki_blobs'
|
nil
|
nil
'commits'
|
nil
|
nil
'users'
|
nil
|
nil
'unknown'
|
nil
|
nil
end
with_them
do
it
'returns the expected highlight map'
do
expect
(
results
).
to
receive
(
results_method
).
and_return
([{
_source:
{
id:
1
},
highlight:
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
}])
if
results_method
expect
(
results
.
highlight_map
(
scope
)).
to
eq
(
expected
)
end
end
end
describe
'#formatted_count'
do
describe
'#formatted_count'
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
...
@@ -542,7 +568,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -542,7 +568,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
describe
'
B
lobs'
do
describe
'
b
lobs'
do
before
do
before
do
project_1
.
repository
.
index_commits_and_blobs
project_1
.
repository
.
index_commits_and_blobs
...
@@ -752,7 +778,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -752,7 +778,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
describe
'
W
ikis'
do
describe
'
w
ikis'
do
let
(
:results
)
{
described_class
.
new
(
user
,
'term'
,
limit_project_ids
)
}
let
(
:results
)
{
described_class
.
new
(
user
,
'term'
,
limit_project_ids
)
}
subject
(
:wiki_blobs
)
{
results
.
objects
(
'wiki_blobs'
)
}
subject
(
:wiki_blobs
)
{
results
.
objects
(
'wiki_blobs'
)
}
...
@@ -839,7 +865,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -839,7 +865,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
describe
'
C
ommits'
do
describe
'
c
ommits'
do
before
do
before
do
project_1
.
repository
.
index_commits_and_blobs
project_1
.
repository
.
index_commits_and_blobs
ensure_elasticsearch_index!
ensure_elasticsearch_index!
...
@@ -875,7 +901,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -875,7 +901,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
describe
'
V
isibility levels'
do
describe
'
v
isibility levels'
do
let
(
:internal_project
)
{
create
(
:project
,
:internal
,
:repository
,
:wiki_repo
,
description:
"Internal project"
)
}
let
(
:internal_project
)
{
create
(
:project
,
:internal
,
:repository
,
:wiki_repo
,
description:
"Internal project"
)
}
let
(
:private_project1
)
{
create
(
:project
,
:private
,
:repository
,
:wiki_repo
,
description:
"Private project"
)
}
let
(
:private_project1
)
{
create
(
:project
,
:private
,
:repository
,
:wiki_repo
,
description:
"Private project"
)
}
let
(
:private_project2
)
{
create
(
:project
,
:private
,
:repository
,
:wiki_repo
,
description:
"Private project where I'm a member"
)
}
let
(
:private_project2
)
{
create
(
:project
,
:private
,
:repository
,
:wiki_repo
,
description:
"Private project where I'm a member"
)
}
...
@@ -886,7 +912,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -886,7 +912,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
private_project2
.
project_members
.
create
(
user:
user
,
access_level:
ProjectMember
::
DEVELOPER
)
private_project2
.
project_members
.
create
(
user:
user
,
access_level:
ProjectMember
::
DEVELOPER
)
end
end
context
'
I
ssues'
do
context
'
i
ssues'
do
it
'finds right set of issues'
do
it
'finds right set of issues'
do
issue_1
=
create
:issue
,
project:
internal_project
,
title:
"Internal project"
issue_1
=
create
:issue
,
project:
internal_project
,
title:
"Internal project"
create
:issue
,
project:
private_project1
,
title:
"Private project"
create
:issue
,
project:
private_project1
,
title:
"Private project"
...
@@ -913,7 +939,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -913,7 +939,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
context
'
M
ilestones'
do
context
'
m
ilestones'
do
let!
(
:milestone_1
)
{
create
(
:milestone
,
project:
internal_project
,
title:
"Internal project"
)
}
let!
(
:milestone_1
)
{
create
(
:milestone
,
project:
internal_project
,
title:
"Internal project"
)
}
let!
(
:milestone_2
)
{
create
(
:milestone
,
project:
private_project1
,
title:
"Private project"
)
}
let!
(
:milestone_2
)
{
create
(
:milestone
,
project:
private_project1
,
title:
"Private project"
)
}
let!
(
:milestone_3
)
{
create
(
:milestone
,
project:
private_project2
,
title:
"Private project which user is member"
)
}
let!
(
:milestone_3
)
{
create
(
:milestone
,
project:
private_project2
,
title:
"Private project which user is member"
)
}
...
@@ -1033,7 +1059,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -1033,7 +1059,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
context
'
P
rojects'
do
context
'
p
rojects'
do
it_behaves_like
'a paginated object'
,
'projects'
it_behaves_like
'a paginated object'
,
'projects'
it
'finds right set of projects'
do
it
'finds right set of projects'
do
...
@@ -1062,7 +1088,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -1062,7 +1088,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
context
'
Merge R
equests'
do
context
'
merge r
equests'
do
it
'finds right set of merge requests'
do
it
'finds right set of merge requests'
do
merge_request_1
=
create
:merge_request
,
target_project:
internal_project
,
source_project:
internal_project
,
title:
"Internal project"
merge_request_1
=
create
:merge_request
,
target_project:
internal_project
,
source_project:
internal_project
,
title:
"Internal project"
create
:merge_request
,
target_project:
private_project1
,
source_project:
private_project1
,
title:
"Private project"
create
:merge_request
,
target_project:
private_project1
,
source_project:
private_project1
,
title:
"Private project"
...
@@ -1089,7 +1115,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -1089,7 +1115,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
context
'
W
ikis'
do
context
'
w
ikis'
do
before
do
before
do
[
public_project
,
internal_project
,
private_project1
,
private_project2
].
each
do
|
project
|
[
public_project
,
internal_project
,
private_project1
,
private_project2
].
each
do
|
project
|
project
.
wiki
.
create_page
(
'index_page'
,
'term'
)
project
.
wiki
.
create_page
(
'index_page'
,
'term'
)
...
@@ -1116,7 +1142,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -1116,7 +1142,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
context
'
C
ommits'
do
context
'
c
ommits'
do
it
'finds right set of commits'
do
it
'finds right set of commits'
do
[
internal_project
,
private_project1
,
private_project2
,
public_project
].
each
do
|
project
|
[
internal_project
,
private_project1
,
private_project2
,
public_project
].
each
do
|
project
|
project
.
repository
.
create_file
(
project
.
repository
.
create_file
(
...
@@ -1148,7 +1174,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
...
@@ -1148,7 +1174,7 @@ RSpec.describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need
end
end
end
end
context
'
B
lobs'
do
context
'
b
lobs'
do
it
'finds right set of blobs'
do
it
'finds right set of blobs'
do
[
internal_project
,
private_project1
,
private_project2
,
public_project
].
each
do
|
project
|
[
internal_project
,
private_project1
,
private_project2
,
public_project
].
each
do
|
project
|
project
.
repository
.
create_file
(
project
.
repository
.
create_file
(
...
...
ee/spec/lib/gitlab/elastic/snippet_search_results_spec.rb
View file @
00f94399
...
@@ -40,6 +40,13 @@ RSpec.describe Gitlab::Elastic::SnippetSearchResults, :elastic, :sidekiq_might_n
...
@@ -40,6 +40,13 @@ RSpec.describe Gitlab::Elastic::SnippetSearchResults, :elastic, :sidekiq_might_n
end
end
end
end
describe
'#highlight_map'
do
it
'returns the expected highlight map'
do
expect
(
results
).
to
receive
(
:snippet_titles
).
and_return
([{
_source:
{
id:
1
},
highlight:
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
}])
expect
(
results
.
highlight_map
(
'snippet_titles'
)).
to
eq
({
1
=>
'test <span class="gl-text-black-normal gl-font-weight-bold">highlight</span>'
})
end
end
context
'when user is not author'
do
context
'when user is not author'
do
let
(
:results
)
{
described_class
.
new
(
create
(
:user
),
'foo'
,
[])
}
let
(
:results
)
{
described_class
.
new
(
create
(
:user
),
'foo'
,
[])
}
...
...
lib/gitlab/search_results.rb
View file @
00f94399
...
@@ -116,6 +116,11 @@ module Gitlab
...
@@ -116,6 +116,11 @@ module Gitlab
UsersFinder
.
new
(
current_user
,
search:
query
).
execute
UsersFinder
.
new
(
current_user
,
search:
query
).
execute
end
end
# highlighting is only performed by Elasticsearch backed results
def
highlight_map
(
scope
)
{}
end
private
private
def
projects
def
projects
...
...
spec/features/projects/badges/list_spec.rb
View file @
00f94399
...
@@ -17,10 +17,10 @@ RSpec.describe 'list of badges' do
...
@@ -17,10 +17,10 @@ RSpec.describe 'list of badges' do
expect
(
page
).
to
have_content
'Markdown'
expect
(
page
).
to
have_content
'Markdown'
expect
(
page
).
to
have_content
'HTML'
expect
(
page
).
to
have_content
'HTML'
expect
(
page
).
to
have_content
'AsciiDoc'
expect
(
page
).
to
have_content
'AsciiDoc'
expect
(
page
).
to
have_css
(
'.highlight'
,
count:
3
)
expect
(
page
).
to
have_css
(
'.
js-syntax-
highlight'
,
count:
3
)
expect
(
page
).
to
have_xpath
(
"//img[@alt='pipeline status']"
)
expect
(
page
).
to
have_xpath
(
"//img[@alt='pipeline status']"
)
page
.
within
(
'.highlight'
,
match: :first
)
do
page
.
within
(
'.
js-syntax-
highlight'
,
match: :first
)
do
expect
(
page
).
to
have_content
'badges/master/pipeline.svg'
expect
(
page
).
to
have_content
'badges/master/pipeline.svg'
end
end
end
end
...
@@ -32,10 +32,10 @@ RSpec.describe 'list of badges' do
...
@@ -32,10 +32,10 @@ RSpec.describe 'list of badges' do
expect
(
page
).
to
have_content
'Markdown'
expect
(
page
).
to
have_content
'Markdown'
expect
(
page
).
to
have_content
'HTML'
expect
(
page
).
to
have_content
'HTML'
expect
(
page
).
to
have_content
'AsciiDoc'
expect
(
page
).
to
have_content
'AsciiDoc'
expect
(
page
).
to
have_css
(
'.highlight'
,
count:
3
)
expect
(
page
).
to
have_css
(
'.
js-syntax-
highlight'
,
count:
3
)
expect
(
page
).
to
have_xpath
(
"//img[@alt='coverage report']"
)
expect
(
page
).
to
have_xpath
(
"//img[@alt='coverage report']"
)
page
.
within
(
'.highlight'
,
match: :first
)
do
page
.
within
(
'.
js-syntax-
highlight'
,
match: :first
)
do
expect
(
page
).
to
have_content
'badges/master/coverage.svg'
expect
(
page
).
to
have_content
'badges/master/coverage.svg'
end
end
end
end
...
...
spec/helpers/blob_helper_spec.rb
View file @
00f94399
...
@@ -5,16 +5,6 @@ require 'spec_helper'
...
@@ -5,16 +5,6 @@ require 'spec_helper'
RSpec
.
describe
BlobHelper
do
RSpec
.
describe
BlobHelper
do
include
TreeHelper
include
TreeHelper
describe
'#highlight'
do
it
'wraps highlighted content'
do
expect
(
helper
.
highlight
(
'test.rb'
,
'52'
)).
to
eq
(
%q[<pre class="code highlight"><code><span id="LC1" class="line" lang="ruby"><span class="mi">52</span></span></code></pre>]
)
end
it
'handles plain version'
do
expect
(
helper
.
highlight
(
'test.rb'
,
'52'
,
plain:
true
)).
to
eq
(
%q[<pre class="code highlight"><code><span id="LC1" class="line" lang="">52</span></code></pre>]
)
end
end
describe
"#sanitize_svg_data"
do
describe
"#sanitize_svg_data"
do
let
(
:input_svg_path
)
{
File
.
join
(
Rails
.
root
,
'spec'
,
'fixtures'
,
'unsanitized.svg'
)
}
let
(
:input_svg_path
)
{
File
.
join
(
Rails
.
root
,
'spec'
,
'fixtures'
,
'unsanitized.svg'
)
}
let
(
:data
)
{
File
.
read
(
input_svg_path
)
}
let
(
:data
)
{
File
.
read
(
input_svg_path
)
}
...
...
spec/lib/gitlab/search_results_spec.rb
View file @
00f94399
...
@@ -58,6 +58,25 @@ RSpec.describe Gitlab::SearchResults do
...
@@ -58,6 +58,25 @@ RSpec.describe Gitlab::SearchResults do
end
end
end
end
describe
'#highlight_map'
do
using
RSpec
::
Parameterized
::
TableSyntax
where
(
:scope
,
:expected
)
do
'projects'
|
{}
'issues'
|
{}
'merge_requests'
|
{}
'milestones'
|
{}
'users'
|
{}
'unknown'
|
{}
end
with_them
do
it
'returns the expected highlight_map'
do
expect
(
results
.
highlight_map
(
scope
)).
to
eq
(
expected
)
end
end
end
describe
'#formatted_limited_count'
do
describe
'#formatted_limited_count'
do
using
RSpec
::
Parameterized
::
TableSyntax
using
RSpec
::
Parameterized
::
TableSyntax
...
...
spec/lib/gitlab/snippet_search_results_spec.rb
View file @
00f94399
...
@@ -21,6 +21,12 @@ RSpec.describe Gitlab::SnippetSearchResults do
...
@@ -21,6 +21,12 @@ RSpec.describe Gitlab::SnippetSearchResults do
end
end
end
end
describe
'#highlight_map'
do
it
'returns the expected highlight map'
do
expect
(
results
.
highlight_map
(
'snippet_titles'
)).
to
eq
({})
end
end
describe
'#objects'
do
describe
'#objects'
do
it
'uses page and per_page to paginate results'
do
it
'uses page and per_page to paginate results'
do
snippet2
=
create
(
:snippet
,
:public
,
content:
'foo'
,
file_name:
'foo'
)
snippet2
=
create
(
:snippet
,
:public
,
content:
'foo'
,
file_name:
'foo'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment