summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2015-09-21 19:38:37 +0000
committerRobert Speicher <robert@gitlab.com>2015-09-21 19:38:37 +0000
commitd4acda1253e4059d2af6a551aa750c7df8c7dd5a (patch)
treeea439afcfc40afa1a8d7f44104f29afbb42274c8 /spec/lib
parentd4a960161eecf5730b56d3f375573fa39aa67e95 (diff)
parent2b94f5fb06ef061fb49a7dadcbb95c0954bc9860 (diff)
downloadgitlab-ce-d4acda1253e4059d2af6a551aa750c7df8c7dd5a.tar.gz
Merge branch 'rs-relative-link-up-one' into 'master'
Allow relative links to go up one directory level See merge request !1352
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/gitlab/markdown/relative_link_filter_spec.rb26
1 files changed, 22 insertions, 4 deletions
diff --git a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
index 7f4d67e403f..027336ceb73 100644
--- a/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
+++ b/spec/lib/gitlab/markdown/relative_link_filter_spec.rb
@@ -4,14 +4,16 @@ require 'spec_helper'
module Gitlab::Markdown
describe RelativeLinkFilter do
- def filter(doc)
- described_class.call(doc, {
+ def filter(doc, contexts = {})
+ contexts.reverse_merge!({
commit: project.commit,
project: project,
project_wiki: project_wiki,
ref: ref,
requested_path: requested_path
})
+
+ described_class.call(doc, contexts)
end
def image(path)
@@ -75,6 +77,22 @@ module Gitlab::Markdown
to eq "/#{project_path}/blob/#{ref}/doc/api/README.md"
end
+ it 'rebuilds relative URL for a file in the repo up one directory' do
+ relative_link = link('../api/README.md')
+ doc = filter(relative_link, requested_path: 'doc/update/7.14-to-8.0.md')
+
+ expect(doc.at_css('a')['href']).
+ to eq "/#{project_path}/blob/#{ref}/doc/api/README.md"
+ end
+
+ it 'rebuilds relative URL for a file in the repo up multiple directories' do
+ relative_link = link('../../../api/README.md')
+ doc = filter(relative_link, requested_path: 'doc/foo/bar/baz/README.md')
+
+ expect(doc.at_css('a')['href']).
+ to eq "/#{project_path}/blob/#{ref}/doc/api/README.md"
+ end
+
it 'rebuilds relative URL for a file in the repo with an anchor' do
doc = filter(link('README.md#section'))
expect(doc.at_css('a')['href']).
@@ -108,8 +126,8 @@ module Gitlab::Markdown
escaped = Addressable::URI.escape(path)
# Stub these methods so the file doesn't actually need to be in the repo
- allow_any_instance_of(described_class).to receive(:file_exists?).
- and_return(true)
+ allow_any_instance_of(described_class).
+ to receive(:file_exists?).and_return(true)
allow_any_instance_of(described_class).
to receive(:image?).with(path).and_return(true)