summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-04-05 03:52:31 +0000
committerRobert Speicher <robert@gitlab.com>2016-04-05 03:52:31 +0000
commit6bf4e9e75232be83995a09f3a83e47fd0103273f (patch)
treefa58191817cb644a1eeb969b23e1d2cc58e654cb /spec/lib
parent67136007933425414293602bc75d2ba4822f2a93 (diff)
parentb9abf938edf52e762d320b1eb8732155e23d7b72 (diff)
downloadgitlab-ce-6bf4e9e75232be83995a09f3a83e47fd0103273f.tar.gz
Merge branch 'banzai-image-link' into 'master'
Add link to image URL for images in discussions. The main problem with this is that it doesn't apply retroactively, only to images that are uploaded after this change. It's also hacky and probably not the most optimal solution. Resolves #14411. See merge request !3464
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/banzai/filter/image_link_filter_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/image_link_filter_spec.rb b/spec/lib/banzai/filter/image_link_filter_spec.rb
new file mode 100644
index 00000000000..dd5594750c8
--- /dev/null
+++ b/spec/lib/banzai/filter/image_link_filter_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe Banzai::Filter::ImageLinkFilter, lib: true do
+ include FilterSpecHelper
+
+ def image(path)
+ %(<img src="#{path}" />)
+ end
+
+ it 'wraps the image with a link to the image src' do
+ doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
+ expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href']
+ end
+
+ it 'does not wrap a duplicate link' do
+ exp = act = %q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>)
+ expect(filter(act).to_html).to eq exp
+ end
+
+ it 'works with external images' do
+ doc = filter(image('https://i.imgur.com/DfssX9C.jpg'))
+ expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href']
+ end
+end