2019-07-25 05:21:37 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-06-06 16:46:28 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 18:09:03 +00:00
|
|
|
RSpec.describe Gitlab::Diff::DiffRefs do
|
2017-06-06 16:46:28 +00:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
2017-09-25 13:25:45 +00:00
|
|
|
describe '#==' do
|
|
|
|
let(:commit) { project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') }
|
2019-12-12 12:07:33 +00:00
|
|
|
|
2017-09-25 13:25:45 +00:00
|
|
|
subject { commit.diff_refs }
|
|
|
|
|
|
|
|
context 'when shas are missing' do
|
|
|
|
let(:other) { described_class.new(base_sha: subject.base_sha, start_sha: subject.start_sha, head_sha: nil) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).not_to eq(other)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when shas are equal' do
|
|
|
|
let(:other) { described_class.new(base_sha: subject.base_sha, start_sha: subject.start_sha, head_sha: subject.head_sha) }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject).to eq(other)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when shas are unequal' do
|
|
|
|
let(:other) { described_class.new(base_sha: subject.base_sha, start_sha: subject.start_sha, head_sha: subject.head_sha.reverse) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).not_to eq(other)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when shas are truncated' do
|
|
|
|
context 'when sha prefixes are too short' do
|
|
|
|
let(:other) { described_class.new(base_sha: subject.base_sha[0, 4], start_sha: subject.start_sha[0, 4], head_sha: subject.head_sha[0, 4]) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).not_to eq(other)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sha prefixes are equal' do
|
|
|
|
let(:other) { described_class.new(base_sha: subject.base_sha[0, 10], start_sha: subject.start_sha[0, 10], head_sha: subject.head_sha[0, 10]) }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(subject).to eq(other)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when sha prefixes are unequal' do
|
|
|
|
let(:other) { described_class.new(base_sha: subject.base_sha[0, 10], start_sha: subject.start_sha[0, 10], head_sha: subject.head_sha[0, 10].reverse) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(subject).not_to eq(other)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-06-06 16:46:28 +00:00
|
|
|
describe '#compare_in' do
|
|
|
|
context 'with diff refs for the initial commit' do
|
|
|
|
let(:commit) { project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') }
|
2019-12-12 12:07:33 +00:00
|
|
|
|
2017-06-06 16:46:28 +00:00
|
|
|
subject { commit.diff_refs }
|
|
|
|
|
|
|
|
it 'returns an appropriate comparison' do
|
|
|
|
compare = subject.compare_in(project)
|
|
|
|
|
|
|
|
expect(compare.diff_refs).to eq(subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with diff refs for a commit' do
|
|
|
|
let(:commit) { project.commit('6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9') }
|
2019-12-12 12:07:33 +00:00
|
|
|
|
2017-06-06 16:46:28 +00:00
|
|
|
subject { commit.diff_refs }
|
|
|
|
|
|
|
|
it 'returns an appropriate comparison' do
|
|
|
|
compare = subject.compare_in(project)
|
|
|
|
|
|
|
|
expect(compare.diff_refs).to eq(subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with diff refs for a comparison through the base' do
|
|
|
|
subject do
|
|
|
|
described_class.new(
|
|
|
|
start_sha: '0b4bc9a49b562e85de7cc9e834518ea6828729b9', # feature
|
|
|
|
base_sha: 'ae73cb07c9eeaf35924a10f713b364d32b2dd34f',
|
|
|
|
head_sha: 'e63f41fe459e62e1228fcef60d7189127aeba95a' # master
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an appropriate comparison' do
|
|
|
|
compare = subject.compare_in(project)
|
|
|
|
|
|
|
|
expect(compare.diff_refs).to eq(subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with diff refs for a straight comparison' do
|
|
|
|
subject do
|
|
|
|
described_class.new(
|
|
|
|
start_sha: '0b4bc9a49b562e85de7cc9e834518ea6828729b9', # feature
|
|
|
|
base_sha: '0b4bc9a49b562e85de7cc9e834518ea6828729b9',
|
|
|
|
head_sha: 'e63f41fe459e62e1228fcef60d7189127aeba95a' # master
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an appropriate comparison' do
|
|
|
|
compare = subject.compare_in(project)
|
|
|
|
|
|
|
|
expect(compare.diff_refs).to eq(subject)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|