2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::Diff::PositionTracer do
|
2019-09-30 21:07:59 +05:30
|
|
|
include PositionTracerHelpers
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
subject do
|
|
|
|
described_class.new(
|
|
|
|
project: project,
|
|
|
|
old_diff_refs: old_diff_refs,
|
|
|
|
new_diff_refs: new_diff_refs
|
2016-08-24 12:49:21 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe '#trace' do
|
|
|
|
let(:diff_refs) { double(complete?: true) }
|
|
|
|
let(:project) { double }
|
|
|
|
let(:old_diff_refs) { diff_refs }
|
|
|
|
let(:new_diff_refs) { diff_refs }
|
|
|
|
let(:position) { double(on_text?: on_text?, diff_refs: diff_refs) }
|
|
|
|
let(:tracer) { double }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
context 'position is on text' do
|
|
|
|
let(:on_text?) { true }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'calls LineStrategy#trace' do
|
|
|
|
expect(Gitlab::Diff::PositionTracer::LineStrategy)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(subject)
|
|
|
|
.and_return(tracer)
|
|
|
|
expect(tracer).to receive(:trace).with(position)
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
subject.trace(position)
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
|
|
|
end
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
context 'position is not on text' do
|
|
|
|
let(:on_text?) { false }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
it 'calls ImageStrategy#trace' do
|
|
|
|
expect(Gitlab::Diff::PositionTracer::ImageStrategy)
|
|
|
|
.to receive(:new)
|
|
|
|
.with(subject)
|
|
|
|
.and_return(tracer)
|
|
|
|
expect(tracer).to receive(:trace).with(position)
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
subject.trace(position)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe 'diffs methods' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:current_user) { project.owner }
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:old_diff_refs) do
|
|
|
|
diff_refs(
|
|
|
|
project.commit(create_branch('new-branch', 'master')[:branch].name),
|
|
|
|
create_file('new-branch', 'file.md', 'content')
|
2016-08-24 12:49:21 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
let(:new_diff_refs) do
|
|
|
|
diff_refs(
|
|
|
|
create_file('new-branch', 'file.md', 'content'),
|
|
|
|
update_file('new-branch', 'file.md', 'updatedcontent')
|
2016-08-24 12:49:21 +05:30
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe '#ac_diffs' do
|
|
|
|
it 'returns the diffs between the base of old and new diff' do
|
|
|
|
diff_refs = subject.ac_diffs.diff_refs
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(diff_refs.base_sha).to eq(old_diff_refs.base_sha)
|
|
|
|
expect(diff_refs.start_sha).to eq(old_diff_refs.base_sha)
|
|
|
|
expect(diff_refs.head_sha).to eq(new_diff_refs.base_sha)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe '#bd_diffs' do
|
|
|
|
it 'returns the diffs between the HEAD of old and new diff' do
|
|
|
|
diff_refs = subject.bd_diffs.diff_refs
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(diff_refs.base_sha).to eq(old_diff_refs.head_sha)
|
|
|
|
expect(diff_refs.start_sha).to eq(old_diff_refs.head_sha)
|
|
|
|
expect(diff_refs.head_sha).to eq(new_diff_refs.head_sha)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
describe '#cd_diffs' do
|
|
|
|
it 'returns the diffs in the new diff' do
|
|
|
|
diff_refs = subject.cd_diffs.diff_refs
|
2016-08-24 12:49:21 +05:30
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
expect(diff_refs.base_sha).to eq(new_diff_refs.base_sha)
|
|
|
|
expect(diff_refs.start_sha).to eq(new_diff_refs.base_sha)
|
|
|
|
expect(diff_refs.head_sha).to eq(new_diff_refs.head_sha)
|
2016-08-24 12:49:21 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|