Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2016-06-18 11:40:40 +0300
committerTimothy Andrew <mail@timothyandrew.net>2016-06-18 11:40:40 +0300
commit6d169d36cabda783116bcb8e2e6f73254566a670 (patch)
treeaa06e870279b96dcfb3c489d65b06bad70d60dfa /spec
parent00906b5bb6cde8cb60281109060a519a54000c61 (diff)
Fix bug in `WikiLinkFilter`.
1. An exception would be raised if the filter was called with an invalid URI. Mainly because we weren't catching the `Addressable` exception. 2. This commit fixes it and adds a spec for the filter.
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/banzai/filter/wiki_link_filter_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/wiki_link_filter_spec.rb b/spec/lib/banzai/filter/wiki_link_filter_spec.rb
new file mode 100644
index 00000000000..92d88c4172c
--- /dev/null
+++ b/spec/lib/banzai/filter/wiki_link_filter_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe Banzai::Filter::WikiLinkFilter, lib: true do
+ include FilterSpecHelper
+
+ let(:namespace) { build_stubbed(:namespace, name: "wiki_link_ns") }
+ let(:project) { build_stubbed(:empty_project, :public, name: "wiki_link_project", namespace: namespace) }
+ let(:user) { double }
+ let(:wiki) { ProjectWiki.new(project, user) }
+
+ it "doesn't rewrite absolute links" do
+ filtered_link = filter("<a href='http://example.com:8000/'>Link</a>", project_wiki: wiki).children[0]
+ expect(filtered_link.attribute('href').value).to eq('http://example.com:8000/')
+ end
+
+ describe "invalid links" do
+ invalid_links = ["http://:8080", "http://", "http://:8080/path"]
+
+ invalid_links.each do |invalid_link|
+ it "doesn't rewrite invalid invalid_links like #{invalid_link}" do
+ filtered_link = filter("<a href='#{invalid_link}'>Link</a>", project_wiki: wiki).children[0]
+ expect(filtered_link.attribute('href').value).to eq(invalid_link)
+ end
+ end
+ end
+end