diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-17 21:09:00 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-17 21:09:00 +0300 |
commit | eb1f5a3e087b7d6a3e85f2724b5a475cc9d9d37d (patch) | |
tree | d572a6d931152ae0dd10427237f5811893438552 /spec/lib/gitlab/diff | |
parent | b304a72312465ed4c0a568ee6a6ea5e97f705c9b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/diff')
-rw-r--r-- | spec/lib/gitlab/diff/lines_unfolder_spec.rb | 74 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/position_collection_spec.rb | 39 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/position_spec.rb | 26 |
3 files changed, 45 insertions, 94 deletions
diff --git a/spec/lib/gitlab/diff/lines_unfolder_spec.rb b/spec/lib/gitlab/diff/lines_unfolder_spec.rb index 3134ff3d817..ebcbe1fb1a0 100644 --- a/spec/lib/gitlab/diff/lines_unfolder_spec.rb +++ b/spec/lib/gitlab/diff/lines_unfolder_spec.rb @@ -212,14 +212,7 @@ describe Gitlab::Diff::LinesUnfolder do context 'position requires a middle expansion and new match lines' do let(:position) do - Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", - 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) + build(:text_diff_position, old_line: 43, new_line: 40) end context 'blob lines' do @@ -321,14 +314,7 @@ describe Gitlab::Diff::LinesUnfolder do context 'position requires a middle expansion and no top match line' do let(:position) do - Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", - 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) + build(:text_diff_position, old_line: 16, new_line: 17) end context 'blob lines' do @@ -422,14 +408,7 @@ describe Gitlab::Diff::LinesUnfolder do context 'position requires a middle expansion and no bottom match line' do let(:position) do - Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", - 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) + build(:text_diff_position, old_line: 82, new_line: 79) end context 'blob lines' do @@ -523,14 +502,7 @@ describe Gitlab::Diff::LinesUnfolder do context 'position requires a short top expansion' do let(:position) do - Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", - 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) + build(:text_diff_position, old_line: 6, new_line: 6) end context 'blob lines' do @@ -621,14 +593,7 @@ describe Gitlab::Diff::LinesUnfolder do context 'position sits between two match lines (no expasion needed)' do let(:position) do - Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", - 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) + build(:text_diff_position, old_line: 64, new_line: 61) end context 'diff lines' do @@ -640,14 +605,7 @@ describe Gitlab::Diff::LinesUnfolder do context 'position requires bottom expansion and new match lines' do let(:position) do - Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", - 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) + build(:text_diff_position, old_line: 107, new_line: 99) end context 'blob lines' do @@ -744,14 +702,7 @@ describe Gitlab::Diff::LinesUnfolder do context 'position requires bottom expansion and no new match line' do let(:position) do - Gitlab::Diff::Position.new(base_sha: "1c59dfa64afbea8c721bb09a06a9d326c952ea19", - 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) + build(:text_diff_position, old_line: 95, new_line: 87) end context 'blob lines' do @@ -844,16 +795,7 @@ describe Gitlab::Diff::LinesUnfolder do end context 'positioned on an image' do - let(:position) do - 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 + let(:position) { build(:image_diff_position) } before do allow(old_blob).to receive(:binary?).and_return(binary?) diff --git a/spec/lib/gitlab/diff/position_collection_spec.rb b/spec/lib/gitlab/diff/position_collection_spec.rb index f2a8312587c..dd8434ab10b 100644 --- a/spec/lib/gitlab/diff/position_collection_spec.rb +++ b/spec/lib/gitlab/diff/position_collection_spec.rb @@ -5,36 +5,17 @@ require 'spec_helper' describe Gitlab::Diff::PositionCollection do let(:merge_request) { build(:merge_request) } - def build_text_position(attrs = {}) - attributes = { - 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) + let(:text_position) do + build(:text_diff_position, :added, diff_refs: diff_refs) end - - def build_image_position(attrs = {}) - attributes = { - old_path: "files/images/any_image.png", - new_path: "files/images/any_image.png", - width: 10, - height: 10, - x: 1, - y: 1, - diff_refs: merge_request.diff_refs, - position_type: "image" - }.merge(attrs) - - Gitlab::Diff::Position.new(attributes) + let(:folded_text_position) do + build(:text_diff_position, diff_refs: diff_refs, old_line: 1, new_line: 1) + end + let(:image_position) do + build(:image_diff_position, diff_refs: diff_refs) end - let(:text_position) { build_text_position } - let(:folded_text_position) { build_text_position(old_line: 1, new_line: 1) } - let(:image_position) { build_image_position } + let(:diff_refs) { merge_request.diff_refs } let(:invalid_position) { 'a position' } let(:head_sha) { merge_request.diff_head_sha } @@ -71,7 +52,9 @@ describe Gitlab::Diff::PositionCollection do end 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 expect(collection.concat([new_text_position])).to be_a(described_class) diff --git a/spec/lib/gitlab/diff/position_spec.rb b/spec/lib/gitlab/diff/position_spec.rb index 839780b53fe..4b11ff16c38 100644 --- a/spec/lib/gitlab/diff/position_spec.rb +++ b/spec/lib/gitlab/diff/position_spec.rb @@ -35,6 +35,32 @@ describe Gitlab::Diff::Position do } 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 let(:commit) { project.commit("2ea1f3dec713d940208fb5ce4a38765ecb5d3f73") } |