diff options
| author | connorshea <connor.james.shea@gmail.com> | 2016-03-30 16:03:49 -0600 |
|---|---|---|
| committer | connorshea <connor.james.shea@gmail.com> | 2016-04-04 19:44:07 -0600 |
| commit | b9abf938edf52e762d320b1eb8732155e23d7b72 (patch) | |
| tree | fa58191817cb644a1eeb969b23e1d2cc58e654cb /spec | |
| parent | 67136007933425414293602bc75d2ba4822f2a93 (diff) | |
| download | gitlab-ce-b9abf938edf52e762d320b1eb8732155e23d7b72.tar.gz | |
Wrap images in discussions and wikis with a link to the image source using ImageLinkFilter.
Resolves #14411.
See merge request !3464
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/features/atom/users_spec.rb | 2 | ||||
| -rw-r--r-- | spec/lib/banzai/filter/image_link_filter_spec.rb | 24 |
2 files changed, 25 insertions, 1 deletions
diff --git a/spec/features/atom/users_spec.rb b/spec/features/atom/users_spec.rb index dc41be8246f..de6aed74fb4 100644 --- a/spec/features/atom/users_spec.rb +++ b/spec/features/atom/users_spec.rb @@ -61,7 +61,7 @@ describe "User Feed", feature: true do end it 'should have XHTML summaries in merge request descriptions' do - expect(body).to match /Here is the fix: <img[^>]*\/>/ + expect(body).to match /Here is the fix: <a[^>]*><img[^>]*\/><\/a>/ end end end 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 |
