diff options
author | Robert Speicher <robert@gitlab.com> | 2016-08-10 00:45:59 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-08-10 00:45:59 +0300 |
commit | bd1b8ae9bbbe8c81d5f1c18a5c8d86fbcb4f1dbf (patch) | |
tree | b6d8aaaf718650ac0be6cf7ef059a80465a75ed4 /spec/lib/banzai/filter/relative_link_filter_spec.rb | |
parent | 936729e5be97d88fbc927ede20ec1d4cf5fe6daa (diff) | |
parent | e63eccf9744de0965d4727326a4b30f1fe8165e8 (diff) |
Merge branch 'relative-link-filter-ref' into 'master'
Do not look up commit again when it is passed to RelativeLinkFilter
## What does this MR do?
Use `context[:commit]` in RelativeLinkFilter instead of looking up commit using `context[:ref]`.
## Why was this MR needed?
Even though the commit object was already passed, unnecessary I/O is done to retrieve the commit object.
## What are the relevant issue numbers?
Fixes #20026
See merge request !5455
Diffstat (limited to 'spec/lib/banzai/filter/relative_link_filter_spec.rb')
-rw-r--r-- | spec/lib/banzai/filter/relative_link_filter_spec.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/spec/lib/banzai/filter/relative_link_filter_spec.rb b/spec/lib/banzai/filter/relative_link_filter_spec.rb index bda8d2ce38a..6b58f3e43ee 100644 --- a/spec/lib/banzai/filter/relative_link_filter_spec.rb +++ b/spec/lib/banzai/filter/relative_link_filter_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Banzai::Filter::RelativeLinkFilter, lib: true do def filter(doc, contexts = {}) contexts.reverse_merge!({ - commit: project.commit, + commit: commit, project: project, project_wiki: project_wiki, ref: ref, @@ -28,6 +28,7 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do let(:project) { create(:project) } let(:project_path) { project.path_with_namespace } let(:ref) { 'markdown' } + let(:commit) { project.commit(ref) } let(:project_wiki) { nil } let(:requested_path) { '/' } @@ -77,7 +78,13 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do expect { filter(act) }.not_to raise_error end - context 'with a valid repository' do + it 'ignores ref if commit is passed' do + doc = filter(link('non/existent.file'), commit: project.commit('empty-branch') ) + expect(doc.at_css('a')['href']). + to eq "/#{project_path}/#{ref}/non/existent.file" # non-existent files have no leading blob/raw/tree + end + + shared_examples :valid_repository do it 'rebuilds absolute URL for a file in the repo' do doc = filter(link('/doc/api/README.md')) expect(doc.at_css('a')['href']). @@ -189,4 +196,13 @@ describe Banzai::Filter::RelativeLinkFilter, lib: true do include_examples :relative_to_requested end end + + context 'with a valid commit' do + include_examples :valid_repository + end + + context 'with a valid ref' do + let(:commit) { nil } # force filter to use ref instead of commit + include_examples :valid_repository + end end |