Commit 3d471c0d authored by Gary Holtz's avatar Gary Holtz Committed by Douglas Barbosa Alexandre

Adding a basic fix and a resulting spec

parent 57acb8eb
......@@ -18,13 +18,17 @@ module Gitlab
private
def raw_diff
"#{diff_header}\n#{from_content_as_diff}#{to_content_as_diff}"
"#{diff_header}\n#{from_content_as_diff}#{spacer}#{to_content_as_diff}"
end
def diff_header
"@@ -#{from_line} +#{from_line}"
end
def spacer
"\n" unless from_content_as_diff[-1, 3] == "\n"
end
def from_content_as_diff
from_content.lines.map { |line| line.prepend('-') }.join
end
......
......@@ -51,5 +51,22 @@ describe Gitlab::Diff::SuggestionDiff do
expect(diff_lines[index].to_hash).to include(expected_line)
end
end
describe 'when the suggestion is for the last line of a file' do
it 'returns a correct value if there is no newline at the end of the file' do
from_content = "One line test"
to_content = "Successful test!"
suggestion = instance_double(Suggestion, from_line: 1,
from_content: from_content,
to_content: to_content)
diff_lines = described_class.new(suggestion).diff_lines
bad_string = "-One line test+Successful test!"
diff_lines.each do |diff_line|
expect(diff_line.to_hash).not_to include(bad_string)
end
end
end
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