Commit 7de90f4b authored by Rubén Dávila's avatar Rubén Dávila

Fix broken spec and small refactor. #3945

parent b74f36c9
......@@ -56,7 +56,7 @@ module DiffHelper
#
diff_file.highlighted_diff_lines.each do |line|
full_line = line.highlighted_text
full_line = line.text
type = line.type
line_code = generate_line_code(diff_file.file_path, line)
line_new = line.new_pos
......@@ -67,7 +67,7 @@ module DiffHelper
if next_line
next_line_code = generate_line_code(diff_file.file_path, next_line)
next_type = next_line.type
next_line = next_line.highlighted_text
next_line = next_line.text
end
if type == 'match' || type.nil?
......
......@@ -22,7 +22,7 @@
= link_to_new_diff_note(line_code)
%td.new_line{data: {linenumber: line.new_pos}}
= link_to raw(type == "old" ? " " : line.new_pos) , "##{line_code}", id: line_code
%td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw(diff_line_content(line.highlighted_text))
%td.line_content{class: "noteable_line #{type} #{line_code}", "line_code" => line_code}= raw(diff_line_content(line.text))
- if @reply_allowed
- comments = @line_notes.select { |n| n.line_code == line_code && n.active? }.sort_by(&:created_at)
......
......@@ -25,7 +25,7 @@ module Gitlab
def update_diff_lines
@highlighted_code.lines.each_with_index do |line, i|
@diff_lines[i].highlighted_text = "#{@diff_line_prefixes[i]}#{line}"
@diff_lines[i].text = "#{@diff_line_prefixes[i]}#{line}"
end
@diff_lines
......
module Gitlab
module Diff
class Line
attr_reader :type, :text, :index, :old_pos, :new_pos
attr_accessor :highlighted_text
attr_reader :type, :index, :old_pos, :new_pos
attr_accessor :text
def initialize(text, type, index, old_pos, new_pos)
@text, @type, @index = text, type, index
......
---
- - match
- 6
- |
<span id="LC1" class="line"><span class="err">@@</span> <span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">12</span> <span class="o">+</span><span class="mi">6</span><span class="p">,</span><span class="mi">18</span> <span class="err">@@</span> <span class="k">module</span> <span class="nn">Popen</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6
- match
- 6
- |
<span id="LC1" class="line"><span class="err">@@</span> <span class="o">-</span><span class="mi">6</span><span class="p">,</span><span class="mi">12</span> <span class="o">+</span><span class="mi">6</span><span class="p">,</span><span class="mi">18</span> <span class="err">@@</span> <span class="k">module</span> <span class="nn">Popen</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6
- -
- 6
- |
<span id="LC2" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6
-
- 6
- |
<span id="LC2" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6
- -
- 7
- |
<span id="LC3" class="line"> <span class="k">def</span> <span class="nf">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7
-
- 7
- |
<span id="LC3" class="line"> <span class="k">def</span> <span class="nf">popen</span><span class="p">(</span><span class="n">cmd</span><span class="p">,</span> <span class="n">path</span><span class="o">=</span><span class="kp">nil</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7
- -
- 8
- |
<span id="LC4" class="line"> <span class="k">unless</span> <span class="n">cmd</span><span class="p">.</span><span class="nf">is_a?</span><span class="p">(</span><span class="no">Array</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8
-
- 8
- |
<span id="LC4" class="line"> <span class="k">unless</span> <span class="n">cmd</span><span class="p">.</span><span class="nf">is_a?</span><span class="p">(</span><span class="no">Array</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8
- - old
- 9
- |
- <span id="LC5" class="line"><span class="k">raise</span> <span class="s2">&quot;System commands must be given as an array of strings&quot;</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9
- new
- 9
- |
+ <span id="LC6" class="line"><span class="k">raise</span> <span class="idiff">RuntimeError, </span><span class="s2">&quot;System commands must be given as an array of strings&quot;</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9
- -
- 10
- |
<span id="LC7" class="line"> <span class="k">end</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10
-
- 10
- |
<span id="LC7" class="line"> <span class="k">end</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10
- -
- 11
- |
<span id="LC8" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11
-
- 11
- |
<span id="LC8" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11
- -
- 12
- |
<span id="LC9" class="line"> <span class="n">path</span> <span class="o">||=</span> <span class="no">Dir</span><span class="p">.</span><span class="nf">pwd</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12
-
- 12
- |
<span id="LC9" class="line"> <span class="n">path</span> <span class="o">||=</span> <span class="no">Dir</span><span class="p">.</span><span class="nf">pwd</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12
- - old
- 13
- |
- <span id="LC10" class="line"><span class="n">vars</span> <span class="o">=</span> <span class="p">{</span> <span class="s2">&quot;PWD&quot;</span> <span class="o">=&gt;</span> <span class="n">path</span> <span class="p">}</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13
- old
-
- "&nbsp;"
-
- - old
- 14
- |
- <span id="LC11" class="line"><span class="n">options</span> <span class="o">=</span> <span class="p">{</span> <span class="ss">chdir: </span><span class="n">path</span> <span class="p">}</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_14_13
- new
- 13
- |
+<span id="LC12" class="line"></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_13
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14
- new
- 14
- |
+ <span id="LC13" class="line"><span class="n">vars</span> <span class="o">=</span> <span class="p">{</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15
- new
- 15
- |
+ <span id="LC14" class="line"><span class="s2">&quot;PWD&quot;</span> <span class="o">=&gt;</span> <span class="n">path</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16
- new
- 16
- |
+ <span id="LC15" class="line"><span class="p">}</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17
- new
- 17
- |
+<span id="LC16" class="line"></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18
- new
- 18
- |
+ <span id="LC17" class="line"><span class="n">options</span> <span class="o">=</span> <span class="p">{</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19
- new
- 19
- |
+ <span id="LC18" class="line"><span class="ss">chdir: </span><span class="n">path</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20
- new
- 20
- |
+ <span id="LC19" class="line"><span class="p">}</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20
- -
- 15
- |
<span id="LC20" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21
-
- 21
- |
<span id="LC20" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21
- -
- 16
- |
<span id="LC21" class="line"> <span class="k">unless</span> <span class="no">File</span><span class="p">.</span><span class="nf">directory?</span><span class="p">(</span><span class="n">path</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22
-
- 22
- |
<span id="LC21" class="line"> <span class="k">unless</span> <span class="no">File</span><span class="p">.</span><span class="nf">directory?</span><span class="p">(</span><span class="n">path</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22
- -
- 17
- |
<span id="LC22" class="line"> <span class="no">FileUtils</span><span class="p">.</span><span class="nf">mkdir_p</span><span class="p">(</span><span class="n">path</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23
-
- 23
- |
<span id="LC22" class="line"> <span class="no">FileUtils</span><span class="p">.</span><span class="nf">mkdir_p</span><span class="p">(</span><span class="n">path</span><span class="p">)</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23
- - match
- 19
- |
<span id="LC23" class="line"><span class="err">@@</span> <span class="o">-</span><span class="mi">19</span><span class="p">,</span><span class="mi">6</span> <span class="o">+</span><span class="mi">25</span><span class="p">,</span><span class="mi">7</span> <span class="err">@@</span> <span class="k">module</span> <span class="nn">Popen</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25
- match
- 25
- |
<span id="LC23" class="line"><span class="err">@@</span> <span class="o">-</span><span class="mi">19</span><span class="p">,</span><span class="mi">6</span> <span class="o">+</span><span class="mi">25</span><span class="p">,</span><span class="mi">7</span> <span class="err">@@</span> <span class="k">module</span> <span class="nn">Popen</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25
- -
- 19
- |
<span id="LC24" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25
-
- 25
- |
<span id="LC24" class="line"> </span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25
- -
- 20
- |
<span id="LC25" class="line"> <span class="vi">@cmd_output</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26
-
- 26
- |
<span id="LC25" class="line"> <span class="vi">@cmd_output</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26
- -
- 21
- |
<span id="LC26" class="line"> <span class="vi">@cmd_status</span> <span class="o">=</span> <span class="mi">0</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27
-
- 27
- |
<span id="LC26" class="line"> <span class="vi">@cmd_status</span> <span class="o">=</span> <span class="mi">0</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27
- -
-
- "&nbsp;"
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28
- new
- 28
- |
+<span id="LC27" class="line"></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28
- -
- 22
- |
<span id="LC28" class="line"> <span class="no">Open3</span><span class="p">.</span><span class="nf">popen3</span><span class="p">(</span><span class="n">vars</span><span class="p">,</span> <span class="o">*</span><span class="n">cmd</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">stdin</span><span class="p">,</span> <span class="n">stdout</span><span class="p">,</span> <span class="n">stderr</span><span class="p">,</span> <span class="n">wait_thr</span><span class="o">|</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29
-
- 29
- |
<span id="LC28" class="line"> <span class="no">Open3</span><span class="p">.</span><span class="nf">popen3</span><span class="p">(</span><span class="n">vars</span><span class="p">,</span> <span class="o">*</span><span class="n">cmd</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">stdin</span><span class="p">,</span> <span class="n">stdout</span><span class="p">,</span> <span class="n">stderr</span><span class="p">,</span> <span class="n">wait_thr</span><span class="o">|</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29
- -
- 23
- |
<span id="LC29" class="line"> <span class="vi">@cmd_output</span> <span class="o">&lt;&lt;</span> <span class="n">stdout</span><span class="p">.</span><span class="nf">read</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30
-
- 30
- |
<span id="LC29" class="line"> <span class="vi">@cmd_output</span> <span class="o">&lt;&lt;</span> <span class="n">stdout</span><span class="p">.</span><span class="nf">read</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30
- -
- 24
- <span id="LC30" class="line"> <span class="vi">@cmd_output</span> <span
class="o">&lt;&lt;</span> <span class="n">stderr</span><span class="p">.</span><span
class="nf">read</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31
-
- 31
- <span id="LC30" class="line"> <span class="vi">@cmd_output</span> <span
class="o">&lt;&lt;</span> <span class="n">stderr</span><span class="p">.</span><span
class="nf">read</span></span>
- 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31
......@@ -131,34 +131,6 @@ describe DiffHelper do
end
def parallel_diff_result_array
[
["match", 6, "@@ -6,12 +6,18 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6", "match", 6, "@@ -6,12 +6,18 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6"],
[nil, 6, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6", nil, 6, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_6_6"], [nil, 7, " def popen(cmd, path=nil)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7", nil, 7, " def popen(cmd, path=nil)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_7_7"],
[nil, 8, " unless cmd.is_a?(Array)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8", nil, 8, " unless cmd.is_a?(Array)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_8_8"],
["old", 9, "- raise <span class='idiff'></span>&quot;System commands must be given as an array of strings&quot;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9", "new", 9, "+ raise <span class='idiff'>RuntimeError, </span>&quot;System commands must be given as an array of strings&quot;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9"],
[nil, 10, " end", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10", nil, 10, " end", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_10"],
[nil, 11, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11", nil, 11, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_11_11"],
[nil, 12, " path ||= Dir.pwd", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12", nil, 12, " path ||= Dir.pwd", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_12_12"],
["old", 13, "- vars = { &quot;PWD&quot; =&gt; path }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13", "old", nil, "&nbsp;", nil],
["old", 14, "- options = { chdir: path }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_14_13", "new", 13, "+", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_13"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14", "new", 14, "+ vars = {", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15", "new", 15, "+ &quot;PWD&quot; =&gt; path", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16", "new", 16, "+ }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_16"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17", "new", 17, "+", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_17"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18", "new", 18, "+ options = {", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_18"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19", "new", 19, "+ chdir: path", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_19"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20", "new", 20, "+ }", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_20"],
[nil, 15, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21", nil, 21, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_21"],
[nil, 16, " unless File.directory?(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22", nil, 22, " unless File.directory?(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_16_22"],
[nil, 17, " FileUtils.mkdir_p(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23", nil, 23, " FileUtils.mkdir_p(path)", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_17_23"],
["match", 19, "@@ -19,6 +25,7 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25", "match", 25, "@@ -19,6 +25,7 @@ module Popen", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25"],
[nil, 19, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25", nil, 25, " ", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_19_25"],
[nil, 20, " @cmd_output = &quot;&quot;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26", nil, 26, " @cmd_output = &quot;&quot;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26"],
[nil, 21, " @cmd_status = 0", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27", nil, 27, " @cmd_status = 0", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_21_27"],
[nil, nil, "&nbsp;", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28", "new", 28, "+", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_28"],
[nil, 22, " Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29", nil, 29, " Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_22_29"],
[nil, 23, " @cmd_output &lt;&lt; stdout.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30", nil, 30, " @cmd_output &lt;&lt; stdout.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_23_30"],
[nil, 24, " @cmd_output &lt;&lt; stderr.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31", nil, 31, " @cmd_output &lt;&lt; stderr.read", "2f6fcd96b88b36ce98c38da085c795a27d92a3dd_24_31"]
]
YAML.load_file("#{Rails.root}/spec/fixtures/parallel_diff_result.yml")
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment