Fix view of notes in search results when noteable is a snippet

Also, streamline the view.

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2016-03-31 09:21:20 +02:00
parent 091b8a6ede
commit e60f034126
No known key found for this signature in database
GPG key ID: 46DF07E5CD9E96AB
4 changed files with 52 additions and 28 deletions

View file

@ -14,6 +14,9 @@ v 8.7.0 (unreleased)
- Implement 'TODOs View' as an option for dashboard preferences !3379 (Elias W.)
- Gracefully handle notes on deleted commits in merge requests (Stan Hu)
v 8.6.3 (unreleased)
- Fix Error 500 when searching for a comment in a project snippet. !3468
v 8.6.2
- Fix dropdown alignment. !3298
- Fix issuable sidebar overlaps on tablet. !3299

View file

@ -1,24 +1,20 @@
- project = note.project
- note_url = Gitlab::UrlBuilder.new(:note).build(note.id)
- noteable_identifier = note.noteable.try(:iid) || note.noteable.id
.search-result-row
%h5.note-search-caption.str-truncated
%i.fa.fa-comment
= link_to_member(project, note.author, avatar: false)
commented on
= link_to project.name_with_namespace, project
&middot;
- if note.for_commit?
= link_to project do
= project.name_with_namespace
&middot;
= link_to namespace_project_commit_path(project.namespace, project, note.commit_id, anchor: dom_id(note)) do
Commit #{truncate_sha(note.commit_id)}
= link_to "Commit #{truncate_sha(note.commit_id)}", note_url
- else
= link_to project do
= project.name_with_namespace
%span #{note.noteable_type.titleize} ##{noteable_identifier}
&middot;
%span #{note.noteable_type.titleize} ##{note.noteable.iid}
&middot;
= link_to [project.namespace.becomes(Namespace), project, note.noteable, anchor: dom_id(note)] do
= note.noteable.title
= link_to note.noteable.title, note_url
.note-search-result
.term

View file

@ -2,6 +2,7 @@ module Gitlab
class UrlBuilder
include Gitlab::Application.routes.url_helpers
include GitlabRoutingHelper
include ActionView::RecordIdentifier
def initialize(type)
@type = type
@ -37,19 +38,16 @@ module Gitlab
namespace_project_commit_url(namespace_id: note.project.namespace,
id: note.commit_id,
project_id: note.project,
anchor: "note_#{note.id}")
anchor: dom_id(note))
elsif note.for_issue?
issue = Issue.find(note.noteable_id)
issue_url(issue,
anchor: "note_#{note.id}")
issue_url(issue, anchor: dom_id(note))
elsif note.for_merge_request?
merge_request = MergeRequest.find(note.noteable_id)
merge_request_url(merge_request,
anchor: "note_#{note.id}")
merge_request_url(merge_request, anchor: dom_id(note))
elsif note.for_snippet?
snippet = Snippet.find(note.noteable_id)
project_snippet_url(snippet,
anchor: "note_#{note.id}")
project_snippet_url(snippet, anchor: dom_id(note))
end
end
end

View file

@ -1,19 +1,46 @@
require 'spec_helper'
describe "Search", feature: true do
before do
login_as :user
@project = create(:project, namespace: @user.namespace)
@project.team << [@user, :reporter]
visit search_path
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
page.within '.search-holder' do
fill_in "search", with: @project.name[0..3]
click_button "Search"
before do
login_with(user)
project.team << [user, :reporter]
visit search_path
end
describe 'searching for Projects' do
it 'finds a project' do
page.within '.search-holder' do
fill_in "search", with: project.name[0..3]
click_button "Search"
end
expect(page).to have_content project.name
end
end
it "should show project in search results" do
expect(page).to have_content @project.name
context 'search for comments' do
it 'finds a snippet' do
snippet = create(:project_snippet, :private, project: project, author: user, title: 'Some title')
note = create(:note,
noteable: snippet,
author: user,
note: 'Supercalifragilisticexpialidocious',
project: project)
# Must visit project dashboard since global search won't search
# everything (e.g. comments, snippets, etc.)
visit namespace_project_path(project.namespace, project)
page.within '.search' do
fill_in 'search', with: note.note
click_button 'Go'
end
click_link 'Comments'
expect(page).to have_link(snippet.title)
end
end
end