summaryrefslogtreecommitdiff
path: root/spec/helpers
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2015-09-22 21:56:27 -0700
committerStan Hu <stanhu@gmail.com>2015-09-22 21:56:27 -0700
commita7b0ee3fd17d4e2afd427606b002d3a9f7c6673d (patch)
treefadfacf68e8a6020bc7c24083271bdf4595f91b4 /spec/helpers
parent03fd5919a393b8784c601c76c3ed65912f4b522a (diff)
downloadgitlab-ce-a7b0ee3fd17d4e2afd427606b002d3a9f7c6673d.tar.gz
Fix cases where Markdown did not render links in activity feed
HTML would be stripped in `truncate_if_block` when a comment had multiple lines and the first wasn't long enough to be truncated. The use of `node.content` would strip all HTML tags. Using `node.inner_html` retains these tags and puts the "..." in between paragraph tags. Closes #2586
Diffstat (limited to 'spec/helpers')
-rw-r--r--spec/helpers/gitlab_markdown_helper_spec.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb
index b8101ae77ec..be0e0c747b7 100644
--- a/spec/helpers/gitlab_markdown_helper_spec.rb
+++ b/spec/helpers/gitlab_markdown_helper_spec.rb
@@ -146,4 +146,24 @@ describe GitlabMarkdownHelper do
expect(random_markdown_tip).to eq 'Random tip'
end
end
+
+ describe '#first_line_in_markdown' do
+ let(:text) { "@#{user.username}, can you look at this?\nHello world\n"}
+
+ it 'truncates Markdown properly' do
+ actual = first_line_in_markdown(text, 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
+ end
end