2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-01 16:52:26 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Gitlab::Diff::PositionTracer do
|
2019-07-05 07:03:47 -04:00
|
|
|
include PositionTracerHelpers
|
2016-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
subject do
|
|
|
|
described_class.new(
|
|
|
|
project: project,
|
|
|
|
old_diff_refs: old_diff_refs,
|
|
|
|
new_diff_refs: new_diff_refs
|
2016-07-01 16:52:26 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
context 'position is on text' do
|
|
|
|
let(:on_text?) { true }
|
2016-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-05-21 16:38:33 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
subject.trace(position)
|
2017-05-21 16:38:33 -04:00
|
|
|
end
|
|
|
|
end
|
2016-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
context 'position is not on text' do
|
|
|
|
let(:on_text?) { false }
|
2016-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
subject.trace(position)
|
2016-07-01 16:52:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
describe 'diffs methods' do
|
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:current_user) { project.owner }
|
2016-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
let(:old_diff_refs) do
|
|
|
|
diff_refs(
|
|
|
|
project.commit(create_branch('new-branch', 'master')[:branch].name),
|
|
|
|
create_file('new-branch', 'file.md', 'content')
|
2016-07-01 16:52:26 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
let(:new_diff_refs) do
|
|
|
|
diff_refs(
|
|
|
|
create_file('new-branch', 'file.md', 'content'),
|
|
|
|
update_file('new-branch', 'file.md', 'updatedcontent')
|
2016-07-01 16:52:26 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-07-01 16:52:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-07-01 16:52:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
describe '#cd_diffs' do
|
|
|
|
it 'returns the diffs in the new diff' do
|
|
|
|
diff_refs = subject.cd_diffs.diff_refs
|
2016-07-01 16:52:26 -04:00
|
|
|
|
2019-07-05 07:03:47 -04:00
|
|
|
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-07-01 16:52:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|