2016-03-30 22:03:49 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 14:24:02 +00:00
|
|
|
describe Banzai::Filter::ImageLinkFilter do
|
2016-03-30 22:03:49 +00:00
|
|
|
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
|
2016-08-13 19:01:28 +00:00
|
|
|
doc = filter(%Q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>))
|
2018-01-27 05:35:53 +00:00
|
|
|
expect(doc.to_html).to match %r{^<a href="/whatever"><img[^>]*></a>$}
|
2016-03-30 22:03:49 +00:00
|
|
|
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
|
2016-06-21 16:24:00 +00:00
|
|
|
|
2016-08-13 05:13:39 +00:00
|
|
|
it 'works with inline images' do
|
|
|
|
doc = filter(%Q(<p>test #{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')} inline</p>))
|
2018-01-27 05:35:53 +00:00
|
|
|
expect(doc.to_html).to match %r{^<p>test <a[^>]*><img[^>]*></a> inline</p>$}
|
2016-06-21 16:24:00 +00:00
|
|
|
end
|
2016-03-30 22:03:49 +00:00
|
|
|
end
|