summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2015-09-23 17:20:37 +0000
committerRobert Speicher <robert@gitlab.com>2015-09-23 17:20:37 +0000
commit0175769aa88704dac400fb811d8d6433d29b2d16 (patch)
treece84632e88b0e064688ca5d35b40a3988942c270 /spec
parent3f2c0e94dfbba060ea2c35fc73a2d07bf4988ae3 (diff)
parenta7b0ee3fd17d4e2afd427606b002d3a9f7c6673d (diff)
downloadgitlab-ce-0175769aa88704dac400fb811d8d6433d29b2d16.tar.gz
Merge branch 'fix-markdown-truncation-removing-links' into 'master'
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 See merge request !1401
Diffstat (limited to 'spec')
-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