Commit 2e89f7c9 authored by nmilojevic1's avatar nmilojevic1

Fix MR comments

  Add empty lines in specs
  Fix format for DIFFLINENOTFOUNDMESSAGE
parent 948ac8b9
...@@ -26,7 +26,7 @@ class DiffNote < Note ...@@ -26,7 +26,7 @@ class DiffNote < Note
NoteDiffFileCreationError = Class.new(StandardError) NoteDiffFileCreationError = Class.new(StandardError)
DIFF_LINE_NOT_FOUND_MESSAGE = _("Failed to find diff line for: %{file_path}, new_pos: %{new_pos}, old_pos: %{old_pos}") DIFF_LINE_NOT_FOUND_MESSAGE = _("Failed to find diff line for: %{file_path}, old_line: %{old_line}, new_line: %{new_line}")
DIFF_FILE_NOT_FOUND_MESSAGE = _("Failed to find diff file") DIFF_FILE_NOT_FOUND_MESSAGE = _("Failed to find diff file")
after_commit :create_diff_file, on: :create after_commit :create_diff_file, on: :create
...@@ -45,8 +45,8 @@ class DiffNote < Note ...@@ -45,8 +45,8 @@ class DiffNote < Note
unless diff_line unless diff_line
raise NoteDiffFileCreationError, DIFF_LINE_NOT_FOUND_MESSAGE % { raise NoteDiffFileCreationError, DIFF_LINE_NOT_FOUND_MESSAGE % {
file_path: diff_file.file_path, file_path: diff_file.file_path,
new_pos: original_position.new_line, old_line: original_position.old_line,
old_pos: original_position.old_line new_line: original_position.new_line
} }
end end
......
...@@ -99,11 +99,13 @@ describe DiffNote do ...@@ -99,11 +99,13 @@ describe DiffNote do
new_line: 9, new_line: 9,
diff_refs: merge_request.diff_refs) diff_refs: merge_request.diff_refs)
end end
subject { build(:diff_note_on_merge_request, project: project, position: position, noteable: merge_request) } subject { build(:diff_note_on_merge_request, project: project, position: position, noteable: merge_request) }
let(:diff_file_from_repository) do let(:diff_file_from_repository) do
position.diff_file(project.repository) position.diff_file(project.repository)
end end
let(:diff_file) do let(:diff_file) do
diffs = merge_request.diffs diffs = merge_request.diffs
raw_diff = diffs.diffable.raw_diffs(diffs.diff_options.merge(paths: ['files/ruby/popen.rb'])).first raw_diff = diffs.diffable.raw_diffs(diffs.diff_options.merge(paths: ['files/ruby/popen.rb'])).first
...@@ -112,18 +114,23 @@ describe DiffNote do ...@@ -112,18 +114,23 @@ describe DiffNote do
diff_refs: diffs.diff_refs, diff_refs: diffs.diff_refs,
fallback_diff_refs: diffs.fallback_diff_refs) fallback_diff_refs: diffs.fallback_diff_refs)
end end
let(:diff_line) { diff_file.diff_lines.first } let(:diff_line) { diff_file.diff_lines.first }
before do before do
allow_any_instance_of(::Gitlab::Diff::Position).to receive(:line_code).with(project.repository).and_return('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14') allow_any_instance_of(::Gitlab::Diff::Position).to receive(:line_code).with(project.repository).and_return('2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_14')
end end
context 'when diffs are already created' do context 'when diffs are already created' do
before do before do
allow(subject).to receive(:created_at_diff?).and_return(true) allow(subject).to receive(:created_at_diff?).and_return(true)
end end
context 'when diff_file is found in persisted diffs' do context 'when diff_file is found in persisted diffs' do
before do before do
allow(merge_request).to receive_message_chain(:diffs, :diff_files, :first).and_return(diff_file) allow(merge_request).to receive_message_chain(:diffs, :diff_files, :first).and_return(diff_file)
end end
context 'when importing' do context 'when importing' do
before do before do
subject.importing = true subject.importing = true
...@@ -134,11 +141,13 @@ describe DiffNote do ...@@ -134,11 +141,13 @@ describe DiffNote do
before do before do
allow(diff_file).to receive(:line_for_position).with(position).and_return(diff_line) allow(diff_file).to receive(:line_for_position).with(position).and_return(diff_line)
end end
it 'creates a diff note file' do it 'creates a diff note file' do
subject.save subject.save
expect(subject.note_diff_file).to be_present expect(subject.note_diff_file).to be_present
end end
end end
context 'when diff_line is not found in persisted diff_file' do context 'when diff_line is not found in persisted diff_file' do
before do before do
allow(diff_file).to receive(:line_for_position).and_return(nil) allow(diff_file).to receive(:line_for_position).and_return(nil)
...@@ -150,12 +159,15 @@ describe DiffNote do ...@@ -150,12 +159,15 @@ describe DiffNote do
context 'when not importing' do context 'when not importing' do
context 'when diff_line is not found' do context 'when diff_line is not found' do
it 'raises an error' do before do
allow(diff_file).to receive(:line_for_position).with(position).and_return(nil) allow(diff_file).to receive(:line_for_position).with(position).and_return(nil)
end
it 'raises an error' do
expect { subject.save }.to raise_error(::DiffNote::NoteDiffFileCreationError, expect { subject.save }.to raise_error(::DiffNote::NoteDiffFileCreationError,
"Failed to find diff line for: #{diff_file.file_path}, "\ "Failed to find diff line for: #{diff_file.file_path}, "\
"new_pos: #{position.new_line}"\ "old_line: #{position.old_line}"\
", old_pos: #{position.old_line}") ", new_line: #{position.new_line}")
end end
end end
...@@ -180,10 +192,12 @@ describe DiffNote do ...@@ -180,10 +192,12 @@ describe DiffNote do
it_behaves_like 'a valid diff note with after commit callback' it_behaves_like 'a valid diff note with after commit callback'
end end
end end
context 'when diffs are not already created' do context 'when diffs are not already created' do
before do before do
allow(subject).to receive(:created_at_diff?).and_return(false) allow(subject).to receive(:created_at_diff?).and_return(false)
end end
it_behaves_like 'a valid diff note with after commit callback' it_behaves_like 'a valid diff note with after commit callback'
end end
......
...@@ -11,8 +11,8 @@ shared_examples 'a valid diff note with after commit callback' do ...@@ -11,8 +11,8 @@ shared_examples 'a valid diff note with after commit callback' do
allow(diff_file_from_repository).to receive(:line_for_position).with(position).and_return(nil) allow(diff_file_from_repository).to receive(:line_for_position).with(position).and_return(nil)
expect { subject.save }.to raise_error(::DiffNote::NoteDiffFileCreationError, expect { subject.save }.to raise_error(::DiffNote::NoteDiffFileCreationError,
"Failed to find diff line for: #{diff_file_from_repository.file_path}, "\ "Failed to find diff line for: #{diff_file_from_repository.file_path}, "\
"new_pos: #{position.new_line}"\ "old_line: #{position.old_line}"\
", old_pos: #{position.old_line}") ", new_line: #{position.new_line}")
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