summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-08-28 14:39:17 +0100
committerJose Vargas <jvargas@gitlab.com>2018-08-28 16:36:25 -0500
commit8ba1f6aea48e8b4b635ae5bf01ef8d3204926a8d (patch)
tree4b6aba9e6dca90fc0c3cca9b49c4c97a2a195fd5
parenta7d8a1183ce34ff849ed2b4c2b505c79b64ebafb (diff)
downloadgitlab-ce-8ba1f6aea48e8b4b635ae5bf01ef8d3204926a8d.tar.gz
Include rich_text in diff cache keys
Previously, this wasn't needed: text was normally set to the highlighted contents anyway. Now, it is: we store different things in text and rich_text. This caused https://gitlab.com/gitlab-com/production/issues/439.
-rw-r--r--lib/gitlab/diff/line.rb7
-rw-r--r--spec/lib/gitlab/conflict/file_spec.rb4
-rw-r--r--spec/lib/gitlab/diff/line_spec.rb12
3 files changed, 16 insertions, 7 deletions
diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb
index 633985d5caa..1ab6df0b6ae 100644
--- a/lib/gitlab/diff/line.rb
+++ b/lib/gitlab/diff/line.rb
@@ -1,16 +1,17 @@
module Gitlab
module Diff
class Line
- SERIALIZE_KEYS = %i(line_code text type index old_pos new_pos).freeze
+ SERIALIZE_KEYS = %i(line_code rich_text text type index old_pos new_pos).freeze
attr_reader :line_code, :type, :index, :old_pos, :new_pos
attr_writer :rich_text
attr_accessor :text
- def initialize(text, type, index, old_pos, new_pos, parent_file: nil, line_code: nil)
+ def initialize(text, type, index, old_pos, new_pos, parent_file: nil, line_code: nil, rich_text: nil)
@text, @type, @index = text, type, index
@old_pos, @new_pos = old_pos, new_pos
@parent_file = parent_file
+ @rich_text = rich_text
# When line code is not provided from cache store we build it
# using the parent_file(Diff::File or Conflict::File).
@@ -18,7 +19,7 @@ module Gitlab
end
def self.init_from_hash(hash)
- new(hash[:text], hash[:type], hash[:index], hash[:old_pos], hash[:new_pos], line_code: hash[:line_code])
+ new(hash[:text], hash[:type], hash[:index], hash[:old_pos], hash[:new_pos], line_code: hash[:line_code], rich_text: hash[:rich_text])
end
def to_hash
diff --git a/spec/lib/gitlab/conflict/file_spec.rb b/spec/lib/gitlab/conflict/file_spec.rb
index 5b343920429..9095ffbfd52 100644
--- a/spec/lib/gitlab/conflict/file_spec.rb
+++ b/spec/lib/gitlab/conflict/file_spec.rb
@@ -69,10 +69,6 @@ describe Gitlab::Conflict::File do
CGI.unescapeHTML(ActionView::Base.full_sanitizer.sanitize(html)).delete("\n")
end
- it 'modifies the existing lines' do
- expect { conflict_file.highlight_lines! }.to change { conflict_file.lines.map(&:instance_variables) }
- end
-
it 'is called implicitly when rich_text is accessed on a line' do
expect(conflict_file).to receive(:highlight_lines!).once.and_call_original
diff --git a/spec/lib/gitlab/diff/line_spec.rb b/spec/lib/gitlab/diff/line_spec.rb
index e9d382d59c6..76d411973c7 100644
--- a/spec/lib/gitlab/diff/line_spec.rb
+++ b/spec/lib/gitlab/diff/line_spec.rb
@@ -1,4 +1,16 @@
describe Gitlab::Diff::Line do
+ describe '.init_from_hash' do
+ it 'round-trips correctly with to_hash' do
+ line = described_class.new('<input>', 'match', 0, 0, 1,
+ parent_file: double(:file),
+ line_code: double(:line_code),
+ rich_text: '&lt;input&gt;')
+
+ expect(described_class.init_from_hash(line.to_hash).to_hash)
+ .to eq(line.to_hash)
+ end
+ end
+
context "when setting rich text" do
it 'escapes any HTML special characters in the diff chunk header' do
subject = described_class.new("<input>", "", 0, 0, 0)