summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2018-04-04 15:50:37 +0000
committerSean McGivern <sean@mcgivern.me.uk>2018-04-04 15:50:37 +0000
commit165e71bf5f5d2beb7c01c0be1a035fc79c76a62c (patch)
treeda2a71da6cf8a797a536601aacde5a9a2cb1175b /spec/lib
parent8512feea040424d9f980352afc194dee90972433 (diff)
parent2cda5ec83813cbe3bcb7879ac326a8d911bb3afd (diff)
downloadgitlab-ce-165e71bf5f5d2beb7c01c0be1a035fc79c76a62c.tar.gz
Merge branch 'osw-41401-render-mr-commit-sha-instead-diffs' into 'master'
Render MR commit SHA instead "diffs" when viable on GFM See merge request gitlab-org/gitlab-ce!18141
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/banzai/filter/merge_request_reference_filter_spec.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
index eeb82822f68..a1dd72c498f 100644
--- a/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/merge_request_reference_filter_spec.rb
@@ -196,6 +196,41 @@ describe Banzai::Filter::MergeRequestReferenceFilter do
end
end
+ context 'URL reference for a commit' do
+ let(:mr) { create(:merge_request, :with_diffs) }
+ let(:reference) do
+ urls.project_merge_request_url(mr.project, mr) + "/diffs?commit_id=#{mr.diff_head_sha}"
+ end
+ let(:commit) { mr.commits.find { |commit| commit.sha == mr.diff_head_sha } }
+
+ it 'links to a valid reference' do
+ doc = reference_filter("See #{reference}")
+
+ expect(doc.css('a').first.attr('href'))
+ .to eq reference
+ end
+
+ it 'has valid text' do
+ doc = reference_filter("See #{reference}")
+
+ expect(doc.text).to eq("See #{mr.to_reference(full: true)} (#{commit.short_id})")
+ end
+
+ it 'has valid title attribute' do
+ doc = reference_filter("See #{reference}")
+
+ expect(doc.css('a').first.attr('title')).to eq(commit.title)
+ end
+
+ it 'ignores invalid commit short_ids on link text' do
+ invalidate_commit_reference =
+ urls.project_merge_request_url(mr.project, mr) + "/diffs?commit_id=12345678"
+ doc = reference_filter("See #{invalidate_commit_reference}")
+
+ expect(doc.text).to eq("See #{mr.to_reference(full: true)} (diffs)")
+ end
+ end
+
context 'cross-project URL reference' do
let(:namespace) { create(:namespace, name: 'cross-reference') }
let(:project2) { create(:project, :public, namespace: namespace) }