summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/string_range_marker_spec.rb
diff options
context:
space:
mode:
authorJarka Kadlecova <jarka@gitlab.com>2017-08-15 07:09:05 +0200
committerJarka Kadlecova <jarka@gitlab.com>2017-08-17 19:55:07 +0200
commitc271fdc80fd17e1931a1d912e231bec2b8e3d098 (patch)
tree1e5372e9cb8bfc5a1429e3e96e127c4168c1c59a /spec/lib/gitlab/string_range_marker_spec.rb
parent04f7f394d3825e3290f523dce28d42b7c87fc9bb (diff)
downloadgitlab-ce-c271fdc80fd17e1931a1d912e231bec2b8e3d098.tar.gz
Don't escape html entities when rich == raw line36041-notification-title
Diffstat (limited to 'spec/lib/gitlab/string_range_marker_spec.rb')
-rw-r--r--spec/lib/gitlab/string_range_marker_spec.rb39
1 files changed, 22 insertions, 17 deletions
diff --git a/spec/lib/gitlab/string_range_marker_spec.rb b/spec/lib/gitlab/string_range_marker_spec.rb
index abeaa7f0ddb..6bc02459dbd 100644
--- a/spec/lib/gitlab/string_range_marker_spec.rb
+++ b/spec/lib/gitlab/string_range_marker_spec.rb
@@ -2,34 +2,39 @@ require 'spec_helper'
describe Gitlab::StringRangeMarker do
describe '#mark' do
+ def mark_diff(rich = nil)
+ raw = 'abc <def>'
+ inline_diffs = [2..5]
+
+ described_class.new(raw, rich).mark(inline_diffs) do |text, left:, right:|
+ "LEFT#{text}RIGHT"
+ end
+ end
+
context "when the rich text is html safe" do
- let(:raw) { "abc <def>" }
let(:rich) { %{<span class="abc">abc</span><span class="space"> </span><span class="def">&lt;def&gt;</span>}.html_safe }
- let(:inline_diffs) { [2..5] }
- subject do
- described_class.new(raw, rich).mark(inline_diffs) do |text, left:, right:|
- "LEFT#{text}RIGHT"
- end
- end
it 'marks the inline diffs' do
- expect(subject).to eq(%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT&lt;dRIGHTef&gt;</span>})
- expect(subject).to be_html_safe
+ expect(mark_diff(rich)).to eq(%{<span class="abc">abLEFTcRIGHT</span><span class="space">LEFT RIGHT</span><span class="def">LEFT&lt;dRIGHTef&gt;</span>})
+ expect(mark_diff(rich)).to be_html_safe
end
end
context "when the rich text is not html safe" do
- let(:raw) { "abc <def>" }
- let(:inline_diffs) { [2..5] }
- subject do
- described_class.new(raw).mark(inline_diffs) do |text, left:, right:|
- "LEFT#{text}RIGHT"
+ context 'when rich text equals raw text' do
+ it 'marks the inline diffs' do
+ expect(mark_diff).to eq(%{abLEFTc <dRIGHTef>})
+ expect(mark_diff).not_to be_html_safe
end
end
- it 'marks the inline diffs' do
- expect(subject).to eq(%{abLEFTc &lt;dRIGHTef&gt;})
- expect(subject).to be_html_safe
+ context 'when rich text doeas not equal raw text' do
+ let(:rich) { "abc <def> differs" }
+
+ it 'marks the inline diffs' do
+ expect(mark_diff(rich)).to eq(%{abLEFTc &lt;dRIGHTef&gt; differs})
+ expect(mark_diff(rich)).to be_html_safe
+ end
end
end
end