2015-02-12 18:53:23 +00:00
|
|
|
require 'spec_helper'
|
2012-08-02 00:26:21 +00:00
|
|
|
|
2017-04-03 09:55:15 +00:00
|
|
|
describe MarkupHelper do
|
2017-01-25 22:10:32 +00:00
|
|
|
let!(:project) { create(:project, :repository) }
|
2012-09-02 06:13:13 +00:00
|
|
|
|
2012-12-07 03:40:42 +00:00
|
|
|
let(:user) { create(:user, username: 'gfm') }
|
2015-04-21 13:13:40 +00:00
|
|
|
let(:commit) { project.commit }
|
2012-09-02 06:13:13 +00:00
|
|
|
let(:issue) { create(:issue, project: project) }
|
2013-04-25 14:15:33 +00:00
|
|
|
let(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
|
2013-03-25 07:20:14 +00:00
|
|
|
let(:snippet) { create(:project_snippet, project: project) }
|
2012-09-02 06:13:13 +00:00
|
|
|
|
2012-08-02 00:26:21 +00:00
|
|
|
before do
|
2015-09-01 22:09:20 +00:00
|
|
|
# Ensure the generated reference links aren't redacted
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2015-09-01 22:09:20 +00:00
|
|
|
|
2012-09-02 06:13:13 +00:00
|
|
|
# Helper expects a @project instance variable
|
2015-09-01 22:09:20 +00:00
|
|
|
helper.instance_variable_set(:@project, project)
|
|
|
|
|
|
|
|
# Stub the `current_user` helper
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
2012-08-02 00:26:21 +00:00
|
|
|
end
|
|
|
|
|
2015-08-27 20:09:01 +00:00
|
|
|
describe "#markdown" do
|
2012-09-02 06:13:13 +00:00
|
|
|
describe "referencing multiple objects" do
|
2015-05-21 20:35:15 +00:00
|
|
|
let(:actual) { "#{merge_request.to_reference} -> #{commit.to_reference} -> #{issue.to_reference}" }
|
2012-09-02 06:13:13 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "links to the merge request" do
|
2018-08-15 19:18:05 +00:00
|
|
|
expected = urls.project_merge_request_path(project, merge_request)
|
2015-09-01 22:09:20 +00:00
|
|
|
expect(helper.markdown(actual)).to match(expected)
|
2012-08-02 00:26:21 +00:00
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "links to the commit" do
|
2018-08-15 19:18:05 +00:00
|
|
|
expected = urls.project_commit_path(project, commit)
|
2015-09-01 22:09:20 +00:00
|
|
|
expect(helper.markdown(actual)).to match(expected)
|
2012-08-02 00:26:21 +00:00
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "links to the issue" do
|
2018-08-15 19:18:05 +00:00
|
|
|
expected = urls.project_issue_path(project, issue)
|
2015-09-01 22:09:20 +00:00
|
|
|
expect(helper.markdown(actual)).to match(expected)
|
2012-08-02 00:26:21 +00:00
|
|
|
end
|
|
|
|
end
|
2015-09-18 18:05:27 +00:00
|
|
|
|
|
|
|
describe "override default project" do
|
|
|
|
let(:actual) { issue.to_reference }
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:second_project) { create(:project, :public) }
|
2015-09-18 18:05:27 +00:00
|
|
|
let(:second_issue) { create(:issue, project: second_project) }
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'links to the issue' do
|
2018-08-15 19:18:05 +00:00
|
|
|
expected = urls.project_issue_path(second_project, second_issue)
|
2015-09-18 18:05:27 +00:00
|
|
|
expect(markdown(actual, project: second_project)).to match(expected)
|
|
|
|
end
|
|
|
|
end
|
2012-09-02 06:13:13 +00:00
|
|
|
end
|
2012-08-02 00:26:21 +00:00
|
|
|
|
2017-08-23 16:53:29 +00:00
|
|
|
describe '#markdown_field' do
|
|
|
|
let(:attribute) { :title }
|
|
|
|
|
|
|
|
describe 'with already redacted attribute' do
|
|
|
|
it 'returns the redacted attribute' do
|
|
|
|
commit.redacted_title_html = 'commit title'
|
|
|
|
|
|
|
|
expect(Banzai).not_to receive(:render_field)
|
|
|
|
|
|
|
|
expect(helper.markdown_field(commit, attribute)).to eq('commit title')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'without redacted attribute' do
|
|
|
|
it 'renders the markdown value' do
|
2017-11-06 16:52:56 +00:00
|
|
|
expect(Banzai).to receive(:render_field).with(commit, attribute, {}).and_call_original
|
2017-08-23 16:53:29 +00:00
|
|
|
|
|
|
|
helper.markdown_field(commit, attribute)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#link_to_markdown_field' do
|
|
|
|
let(:link) { '/commits/0a1b2c3d' }
|
|
|
|
let(:issues) { create_list(:issue, 2, project: project) }
|
|
|
|
|
2019-06-05 04:59:48 +00:00
|
|
|
# Clean the cache to make sure the title is re-rendered from the stubbed one
|
|
|
|
it 'handles references nested in links with all the text', :clean_gitlab_redis_cache do
|
2017-08-23 16:53:29 +00:00
|
|
|
allow(commit).to receive(:title).and_return("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real")
|
|
|
|
|
|
|
|
actual = helper.link_to_markdown_field(commit, :title, link)
|
|
|
|
doc = Nokogiri::HTML.parse(actual)
|
|
|
|
|
|
|
|
# Make sure we didn't create invalid markup
|
|
|
|
expect(doc.errors).to be_empty
|
|
|
|
|
|
|
|
# Leading commit link
|
|
|
|
expect(doc.css('a')[0].attr('href')).to eq link
|
|
|
|
expect(doc.css('a')[0].text).to eq 'This should finally fix '
|
|
|
|
|
|
|
|
# First issue link
|
|
|
|
expect(doc.css('a')[1].attr('href'))
|
2018-08-15 19:18:05 +00:00
|
|
|
.to eq urls.project_issue_path(project, issues[0])
|
2017-08-23 16:53:29 +00:00
|
|
|
expect(doc.css('a')[1].text).to eq issues[0].to_reference
|
|
|
|
|
|
|
|
# Internal commit link
|
|
|
|
expect(doc.css('a')[2].attr('href')).to eq link
|
|
|
|
expect(doc.css('a')[2].text).to eq ' and '
|
|
|
|
|
|
|
|
# Second issue link
|
|
|
|
expect(doc.css('a')[3].attr('href'))
|
2018-08-15 19:18:05 +00:00
|
|
|
.to eq urls.project_issue_path(project, issues[1])
|
2017-08-23 16:53:29 +00:00
|
|
|
expect(doc.css('a')[3].text).to eq issues[1].to_reference
|
|
|
|
|
|
|
|
# Trailing commit link
|
|
|
|
expect(doc.css('a')[4].attr('href')).to eq link
|
|
|
|
expect(doc.css('a')[4].text).to eq ' for real'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#link_to_markdown' do
|
2017-01-25 22:10:32 +00:00
|
|
|
let(:link) { '/commits/0a1b2c3d' }
|
2017-01-26 12:09:29 +00:00
|
|
|
let(:issues) { create_list(:issue, 2, project: project) }
|
2012-08-02 00:26:21 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'handles references nested in links with all the text' do
|
2017-08-23 16:53:29 +00:00
|
|
|
actual = helper.link_to_markdown("This should finally fix #{issues[0].to_reference} and #{issues[1].to_reference} for real", link)
|
2015-04-20 19:43:27 +00:00
|
|
|
doc = Nokogiri::HTML.parse(actual)
|
2012-08-02 00:26:21 +00:00
|
|
|
|
2015-04-21 17:12:19 +00:00
|
|
|
# Make sure we didn't create invalid markup
|
|
|
|
expect(doc.errors).to be_empty
|
|
|
|
|
2012-09-02 06:13:13 +00:00
|
|
|
# Leading commit link
|
2017-01-25 22:10:32 +00:00
|
|
|
expect(doc.css('a')[0].attr('href')).to eq link
|
2015-04-20 19:43:27 +00:00
|
|
|
expect(doc.css('a')[0].text).to eq 'This should finally fix '
|
2012-08-02 00:26:21 +00:00
|
|
|
|
2012-09-02 06:13:13 +00:00
|
|
|
# First issue link
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(doc.css('a')[1].attr('href'))
|
2018-08-15 19:18:05 +00:00
|
|
|
.to eq urls.project_issue_path(project, issues[0])
|
2015-05-21 20:35:15 +00:00
|
|
|
expect(doc.css('a')[1].text).to eq issues[0].to_reference
|
2012-08-02 00:28:50 +00:00
|
|
|
|
2012-09-02 06:13:13 +00:00
|
|
|
# Internal commit link
|
2017-01-25 22:10:32 +00:00
|
|
|
expect(doc.css('a')[2].attr('href')).to eq link
|
2015-04-20 19:43:27 +00:00
|
|
|
expect(doc.css('a')[2].text).to eq ' and '
|
2012-08-02 00:28:50 +00:00
|
|
|
|
2012-09-02 06:13:13 +00:00
|
|
|
# Second issue link
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(doc.css('a')[3].attr('href'))
|
2018-08-15 19:18:05 +00:00
|
|
|
.to eq urls.project_issue_path(project, issues[1])
|
2015-05-21 20:35:15 +00:00
|
|
|
expect(doc.css('a')[3].text).to eq issues[1].to_reference
|
2012-09-02 06:13:13 +00:00
|
|
|
|
|
|
|
# Trailing commit link
|
2017-01-25 22:10:32 +00:00
|
|
|
expect(doc.css('a')[4].attr('href')).to eq link
|
2015-04-20 19:43:27 +00:00
|
|
|
expect(doc.css('a')[4].text).to eq ' for real'
|
2012-08-02 00:28:50 +00:00
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'forwards HTML options' do
|
2017-08-23 16:53:29 +00:00
|
|
|
actual = helper.link_to_markdown("Fixed in #{commit.id}", link, class: 'foo')
|
2015-08-27 21:28:45 +00:00
|
|
|
doc = Nokogiri::HTML.parse(actual)
|
|
|
|
|
|
|
|
expect(doc.css('a')).to satisfy do |v|
|
|
|
|
# 'foo' gets added to all links
|
|
|
|
v.all? { |a| a.attr('class').match(/foo$/) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-19 23:42:26 +00:00
|
|
|
it "escapes HTML passed in as the body" do
|
2015-05-21 20:35:15 +00:00
|
|
|
actual = "This is a <h1>test</h1> - see #{issues[0].to_reference}"
|
2017-08-23 16:53:29 +00:00
|
|
|
expect(helper.link_to_markdown(actual, link))
|
2017-06-21 13:48:12 +00:00
|
|
|
.to match('<h1>test</h1>')
|
2012-09-19 23:42:26 +00:00
|
|
|
end
|
2015-05-29 05:56:30 +00:00
|
|
|
|
|
|
|
it 'ignores reference links when they are the entire body' do
|
|
|
|
text = issues[0].to_reference
|
2017-08-23 16:53:29 +00:00
|
|
|
act = helper.link_to_markdown(text, '/foo')
|
2015-05-29 05:56:30 +00:00
|
|
|
expect(act).to eq %Q(<a href="/foo">#{issues[0].to_reference}</a>)
|
|
|
|
end
|
2015-10-01 04:09:07 +00:00
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it 'replaces commit message with emoji to link' do
|
2017-08-23 16:53:29 +00:00
|
|
|
actual = link_to_markdown(':book: Book', '/foo')
|
2017-06-21 13:48:12 +00:00
|
|
|
expect(actual)
|
|
|
|
.to eq '<gl-emoji title="open book" data-name="book" data-unicode-version="6.0">📖</gl-emoji><a href="/foo"> Book</a>'
|
2015-10-01 04:09:07 +00:00
|
|
|
end
|
2012-08-02 00:28:50 +00:00
|
|
|
end
|
2012-08-02 00:29:15 +00:00
|
|
|
|
2017-08-23 16:53:29 +00:00
|
|
|
describe '#link_to_html' do
|
|
|
|
it 'wraps the rendered content in a link' do
|
|
|
|
link = '/commits/0a1b2c3d'
|
|
|
|
issue = create(:issue, project: project)
|
|
|
|
|
|
|
|
rendered = helper.markdown("This should finally fix #{issue.to_reference} for real", pipeline: :single_line)
|
|
|
|
doc = Nokogiri::HTML.parse(rendered)
|
|
|
|
|
|
|
|
expect(doc.css('a')[0].attr('href'))
|
2018-08-15 19:18:05 +00:00
|
|
|
.to eq urls.project_issue_path(project, issue)
|
2017-08-23 16:53:29 +00:00
|
|
|
expect(doc.css('a')[0].text).to eq issue.to_reference
|
|
|
|
|
|
|
|
wrapped = helper.link_to_html(rendered, link)
|
|
|
|
doc = Nokogiri::HTML.parse(wrapped)
|
|
|
|
|
|
|
|
expect(doc.css('a')[0].attr('href')).to eq link
|
|
|
|
expect(doc.css('a')[0].text).to eq 'This should finally fix '
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-13 22:05:42 +00:00
|
|
|
describe '#render_wiki_content' do
|
2013-03-14 06:31:08 +00:00
|
|
|
before do
|
2013-12-14 13:43:48 +00:00
|
|
|
@wiki = double('WikiPage')
|
2015-02-12 18:17:35 +00:00
|
|
|
allow(@wiki).to receive(:content).and_return('wiki content')
|
2016-06-08 05:02:50 +00:00
|
|
|
allow(@wiki).to receive(:slug).and_return('nested/page')
|
2016-01-12 04:10:08 +00:00
|
|
|
helper.instance_variable_set(:@project_wiki, @wiki)
|
2013-03-14 06:31:08 +00:00
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "uses Wiki pipeline for markdown files" do
|
2015-02-12 18:17:35 +00:00
|
|
|
allow(@wiki).to receive(:format).and_return(:markdown)
|
2013-03-14 06:31:08 +00:00
|
|
|
|
2018-07-06 18:49:33 +00:00
|
|
|
expect(helper).to receive(:markdown_unsafe).with('wiki content',
|
|
|
|
pipeline: :wiki, project: project, project_wiki: @wiki, page_slug: "nested/page",
|
2018-08-15 20:51:29 +00:00
|
|
|
issuable_state_filter_enabled: true)
|
2013-03-14 06:31:08 +00:00
|
|
|
|
|
|
|
helper.render_wiki_content(@wiki)
|
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "uses Asciidoctor for asciidoc files" do
|
2015-05-12 23:07:48 +00:00
|
|
|
allow(@wiki).to receive(:format).and_return(:asciidoc)
|
|
|
|
|
2017-04-21 15:17:19 +00:00
|
|
|
expect(helper).to receive(:asciidoc_unsafe).with('wiki content')
|
2015-05-12 23:07:48 +00:00
|
|
|
|
|
|
|
helper.render_wiki_content(@wiki)
|
|
|
|
end
|
|
|
|
|
2016-07-25 18:16:19 +00:00
|
|
|
it "uses the Gollum renderer for all other file types" do
|
2015-02-12 18:17:35 +00:00
|
|
|
allow(@wiki).to receive(:format).and_return(:rdoc)
|
2013-12-14 13:43:48 +00:00
|
|
|
formatted_content_stub = double('formatted_content')
|
2015-02-12 18:17:35 +00:00
|
|
|
expect(formatted_content_stub).to receive(:html_safe)
|
|
|
|
allow(@wiki).to receive(:formatted_content).and_return(formatted_content_stub)
|
2013-03-14 06:31:08 +00:00
|
|
|
|
|
|
|
helper.render_wiki_content(@wiki)
|
|
|
|
end
|
|
|
|
end
|
2015-06-24 01:00:10 +00:00
|
|
|
|
2017-04-21 15:17:19 +00:00
|
|
|
describe 'markup' do
|
2017-04-06 14:47:52 +00:00
|
|
|
let(:content) { 'Noël' }
|
|
|
|
|
|
|
|
it 'preserves encoding' do
|
|
|
|
expect(content.encoding.name).to eq('UTF-8')
|
2017-04-21 15:17:19 +00:00
|
|
|
expect(helper.markup('foo.rst', content).encoding.name).to eq('UTF-8')
|
2017-04-06 14:47:52 +00:00
|
|
|
end
|
|
|
|
|
2018-07-06 18:49:33 +00:00
|
|
|
it 'delegates to #markdown_unsafe when file name corresponds to Markdown' do
|
2017-04-06 14:47:52 +00:00
|
|
|
expect(helper).to receive(:gitlab_markdown?).with('foo.md').and_return(true)
|
2017-04-21 15:17:19 +00:00
|
|
|
expect(helper).to receive(:markdown_unsafe).and_return('NOEL')
|
2017-04-06 14:47:52 +00:00
|
|
|
|
2017-04-21 15:17:19 +00:00
|
|
|
expect(helper.markup('foo.md', content)).to eq('NOEL')
|
2017-04-06 14:47:52 +00:00
|
|
|
end
|
|
|
|
|
2018-07-06 18:49:33 +00:00
|
|
|
it 'delegates to #asciidoc_unsafe when file name corresponds to AsciiDoc' do
|
2017-04-06 14:47:52 +00:00
|
|
|
expect(helper).to receive(:asciidoc?).with('foo.adoc').and_return(true)
|
2017-04-21 15:17:19 +00:00
|
|
|
expect(helper).to receive(:asciidoc_unsafe).and_return('NOEL')
|
2017-04-06 14:47:52 +00:00
|
|
|
|
2017-04-21 15:17:19 +00:00
|
|
|
expect(helper.markup('foo.adoc', content)).to eq('NOEL')
|
2017-04-06 14:47:52 +00:00
|
|
|
end
|
2018-07-06 18:49:33 +00:00
|
|
|
|
|
|
|
it 'uses passed in rendered content' do
|
|
|
|
expect(helper).not_to receive(:gitlab_markdown?)
|
|
|
|
expect(helper).not_to receive(:markdown_unsafe)
|
|
|
|
|
|
|
|
expect(helper.markup('foo.md', content, rendered: '<p>NOEL</p>')).to eq('<p>NOEL</p>')
|
|
|
|
end
|
|
|
|
|
2018-08-15 20:51:29 +00:00
|
|
|
it 'defaults to CommonMark' do
|
|
|
|
expect(helper.markup('foo.md', 'x^2')).to include('x^2')
|
|
|
|
end
|
2017-04-06 14:47:52 +00:00
|
|
|
end
|
|
|
|
|
2015-09-23 04:56:27 +00:00
|
|
|
describe '#first_line_in_markdown' do
|
2017-11-06 16:52:56 +00:00
|
|
|
shared_examples_for 'common markdown examples' do
|
|
|
|
let(:project_base) { build(:project, :repository) }
|
2015-09-23 04:56:27 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
it 'displays inline code' do
|
|
|
|
object = create_object('Text with `inline code`')
|
|
|
|
expected = 'Text with <code>inline code</code>'
|
2015-09-23 04:56:27 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
expect(first_line_in_markdown(object, attribute, 100, project: project)).to match(expected)
|
|
|
|
end
|
2015-09-23 04:56:27 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
it 'truncates the text with multiple paragraphs' do
|
|
|
|
object = create_object("Paragraph 1\n\nParagraph 2")
|
|
|
|
expected = 'Paragraph 1...'
|
2015-09-23 04:56:27 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
expect(first_line_in_markdown(object, attribute, 100, project: project)).to match(expected)
|
|
|
|
end
|
2017-03-14 06:24:56 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
it 'displays the first line of a code block' do
|
|
|
|
object = create_object("```\nCode block\nwith two lines\n```")
|
|
|
|
expected = %r{<pre.+><code><span class="line">Code block\.\.\.</span>\n</code></pre>}
|
2017-03-14 06:24:56 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
expect(first_line_in_markdown(object, attribute, 100, project: project)).to match(expected)
|
|
|
|
end
|
2017-03-14 06:24:56 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
it 'truncates a single long line of text' do
|
|
|
|
text = 'The quick brown fox jumped over the lazy dog twice' # 50 chars
|
|
|
|
object = create_object(text * 4)
|
|
|
|
expected = (text * 2).sub(/.{3}/, '...')
|
|
|
|
|
|
|
|
expect(first_line_in_markdown(object, attribute, 150, project: project)).to match(expected)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'preserves a link href when link text is truncated' do
|
|
|
|
text = 'The quick brown fox jumped over the lazy dog' # 44 chars
|
|
|
|
input = "#{text}#{text}#{text} " # 133 chars
|
|
|
|
link_url = 'http://example.com/foo/bar/baz' # 30 chars
|
|
|
|
input << link_url
|
|
|
|
object = create_object(input)
|
|
|
|
expected_link_text = 'http://example...</a>'
|
|
|
|
|
|
|
|
expect(first_line_in_markdown(object, attribute, 150, project: project)).to match(link_url)
|
|
|
|
expect(first_line_in_markdown(object, attribute, 150, project: project)).to match(expected_link_text)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'preserves code color scheme' do
|
|
|
|
object = create_object("```ruby\ndef test\n 'hello world'\nend\n```")
|
2018-06-14 08:30:16 +00:00
|
|
|
expected = "<pre class=\"code highlight js-syntax-highlight ruby\">" \
|
2017-11-06 16:52:56 +00:00
|
|
|
"<code><span class=\"line\"><span class=\"k\">def</span> <span class=\"nf\">test</span>...</span>\n" \
|
|
|
|
"</code></pre>"
|
|
|
|
|
|
|
|
expect(first_line_in_markdown(object, attribute, 150, project: project)).to eq(expected)
|
|
|
|
end
|
|
|
|
|
2018-09-12 22:47:21 +00:00
|
|
|
context 'when images are allowed' do
|
|
|
|
it 'preserves data-src for lazy images' do
|
|
|
|
object = create_object("![ImageTest](/uploads/test.png)")
|
|
|
|
image_url = "data-src=\".*/uploads/test.png\""
|
|
|
|
text = first_line_in_markdown(object, attribute, 150, project: project, allow_images: true)
|
|
|
|
|
|
|
|
expect(text).to match(image_url)
|
|
|
|
expect(text).to match('<a')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when images are not allowed' do
|
|
|
|
it 'removes any images' do
|
|
|
|
object = create_object("![ImageTest](/uploads/test.png)")
|
|
|
|
text = first_line_in_markdown(object, attribute, 150, project: project)
|
2017-11-06 16:52:56 +00:00
|
|
|
|
2018-09-12 22:47:21 +00:00
|
|
|
expect(text).not_to match('<img')
|
|
|
|
expect(text).not_to match('<a')
|
|
|
|
end
|
2017-11-06 16:52:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'labels formatting' do
|
|
|
|
let(:label_title) { 'this should be ~label_1' }
|
|
|
|
|
|
|
|
def create_and_format_label(project)
|
|
|
|
create(:label, title: 'label_1', project: project)
|
|
|
|
object = create_object(label_title, project: project)
|
2017-03-14 06:24:56 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
first_line_in_markdown(object, attribute, 150, project: project)
|
|
|
|
end
|
2017-03-14 06:24:56 +00:00
|
|
|
|
2017-11-06 16:52:56 +00:00
|
|
|
it 'preserves style attribute for a label that can be accessed by current_user' do
|
|
|
|
project = create(:project, :public)
|
|
|
|
|
|
|
|
expect(create_and_format_label(project)).to match(/span class=.*style=.*/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not style a label that can not be accessed by current_user' do
|
|
|
|
project = create(:project, :private)
|
|
|
|
|
|
|
|
expect(create_and_format_label(project)).to eq("<p>#{label_title}</p>")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'truncates Markdown properly' do
|
|
|
|
object = create_object("@#{user.username}, can you look at this?\nHello world\n")
|
|
|
|
actual = first_line_in_markdown(object, attribute, 100, project: project)
|
|
|
|
|
|
|
|
doc = Nokogiri::HTML.parse(actual)
|
|
|
|
|
|
|
|
# Make sure we didn't create invalid markup
|
|
|
|
expect(doc.errors).to be_empty
|
|
|
|
|
|
|
|
# Leading user link
|
|
|
|
expect(doc.css('a').length).to eq(1)
|
|
|
|
expect(doc.css('a')[0].attr('href')).to eq user_path(user)
|
|
|
|
expect(doc.css('a')[0].text).to eq "@#{user.username}"
|
|
|
|
|
|
|
|
expect(doc.content).to eq "@#{user.username}, can you look at this?..."
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'truncates Markdown with emoji properly' do
|
|
|
|
object = create_object("foo :wink:\nbar :grinning:")
|
|
|
|
actual = first_line_in_markdown(object, attribute, 100, project: project)
|
|
|
|
|
|
|
|
doc = Nokogiri::HTML.parse(actual)
|
|
|
|
|
|
|
|
# Make sure we didn't create invalid markup
|
|
|
|
# But also account for the 2 errors caused by the unknown `gl-emoji` elements
|
|
|
|
expect(doc.errors.length).to eq(2)
|
|
|
|
|
|
|
|
expect(doc.css('gl-emoji').length).to eq(2)
|
|
|
|
expect(doc.css('gl-emoji')[0].attr('data-name')).to eq 'wink'
|
|
|
|
expect(doc.css('gl-emoji')[1].attr('data-name')).to eq 'grinning'
|
|
|
|
|
|
|
|
expect(doc.content).to eq "foo 😉\nbar 😀"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the asked attribute can be redacted' do
|
|
|
|
include_examples 'common markdown examples' do
|
|
|
|
let(:attribute) { :note }
|
|
|
|
def create_object(title, project: project_base)
|
|
|
|
build(:note, note: title, project: project)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the asked attribute can not be redacted' do
|
|
|
|
include_examples 'common markdown examples' do
|
|
|
|
let(:attribute) { :body }
|
|
|
|
def create_object(title, project: project_base)
|
|
|
|
issue = build(:issue, title: title)
|
|
|
|
build(:todo, :done, project: project_base, author: user, target: issue)
|
|
|
|
end
|
|
|
|
end
|
2017-03-14 06:24:56 +00:00
|
|
|
end
|
2015-09-23 04:56:27 +00:00
|
|
|
end
|
2016-12-21 16:41:33 +00:00
|
|
|
|
|
|
|
describe '#cross_project_reference' do
|
|
|
|
it 'shows the full MR reference' do
|
2017-07-20 09:34:09 +00:00
|
|
|
expect(helper.cross_project_reference(project, merge_request)).to include(project.full_path)
|
2016-12-21 16:41:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows the full issue reference' do
|
2017-07-20 09:34:09 +00:00
|
|
|
expect(helper.cross_project_reference(project, issue)).to include(project.full_path)
|
2016-12-21 16:41:33 +00:00
|
|
|
end
|
|
|
|
end
|
2018-08-15 19:18:05 +00:00
|
|
|
|
|
|
|
def urls
|
|
|
|
Gitlab::Routing.url_helpers
|
|
|
|
end
|
2012-08-02 00:26:21 +00:00
|
|
|
end
|