summaryrefslogtreecommitdiff
path: root/spec/support/commit_trailers_spec_helper.rb
diff options
context:
space:
mode:
authorOmar Mekky <alphaengine@gmail.com>2018-04-04 15:04:03 +0000
committerDouwe Maan <douwe@gitlab.com>2018-04-04 15:04:03 +0000
commita069aa494a71450f3a6627b723bd5312bbf20133 (patch)
tree0d0916e3320b50d645068335b47a012eaf8c0a02 /spec/support/commit_trailers_spec_helper.rb
parentb15dd5dfa2ac269763d6342d7f0b3d9a64eb7fe4 (diff)
downloadgitlab-ce-a069aa494a71450f3a6627b723bd5312bbf20133.tar.gz
Add banzai filter to detect commit message trailers and properly link the users
Diffstat (limited to 'spec/support/commit_trailers_spec_helper.rb')
-rw-r--r--spec/support/commit_trailers_spec_helper.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/support/commit_trailers_spec_helper.rb b/spec/support/commit_trailers_spec_helper.rb
new file mode 100644
index 00000000000..add359946db
--- /dev/null
+++ b/spec/support/commit_trailers_spec_helper.rb
@@ -0,0 +1,41 @@
+module CommitTrailersSpecHelper
+ extend ActiveSupport::Concern
+
+ def expect_to_have_user_link_with_avatar(doc, user:, trailer:, email: nil)
+ wrapper = find_user_wrapper(doc, trailer)
+
+ expect_to_have_links_with_url_and_avatar(wrapper, urls.user_url(user), email || user.email)
+ expect(wrapper.attribute('data-user').value).to eq user.id.to_s
+ end
+
+ def expect_to_have_mailto_link(doc, email:, trailer:)
+ wrapper = find_user_wrapper(doc, trailer)
+
+ expect_to_have_links_with_url_and_avatar(wrapper, "mailto:#{CGI.escape_html(email)}", email)
+ end
+
+ def expect_to_have_links_with_url_and_avatar(doc, url, email)
+ expect(doc).not_to be_nil
+ expect(doc.xpath("a[position()<3 and @href='#{url}']").size).to eq 2
+ expect(doc.xpath("a[position()=3 and @href='mailto:#{CGI.escape_html(email)}']").size).to eq 1
+ expect(doc.css('img').size).to eq 1
+ end
+
+ def find_user_wrapper(doc, trailer)
+ doc.xpath("descendant-or-self::node()[@data-trailer='#{trailer}']").first
+ end
+
+ def build_commit_message(trailer:, name:, email:)
+ message = trailer_line(trailer, name, email)
+
+ [message, commit_html(message)]
+ end
+
+ def trailer_line(trailer, name, email)
+ "#{trailer} #{name} <#{email}>"
+ end
+
+ def commit_html(message)
+ "<pre>#{CGI.escape_html(message)}</pre>"
+ end
+end