Commit ff346a9a authored by Alex Kalderimis's avatar Alex Kalderimis Committed by Douglas Barbosa Alexandre

Ensure diff notes on designs are coherent

They need to have issues that have the same projects as the designs.
This change ensures that.

* More informative error message

The message 'is invalid' is less helpful than 'is incomplete', which
tells the user to look to the 'complete?' method

* Adds a factory for diff positions

we use this in the notes factory
parent 63c319bb
...@@ -161,7 +161,7 @@ class DiffNote < Note ...@@ -161,7 +161,7 @@ class DiffNote < Note
def positions_complete def positions_complete
return if self.original_position.complete? && self.position.complete? return if self.original_position.complete? && self.position.complete?
errors.add(:position, "is invalid") errors.add(:position, "is incomplete")
end end
def keep_around_commits def keep_around_commits
......
...@@ -21,17 +21,6 @@ FactoryBot.define do ...@@ -21,17 +21,6 @@ FactoryBot.define do
factory :note_on_epic, parent: :note, traits: [:on_epic] factory :note_on_epic, parent: :note, traits: [:on_epic]
factory :diff_note_on_design, parent: :note, traits: [:on_design], class: 'DiffNote' do factory :diff_note_on_design, parent: :note, traits: [:on_design], class: 'DiffNote' do
position do position { build(:image_diff_position, file: noteable.full_path) }
Gitlab::Diff::Position.new(
old_path: noteable.full_path,
new_path: noteable.full_path,
width: 10,
height: 10,
x: 1,
y: 1,
position_type: "image",
diff_refs: noteable.diff_refs
)
end
end end
end end
# frozen_string_literal: true
FactoryBot.define do
factory :diff_position, class: 'Gitlab::Diff::Position' do
skip_create # non-model factories (i.e. without #save)
transient do
file { 'path/to/file' }
# Allow diff to be passed as a single object.
diff_refs do
::Gitlab::Diff::DiffRefs.new(
base_sha: Digest::SHA1.hexdigest(SecureRandom.hex),
head_sha: Digest::SHA1.hexdigest(SecureRandom.hex),
start_sha: Digest::SHA1.hexdigest(SecureRandom.hex)
)
end
end
old_path { file }
new_path { file }
base_sha { diff_refs&.base_sha }
head_sha { diff_refs&.head_sha }
start_sha { diff_refs&.start_sha }
initialize_with { new(attributes) }
trait :moved do
new_path { 'path/to/new.file' }
end
factory :text_diff_position do
position_type { 'text' }
old_line { 10 }
new_line { 10 }
trait :added do
old_line { nil }
end
end
factory :image_diff_position do
position_type { 'image' }
x { 1 }
y { 1 }
width { 10 }
height { 10 }
end
end
end
...@@ -58,24 +58,20 @@ FactoryBot.define do ...@@ -58,24 +58,20 @@ FactoryBot.define do
end end
position do position do
Gitlab::Diff::Position.new( build(:text_diff_position,
old_path: "files/ruby/popen.rb", file: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb", old_line: nil,
old_line: nil, new_line: line_number,
new_line: line_number, diff_refs: diff_refs)
diff_refs: diff_refs
)
end end
trait :folded_position do trait :folded_position do
position do position do
Gitlab::Diff::Position.new( build(:text_diff_position,
old_path: "files/ruby/popen.rb", file: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb", old_line: 1,
old_line: 1, new_line: 1,
new_line: 1, diff_refs: diff_refs)
diff_refs: diff_refs
)
end end
end end
...@@ -86,16 +82,9 @@ FactoryBot.define do ...@@ -86,16 +82,9 @@ FactoryBot.define do
factory :image_diff_note_on_merge_request do factory :image_diff_note_on_merge_request do
position do position do
Gitlab::Diff::Position.new( build(:image_diff_position,
old_path: "files/images/any_image.png", file: "files/images/any_image.png",
new_path: "files/images/any_image.png", diff_refs: diff_refs)
width: 10,
height: 10,
x: 1,
y: 1,
diff_refs: diff_refs,
position_type: "image"
)
end end
end end
end end
...@@ -109,9 +98,8 @@ FactoryBot.define do ...@@ -109,9 +98,8 @@ FactoryBot.define do
end end
position do position do
Gitlab::Diff::Position.new( build(:text_diff_position,
old_path: "files/ruby/popen.rb", file: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil, old_line: nil,
new_line: line_number, new_line: line_number,
diff_refs: diff_refs diff_refs: diff_refs
......
...@@ -48,29 +48,11 @@ describe 'Merge request > User creates image diff notes', :js do ...@@ -48,29 +48,11 @@ describe 'Merge request > User creates image diff notes', :js do
let(:commit) { project.commit('2f63565e7aac07bcdadb654e253078b727143ec4') } let(:commit) { project.commit('2f63565e7aac07bcdadb654e253078b727143ec4') }
let(:note1_position) do let(:note1_position) do
Gitlab::Diff::Position.new( build(:image_diff_position, file: path, diff_refs: commit.diff_refs)
old_path: path,
new_path: path,
width: 100,
height: 100,
x: 10,
y: 10,
position_type: "image",
diff_refs: commit.diff_refs
)
end end
let(:note2_position) do let(:note2_position) do
Gitlab::Diff::Position.new( build(:image_diff_position, file: path, diff_refs: commit.diff_refs)
old_path: path,
new_path: path,
width: 100,
height: 100,
x: 20,
y: 20,
position_type: "image",
diff_refs: commit.diff_refs
)
end end
let!(:note1) { create(:diff_note_on_commit, commit_id: commit.id, project: project, position: note1_position, note: 'my note 1') } let!(:note1) { create(:diff_note_on_commit, commit_id: commit.id, project: project, position: note1_position, note: 'my note 1') }
...@@ -93,16 +75,7 @@ describe 'Merge request > User creates image diff notes', :js do ...@@ -93,16 +75,7 @@ describe 'Merge request > User creates image diff notes', :js do
%w(inline parallel).each do |view| %w(inline parallel).each do |view|
context "#{view} view" do context "#{view} view" do
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:image_diff_position, file: path, diff_refs: merge_request.diff_refs)
old_path: path,
new_path: path,
width: 100,
height: 100,
x: 1,
y: 1,
position_type: "image",
diff_refs: merge_request.diff_refs
)
end end
let!(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position) } let!(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: position) }
...@@ -167,16 +140,7 @@ describe 'Merge request > User creates image diff notes', :js do ...@@ -167,16 +140,7 @@ describe 'Merge request > User creates image diff notes', :js do
let(:path) { "files/images/ee_repo_logo.png" } let(:path) { "files/images/ee_repo_logo.png" }
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:image_diff_position, file: path, diff_refs: merge_request.diff_refs)
old_path: path,
new_path: path,
width: 100,
height: 100,
x: 50,
y: 50,
position_type: "image",
diff_refs: merge_request.diff_refs
)
end end
before do before do
......
...@@ -10,13 +10,9 @@ describe 'Merge request > User resolves diff notes and threads', :js do ...@@ -10,13 +10,9 @@ describe 'Merge request > User resolves diff notes and threads', :js do
let!(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, note: "| Markdown | Table |\n|-------|---------|\n| first | second |") } let!(:note) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, note: "| Markdown | Table |\n|-------|---------|\n| first | second |") }
let(:path) { "files/ruby/popen.rb" } let(:path) { "files/ruby/popen.rb" }
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:text_diff_position,
old_path: path, file: path, old_line: nil, new_line: 9,
new_path: path, diff_refs: merge_request.diff_refs)
old_line: nil,
new_line: 9,
diff_refs: merge_request.diff_refs
)
end end
before do before do
......
...@@ -13,20 +13,16 @@ describe 'Merge request > User resolves outdated diff discussions', :js do ...@@ -13,20 +13,16 @@ describe 'Merge request > User resolves outdated diff discussions', :js do
let(:current_diff_refs) { merge_request.diff_refs } let(:current_diff_refs) { merge_request.diff_refs }
let(:outdated_position) do let(:outdated_position) do
Gitlab::Diff::Position.new( build(:text_diff_position, :added,
old_path: 'files/csv/Book1.csv', file: 'files/csv/Book1.csv',
new_path: 'files/csv/Book1.csv',
old_line: nil,
new_line: 9, new_line: 9,
diff_refs: outdated_diff_refs diff_refs: outdated_diff_refs
) )
end end
let(:current_position) do let(:current_position) do
Gitlab::Diff::Position.new( build(:text_diff_position, :added,
old_path: 'files/csv/Book1.csv', file: 'files/csv/Book1.csv',
new_path: 'files/csv/Book1.csv',
old_line: nil,
new_line: 1, new_line: 1,
diff_refs: current_diff_refs diff_refs: current_diff_refs
) )
......
...@@ -10,10 +10,8 @@ describe 'Merge request > User sees avatars on diff notes', :js do ...@@ -10,10 +10,8 @@ describe 'Merge request > User sees avatars on diff notes', :js do
let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user, title: 'Bug NS-04') } let(:merge_request) { create(:merge_request_with_diffs, source_project: project, author: user, title: 'Bug NS-04') }
let(:path) { 'files/ruby/popen.rb' } let(:path) { 'files/ruby/popen.rb' }
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:text_diff_position, :added,
old_path: path, file: path,
new_path: path,
old_line: nil,
new_line: 9, new_line: 9,
diff_refs: merge_request.diff_refs diff_refs: merge_request.diff_refs
) )
......
...@@ -18,10 +18,8 @@ describe 'Merge request > User sees threads', :js do ...@@ -18,10 +18,8 @@ describe 'Merge request > User sees threads', :js do
let!(:outdated_discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: outdated_position).to_discussion } let!(:outdated_discussion) { create(:diff_note_on_merge_request, project: project, noteable: merge_request, position: outdated_position).to_discussion }
let!(:active_discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion } let!(:active_discussion) { create(:diff_note_on_merge_request, noteable: merge_request, project: project).to_discussion }
let(:outdated_position) do let(:outdated_position) do
Gitlab::Diff::Position.new( build(:text_diff_position, :added,
old_path: "files/ruby/popen.rb", file: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 9, new_line: 9,
diff_refs: outdated_diff_refs diff_refs: outdated_diff_refs
) )
......
...@@ -86,10 +86,8 @@ describe 'Merge request > User sees versions', :js do ...@@ -86,10 +86,8 @@ describe 'Merge request > User sees versions', :js do
it 'shows comments that were last relevant at that version' do it 'shows comments that were last relevant at that version' do
expect(page).to have_content '5 files' expect(page).to have_content '5 files'
position = Gitlab::Diff::Position.new( position = build(:text_diff_position, :added,
old_path: ".gitmodules", file: ".gitmodules",
new_path: ".gitmodules",
old_line: nil,
new_line: 4, new_line: 4,
diff_refs: merge_request_diff1.diff_refs diff_refs: merge_request_diff1.diff_refs
) )
...@@ -136,9 +134,8 @@ describe 'Merge request > User sees versions', :js do ...@@ -136,9 +134,8 @@ describe 'Merge request > User sees versions', :js do
expect(additions_content).to eq '15' expect(additions_content).to eq '15'
expect(deletions_content).to eq '6' expect(deletions_content).to eq '6'
position = Gitlab::Diff::Position.new( position = build(:text_diff_position,
old_path: ".gitmodules", file: ".gitmodules",
new_path: ".gitmodules",
old_line: 4, old_line: 4,
new_line: 4, new_line: 4,
diff_refs: merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs diff_refs: merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs
......
...@@ -36,10 +36,8 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont ...@@ -36,10 +36,8 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
end end
let(:path) { "files/ruby/popen.rb" } let(:path) { "files/ruby/popen.rb" }
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:text_diff_position, :added,
old_path: path, file: path,
new_path: path,
old_line: nil,
new_line: 14, new_line: 14,
diff_refs: merge_request.diff_refs diff_refs: merge_request.diff_refs
) )
...@@ -112,14 +110,8 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont ...@@ -112,14 +110,8 @@ describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :cont
let(:merge_request2) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, title: "Added images") } let(:merge_request2) { create(:merge_request_with_diffs, :with_image_diffs, source_project: project, title: "Added images") }
let(:image_path) { "files/images/ee_repo_logo.png" } let(:image_path) { "files/images/ee_repo_logo.png" }
let(:image_position) do let(:image_position) do
Gitlab::Diff::Position.new( build(:image_diff_position,
old_path: image_path, file: image_path,
new_path: image_path,
width: 100,
height: 100,
x: 1,
y: 1,
position_type: "image",
diff_refs: merge_request2.diff_refs diff_refs: merge_request2.diff_refs
) )
end end
......
...@@ -12,10 +12,8 @@ describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)', type ...@@ -12,10 +12,8 @@ describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)', type
let(:path) { "files/ruby/popen.rb" } let(:path) { "files/ruby/popen.rb" }
let(:selected_commit) { merge_request.all_commits[0] } let(:selected_commit) { merge_request.all_commits[0] }
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:text_diff_position, :added,
old_path: path, file: path,
new_path: path,
old_line: nil,
new_line: 14, new_line: 14,
diff_refs: merge_request.diff_refs diff_refs: merge_request.diff_refs
) )
......
...@@ -62,10 +62,8 @@ describe NotesHelper do ...@@ -62,10 +62,8 @@ describe NotesHelper do
context 'when the discussion is on an older merge request version' do context 'when the discussion is on an older merge request version' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:text_diff_position, :added,
old_path: ".gitmodules", file: ".gitmodules",
new_path: ".gitmodules",
old_line: nil,
new_line: 4, new_line: 4,
diff_refs: merge_request_diff1.diff_refs diff_refs: merge_request_diff1.diff_refs
) )
...@@ -86,9 +84,8 @@ describe NotesHelper do ...@@ -86,9 +84,8 @@ describe NotesHelper do
context 'when the discussion is on a comparison between merge request versions' do context 'when the discussion is on a comparison between merge request versions' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new( build(:text_diff_position,
old_path: ".gitmodules", file: ".gitmodules",
new_path: ".gitmodules",
old_line: 4, old_line: 4,
new_line: 4, new_line: 4,
diff_refs: merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs diff_refs: merge_request_diff3.compare_with(merge_request_diff1.head_commit_sha).diff_refs
......
...@@ -212,14 +212,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -212,14 +212,7 @@ describe Gitlab::Diff::LinesUnfolder do
context 'position requires a middle expansion and new match lines' do context 'position requires a middle expansion and new match lines' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", build(:text_diff_position, old_line: 43, new_line: 40)
start_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19",
head_sha: "1487062132228de836236c522fe52fed4980a46c",
old_path: "build-aux/flatpak/org.gnome.Nautilus.json",
new_path: "build-aux/flatpak/org.gnome.Nautilus.json",
position_type: "text",
old_line: 43,
new_line: 40)
end end
context 'blob lines' do context 'blob lines' do
...@@ -321,14 +314,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -321,14 +314,7 @@ describe Gitlab::Diff::LinesUnfolder do
context 'position requires a middle expansion and no top match line' do context 'position requires a middle expansion and no top match line' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", build(:text_diff_position, old_line: 16, new_line: 17)
start_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19",
head_sha: "1487062132228de836236c522fe52fed4980a46c",
old_path: "build-aux/flatpak/org.gnome.Nautilus.json",
new_path: "build-aux/flatpak/org.gnome.Nautilus.json",
position_type: "text",
old_line: 16,
new_line: 17)
end end
context 'blob lines' do context 'blob lines' do
...@@ -422,14 +408,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -422,14 +408,7 @@ describe Gitlab::Diff::LinesUnfolder do
context 'position requires a middle expansion and no bottom match line' do context 'position requires a middle expansion and no bottom match line' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", build(:text_diff_position, old_line: 82, new_line: 79)
start_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19",
head_sha: "1487062132228de836236c522fe52fed4980a46c",
old_path: "build-aux/flatpak/org.gnome.Nautilus.json",
new_path: "build-aux/flatpak/org.gnome.Nautilus.json",
position_type: "text",
old_line: 82,
new_line: 79)
end end
context 'blob lines' do context 'blob lines' do
...@@ -523,14 +502,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -523,14 +502,7 @@ describe Gitlab::Diff::LinesUnfolder do
context 'position requires a short top expansion' do context 'position requires a short top expansion' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", build(:text_diff_position, old_line: 6, new_line: 6)
start_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19",
head_sha: "1487062132228de836236c522fe52fed4980a46c",
old_path: "build-aux/flatpak/org.gnome.Nautilus.json",
new_path: "build-aux/flatpak/org.gnome.Nautilus.json",
position_type: "text",
old_line: 6,
new_line: 6)
end end
context 'blob lines' do context 'blob lines' do
...@@ -621,14 +593,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -621,14 +593,7 @@ describe Gitlab::Diff::LinesUnfolder do
context 'position sits between two match lines (no expasion needed)' do context 'position sits between two match lines (no expasion needed)' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", build(:text_diff_position, old_line: 64, new_line: 61)
start_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19",
head_sha: "1487062132228de836236c522fe52fed4980a46c",
old_path: "build-aux/flatpak/org.gnome.Nautilus.json",
new_path: "build-aux/flatpak/org.gnome.Nautilus.json",
position_type: "text",
old_line: 64,
new_line: 61)
end end
context 'diff lines' do context 'diff lines' do
...@@ -640,14 +605,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -640,14 +605,7 @@ describe Gitlab::Diff::LinesUnfolder do
context 'position requires bottom expansion and new match lines' do context 'position requires bottom expansion and new match lines' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", build(:text_diff_position, old_line: 107, new_line: 99)
start_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19",
head_sha: "1487062132228de836236c522fe52fed4980a46c",
old_path: "build-aux/flatpak/org.gnome.Nautilus.json",
new_path: "build-aux/flatpak/org.gnome.Nautilus.json",
position_type: "text",
old_line: 107,
new_line: 99)
end end
context 'blob lines' do context 'blob lines' do
...@@ -744,14 +702,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -744,14 +702,7 @@ describe Gitlab::Diff::LinesUnfolder do
context 'position requires bottom expansion and no new match line' do context 'position requires bottom expansion and no new match line' do
let(:position) do let(:position) do
Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", build(:text_diff_position, old_line: 95, new_line: 87)
start_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19",
head_sha: "1487062132228de836236c522fe52fed4980a46c",
old_path: "build-aux/flatpak/org.gnome.Nautilus.json",
new_path: "build-aux/flatpak/org.gnome.Nautilus.json",
position_type: "text",
old_line: 95,
new_line: 87)
end end
context 'blob lines' do context 'blob lines' do
...@@ -844,16 +795,7 @@ describe Gitlab::Diff::LinesUnfolder do ...@@ -844,16 +795,7 @@ describe Gitlab::Diff::LinesUnfolder do
end end
context 'positioned on an image' do context 'positioned on an image' do
let(:position) do let(:position) { build(:image_diff_position) }
Gitlab::Diff::Position.new(
base_sha: '1c59dfa64afbea8c721bb09a06a9d326c952ea19',
start_sha: '1c59dfa64afbea8c721bb09a06a9d326c952ea19',
head_sha: '1487062132228de836236c522fe52fed4980a46c',
old_path: 'image.jpg',
new_path: 'image.jpg',
position_type: 'image'
)
end
before do before do
allow(old_blob).to receive(:binary?).and_return(binary?) allow(old_blob).to receive(:binary?).and_return(binary?)
......
...@@ -5,36 +5,17 @@ require 'spec_helper' ...@@ -5,36 +5,17 @@ require 'spec_helper'
describe Gitlab::Diff::PositionCollection do describe Gitlab::Diff::PositionCollection do
let(:merge_request) { build(:merge_request) } let(:merge_request) { build(:merge_request) }
def build_text_position(attrs = {}) let(:text_position) do
attributes = { build(:text_diff_position, :added, diff_refs: diff_refs)
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
diff_refs: merge_request.diff_refs
}.merge(attrs)
Gitlab::Diff::Position.new(attributes)
end end
let(:folded_text_position) do
def build_image_position(attrs = {}) build(:text_diff_position, diff_refs: diff_refs, old_line: 1, new_line: 1)
attributes = { end
old_path: "files/images/any_image.png", let(:image_position) do
new_path: "files/images/any_image.png", build(:image_diff_position, diff_refs: diff_refs)
width: 10,
height: 10,
x: 1,
y: 1,
diff_refs: merge_request.diff_refs,
position_type: "image"
}.merge(attrs)
Gitlab::Diff::Position.new(attributes)
end end
let(:text_position) { build_text_position } let(:diff_refs) { merge_request.diff_refs }
let(:folded_text_position) { build_text_position(old_line: 1, new_line: 1) }
let(:image_position) { build_image_position }
let(:invalid_position) { 'a position' } let(:invalid_position) { 'a position' }
let(:head_sha) { merge_request.diff_head_sha } let(:head_sha) { merge_request.diff_head_sha }
...@@ -71,7 +52,9 @@ describe Gitlab::Diff::PositionCollection do ...@@ -71,7 +52,9 @@ describe Gitlab::Diff::PositionCollection do
end end
describe '#concat' do describe '#concat' do
let(:new_text_position) { build_text_position(old_line: 1, new_line: 1) } let(:new_text_position) do
build(:text_diff_position, diff_refs: diff_refs, old_line: 1, new_line: 1)
end
it 'returns a Gitlab::Diff::Position' do it 'returns a Gitlab::Diff::Position' do
expect(collection.concat([new_text_position])).to be_a(described_class) expect(collection.concat([new_text_position])).to be_a(described_class)
......
...@@ -35,6 +35,32 @@ describe Gitlab::Diff::Position do ...@@ -35,6 +35,32 @@ describe Gitlab::Diff::Position do
} }
end end
describe 'factory' do
it 'produces a complete text position' do
position = build(:text_diff_position)
expect(position).to be_complete
expect(position).to have_attributes(position_type: 'text')
end
it 'produces a complete image position' do
position = build(:image_diff_position)
expect(position).to be_complete
expect(position).to have_attributes(position_type: 'image')
end
it 'allows the diff_refs to be passed as a single object' do
head_sha = Digest::SHA1.hexdigest(SecureRandom.hex)
base_sha = Digest::SHA1.hexdigest(SecureRandom.hex)
start_sha = Digest::SHA1.hexdigest(SecureRandom.hex)
refs = ::Gitlab::Diff::DiffRefs.new(base_sha: base_sha, start_sha: start_sha, head_sha: head_sha)
expect(build(:diff_position, diff_refs: refs).diff_refs).to eq(refs)
end
end
describe "position for an added text file" do describe "position for an added text file" do
let(:commit) { project.commit("2ea1f3dec713d940208fb5ce4a38765ecb5d3f73") } let(:commit) { project.commit("2ea1f3dec713d940208fb5ce4a38765ecb5d3f73") }
......
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