From 091b8a6ede2515bb555ec8662b9d933d70bda3e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 31 Mar 2016 09:20:27 +0200 Subject: [PATCH 1/2] Rename Note#for_project_snippet? to #for_snippet? MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Coutable --- app/models/note.rb | 2 +- app/services/todo_service.rb | 2 +- lib/gitlab/note_data_builder.rb | 2 +- lib/gitlab/url_builder.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/note.rb b/app/models/note.rb index b0c33f2eec5..87ced65c650 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -311,7 +311,7 @@ class Note < ActiveRecord::Base for_merge_request? && for_diff_line? end - def for_project_snippet? + def for_snippet? noteable_type == "Snippet" end diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index f2662922e90..c678c84f22c 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -123,7 +123,7 @@ class TodoService def handle_note(note, author) # Skip system notes, and notes on project snippet - return if note.system? || note.for_project_snippet? + return if note.system? || note.for_snippet? project = note.project target = note.noteable diff --git a/lib/gitlab/note_data_builder.rb b/lib/gitlab/note_data_builder.rb index 71cf6a0d886..18523e0aefe 100644 --- a/lib/gitlab/note_data_builder.rb +++ b/lib/gitlab/note_data_builder.rb @@ -41,7 +41,7 @@ module Gitlab data[:issue] = note.noteable.hook_attrs elsif note.for_merge_request? data[:merge_request] = note.noteable.hook_attrs - elsif note.for_project_snippet? + elsif note.for_snippet? data[:snippet] = note.noteable.hook_attrs end diff --git a/lib/gitlab/url_builder.rb b/lib/gitlab/url_builder.rb index 6f0d02cafd1..7486510a4af 100644 --- a/lib/gitlab/url_builder.rb +++ b/lib/gitlab/url_builder.rb @@ -46,7 +46,7 @@ module Gitlab merge_request = MergeRequest.find(note.noteable_id) merge_request_url(merge_request, anchor: "note_#{note.id}") - elsif note.for_project_snippet? + elsif note.for_snippet? snippet = Snippet.find(note.noteable_id) project_snippet_url(snippet, anchor: "note_#{note.id}") From e60f034126712b7e5a3b3ff9c5e92359aaf96e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Coutable?= Date: Thu, 31 Mar 2016 09:21:20 +0200 Subject: [PATCH 2/2] Fix view of notes in search results when noteable is a snippet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also, streamline the view. Signed-off-by: Rémy Coutable --- CHANGELOG | 3 ++ app/views/search/results/_note.html.haml | 18 ++++----- lib/gitlab/url_builder.rb | 12 +++--- spec/features/search_spec.rb | 47 +++++++++++++++++++----- 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 25eeb24b499..f693d6b1d13 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/app/views/search/results/_note.html.haml b/app/views/search/results/_note.html.haml index 5fcba2b7e93..9544e3d3e17 100644 --- a/app/views/search/results/_note.html.haml +++ b/app/views/search/results/_note.html.haml @@ -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 + · - if note.for_commit? - = link_to project do - = project.name_with_namespace - · - = 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} · - %span #{note.noteable_type.titleize} ##{note.noteable.iid} - · - = 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 diff --git a/lib/gitlab/url_builder.rb b/lib/gitlab/url_builder.rb index 7486510a4af..e157bb96f2a 100644 --- a/lib/gitlab/url_builder.rb +++ b/lib/gitlab/url_builder.rb @@ -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 diff --git a/spec/features/search_spec.rb b/spec/features/search_spec.rb index 84c036e59c0..3e6289a46b1 100644 --- a/spec/features/search_spec.rb +++ b/spec/features/search_spec.rb @@ -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