Merge branch 'fix_wiki_links' into 'master'

Fix wiki search results point to raw source

Closes https://github.com/gitlabhq/gitlabhq/issues/9581

See merge request !3138
This commit is contained in:
Robert Speicher 2016-03-17 02:58:12 +00:00
commit c280edd31c
5 changed files with 25 additions and 4 deletions

View file

@ -11,6 +11,7 @@ v 8.6.0 (unreleased)
GitLab will ask the user to create a new one upon first visit.
- Fix issue when pushing to projects ending in .wiki
- Add support for wiki with UTF-8 page names (Hiroyuki Sato)
- Fix wiki search results point to raw source (Hiroyuki Sato)
- Don't load all of GitLab in mail_room
- Update `omniauth-saml` to 1.5.0 to allow for custom response attributes to be set
- Memoize @group in Admin::GroupsController (Yatish Mehta)

View file

@ -758,12 +758,15 @@ class Repository
def parse_search_result(result)
ref = nil
filename = nil
basename = nil
startline = 0
result.each_line.each_with_index do |line, index|
if line =~ /^.*:.*:\d+:/
ref, filename, startline = line.split(':')
startline = startline.to_i - index
extname = File.extname(filename)
basename = filename.sub(/#{extname}$/, '')
break
end
end
@ -776,6 +779,7 @@ class Repository
OpenStruct.new(
filename: filename,
basename: basename,
ref: ref,
startline: startline,
data: data

View file

@ -2,9 +2,9 @@
.blob-result
.file-holder
.file-title
= link_to namespace_project_wiki_path(@project.namespace, @project, wiki_blob.filename) do
= link_to namespace_project_wiki_path(@project.namespace, @project, wiki_blob.basename) do
%i.fa.fa-file
%strong
= wiki_blob.filename
= wiki_blob.basename
.file-content.code.term
= render 'shared/file_highlight', blob: wiki_blob, first_line_number: wiki_blob.startline

View file

@ -100,7 +100,7 @@ class Spinach::Features::Search < Spinach::FeatureSteps
step 'I should see "test_wiki" link in the search results' do
page.within('.results') do
find(:css, '.search-results').should have_link 'test_wiki.md'
expect(find(:css, '.search-results')).to have_link 'test_wiki'
end
end

View file

@ -101,13 +101,29 @@ describe Repository, models: true do
end
describe 'parsing result' do
subject { repository.parse_search_result(results.first) }
subject { repository.parse_search_result(search_result) }
let(:search_result) { results.first }
it { is_expected.to be_an OpenStruct }
it { expect(subject.filename).to eq('CHANGELOG') }
it { expect(subject.basename).to eq('CHANGELOG') }
it { expect(subject.ref).to eq('master') }
it { expect(subject.startline).to eq(186) }
it { expect(subject.data.lines[2]).to eq(" - Feature: Replace teams with group membership\n") }
context "when filename has extension" do
let(:search_result) { "master:CONTRIBUTE.md:5:- [Contribute to GitLab](#contribute-to-gitlab)\n" }
it { expect(subject.filename).to eq('CONTRIBUTE.md') }
it { expect(subject.basename).to eq('CONTRIBUTE') }
end
context "when file under directory" do
let(:search_result) { "master:a/b/c.md:5:a b c\n" }
it { expect(subject.filename).to eq('a/b/c.md') }
it { expect(subject.basename).to eq('a/b/c') }
end
end
end