diff options
author | Markus Koller <mkoller@gitlab.com> | 2019-06-20 15:59:58 +0300 |
---|---|---|
committer | Markus Koller <mkoller@gitlab.com> | 2019-06-20 19:05:12 +0300 |
commit | 6905a62867067f2f61feb6734be3972cb5b9f7a7 (patch) | |
tree | ea953acc268cc1c747870ee88d2892a174b65878 /spec/lib/gitlab/search | |
parent | f4605ad880e9b76c94218cb7c4f16215c4f62e8e (diff) |
Build correct basenames for title search results
The "basename" here needs to be the full path without the trailing
extension, instead of stripping the leading path as well.
This was previously fixed in 2f36efa0871 inside the view, but the
problematic code was still present in FoundBlob, and the corresponding
spec didn't actually use a child wiki page to properly verify the fix.
Diffstat (limited to 'spec/lib/gitlab/search')
-rw-r--r-- | spec/lib/gitlab/search/found_blob_spec.rb | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/spec/lib/gitlab/search/found_blob_spec.rb b/spec/lib/gitlab/search/found_blob_spec.rb index 74157e5c67c..da263bc7523 100644 --- a/spec/lib/gitlab/search/found_blob_spec.rb +++ b/spec/lib/gitlab/search/found_blob_spec.rb @@ -3,14 +3,15 @@ require 'spec_helper' describe Gitlab::Search::FoundBlob do - describe 'parsing results' do - let(:project) { create(:project, :public, :repository) } + let(:project) { create(:project, :public, :repository) } + + describe 'parsing content results' do let(:results) { project.repository.search_files_by_content('feature', 'master') } let(:search_result) { results.first } subject { described_class.new(content_match: search_result, project: project) } - it "returns a valid FoundBlob" do + it 'returns a valid FoundBlob' do is_expected.to be_an described_class expect(subject.id).to be_nil expect(subject.path).to eq('CHANGELOG') @@ -21,13 +22,13 @@ describe Gitlab::Search::FoundBlob do expect(subject.data.lines[2]).to eq(" - Feature: Replace teams with group membership\n") end - it "doesn't parses content if not needed" do + it 'does not parse content if not needed' do expect(subject).not_to receive(:parse_search_result) expect(subject.project_id).to eq(project.id) expect(subject.binary_filename).to eq('CHANGELOG') end - it "parses content only once when needed" do + it 'parses content only once when needed' do expect(subject).to receive(:parse_search_result).once.and_call_original expect(subject.filename).to eq('CHANGELOG') expect(subject.startline).to eq(188) @@ -119,7 +120,7 @@ describe Gitlab::Search::FoundBlob do end end - context "when filename has extension" do + context 'when filename has extension' do let(:search_result) { "master:CONTRIBUTE.md\x005\x00- [Contribute to GitLab](#contribute-to-gitlab)\n" } it { expect(subject.path).to eq('CONTRIBUTE.md') } @@ -127,7 +128,7 @@ describe Gitlab::Search::FoundBlob do it { expect(subject.basename).to eq('CONTRIBUTE') } end - context "when file under directory" do + context 'when file is under directory' do let(:search_result) { "master:a/b/c.md\x005\x00a b c\n" } it { expect(subject.path).to eq('a/b/c.md') } @@ -135,4 +136,28 @@ describe Gitlab::Search::FoundBlob do it { expect(subject.basename).to eq('a/b/c') } end end + + describe 'parsing title results' do + context 'when file is under directory' do + let(:path) { 'a/b/c.md' } + + subject { described_class.new(blob_filename: path, project: project, ref: 'master') } + + before do + allow(Gitlab::Git::Blob).to receive(:batch).and_return([ + Gitlab::Git::Blob.new(path: path) + ]) + end + + 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') } + + context 'when filename has multiple extensions' do + let(:path) { 'a/b/c.whatever.md' } + + it { expect(subject.basename).to eq('a/b/c.whatever') } + end + end + end end |