2019-11-24 07:06:34 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-07-06 06:35:30 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::HookData::BaseBuilder do
|
2018-07-17 09:58:14 -04:00
|
|
|
describe '#absolute_image_urls' do
|
|
|
|
let(:subclass) do
|
|
|
|
Class.new(described_class) do
|
|
|
|
public :absolute_image_urls
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-06 06:35:30 -04:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
2018-10-15 06:42:15 -04:00
|
|
|
context 'with an upload prefix specified' do
|
|
|
|
let(:project_with_path) { double(full_path: 'baz/bar') }
|
|
|
|
let(:object_with_project) { double(project: project_with_path) }
|
2019-12-12 07:07:33 -05:00
|
|
|
|
2018-10-15 06:42:15 -04:00
|
|
|
subject { subclass.new(object_with_project) }
|
|
|
|
|
|
|
|
where do
|
|
|
|
{
|
|
|
|
'relative image URL' => {
|
|
|
|
input: '![an image](foo.png)',
|
|
|
|
output: "![an image](#{Gitlab.config.gitlab.url}/foo.png)"
|
|
|
|
},
|
|
|
|
'absolute upload URL' => {
|
|
|
|
input: '![an image](/uploads/foo.png)',
|
|
|
|
output: "![an image](#{Gitlab.config.gitlab.url}/baz/bar/uploads/foo.png)"
|
|
|
|
},
|
|
|
|
'absolute non-upload URL' => {
|
|
|
|
input: '![an image](/downloads/foo.png)',
|
|
|
|
output: "![an image](#{Gitlab.config.gitlab.url}/downloads/foo.png)"
|
|
|
|
}
|
2018-07-06 06:35:30 -04:00
|
|
|
}
|
2018-10-15 06:42:15 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { expect(subject.absolute_image_urls(input)).to eq(output) }
|
|
|
|
end
|
2018-07-06 06:35:30 -04:00
|
|
|
end
|
|
|
|
|
2018-10-15 06:42:15 -04:00
|
|
|
context 'without an upload prefix specified' do
|
|
|
|
subject { subclass.new(nil) }
|
|
|
|
|
|
|
|
where do
|
|
|
|
{
|
|
|
|
'relative image URL' => {
|
|
|
|
input: '![an image](foo.png)',
|
|
|
|
output: "![an image](#{Gitlab.config.gitlab.url}/foo.png)"
|
|
|
|
},
|
|
|
|
'absolute upload URL' => {
|
|
|
|
input: '![an image](/uploads/foo.png)',
|
|
|
|
output: "![an image](#{Gitlab.config.gitlab.url}/uploads/foo.png)"
|
|
|
|
},
|
|
|
|
'absolute non-upload URL' => {
|
|
|
|
input: '![an image](/downloads/foo.png)',
|
|
|
|
output: "![an image](#{Gitlab.config.gitlab.url}/downloads/foo.png)"
|
|
|
|
},
|
|
|
|
'HTTP URL' => {
|
|
|
|
input: '![an image](http://example.com/foo.png)',
|
|
|
|
output: '![an image](http://example.com/foo.png)'
|
|
|
|
},
|
|
|
|
'HTTPS URL' => {
|
|
|
|
input: '![an image](https://example.com/foo.png)',
|
|
|
|
output: '![an image](https://example.com/foo.png)'
|
|
|
|
},
|
|
|
|
'protocol-relative URL' => {
|
|
|
|
input: '![an image](//example.com/foo.png)',
|
|
|
|
output: '![an image](//example.com/foo.png)'
|
|
|
|
},
|
|
|
|
'URL reference by title' => {
|
|
|
|
input: "![foo]\n\n[foo]: foo.png",
|
|
|
|
output: "![foo]\n\n[foo]: foo.png"
|
|
|
|
},
|
|
|
|
'URL reference by label' => {
|
|
|
|
input: "![][foo]\n\n[foo]: foo.png",
|
|
|
|
output: "![][foo]\n\n[foo]: foo.png"
|
|
|
|
},
|
|
|
|
'in Markdown inline code block' => {
|
|
|
|
input: '`![an image](foo.png)`',
|
|
|
|
output: "`![an image](#{Gitlab.config.gitlab.url}/foo.png)`"
|
|
|
|
},
|
|
|
|
'in HTML tag on the same line' => {
|
|
|
|
input: '<p>![an image](foo.png)</p>',
|
|
|
|
output: "<p>![an image](#{Gitlab.config.gitlab.url}/foo.png)</p>"
|
|
|
|
},
|
|
|
|
'in Markdown multi-line code block' => {
|
|
|
|
input: "```\n![an image](foo.png)\n```",
|
|
|
|
output: "```\n![an image](foo.png)\n```"
|
|
|
|
},
|
|
|
|
'in HTML tag on different lines' => {
|
|
|
|
input: "<p>\n![an image](foo.png)\n</p>",
|
|
|
|
output: "<p>\n![an image](foo.png)\n</p>"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
it { expect(subject.absolute_image_urls(input)).to eq(output) }
|
|
|
|
end
|
2018-07-06 06:35:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|