2017-01-04 13:43:06 -05:00
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
describe Gitlab::Git::Compare, seed_helper: true do
|
2017-02-15 21:08:30 -05:00
|
|
|
let(:repository) { Gitlab::Git::Repository.new('default', TEST_REPO_PATH) }
|
2017-06-06 12:46:28 -04:00
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, straight: false) }
|
|
|
|
let(:compare_straight) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, straight: true) }
|
2017-01-04 13:43:06 -05:00
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#commits' do
|
2017-01-04 13:43:06 -05:00
|
|
|
subject do
|
|
|
|
compare.commits.map(&:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has 8 elements' do
|
|
|
|
expect(subject.size).to eq(8)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(SeedRepo::Commit::PARENT_ID) }
|
|
|
|
it { is_expected.not_to include(SeedRepo::BigCommit::PARENT_ID) }
|
|
|
|
|
|
|
|
context 'non-existing base ref' do
|
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'non-existing head ref' do
|
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'base ref is equal to head ref' do
|
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'providing nil as base ref or head ref' do
|
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, nil, nil) }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#diffs' do
|
2017-01-04 13:43:06 -05:00
|
|
|
subject do
|
|
|
|
compare.diffs.map(&:new_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has 10 elements' do
|
|
|
|
expect(subject.size).to eq(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include('files/ruby/popen.rb') }
|
|
|
|
it { is_expected.not_to include('LICENSE') }
|
|
|
|
|
|
|
|
context 'non-existing base ref' do
|
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, 'no-such-branch', SeedRepo::Commit::ID) }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'non-existing head ref' do
|
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, '1234567890') }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#same' do
|
2017-01-04 13:43:06 -05:00
|
|
|
subject do
|
|
|
|
compare.same
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to eq(false) }
|
|
|
|
|
|
|
|
context 'base ref is equal to head ref' do
|
|
|
|
let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::BigCommit::ID) }
|
|
|
|
|
|
|
|
it { is_expected.to eq(true) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#commits', 'straight compare' do
|
2017-01-04 13:43:06 -05:00
|
|
|
subject do
|
|
|
|
compare_straight.commits.map(&:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has 8 elements' do
|
|
|
|
expect(subject.size).to eq(8)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(SeedRepo::Commit::PARENT_ID) }
|
|
|
|
it { is_expected.not_to include(SeedRepo::BigCommit::PARENT_ID) }
|
|
|
|
end
|
|
|
|
|
2017-03-24 19:04:03 -04:00
|
|
|
describe '#diffs', 'straight compare' do
|
2017-01-04 13:43:06 -05:00
|
|
|
subject do
|
|
|
|
compare_straight.diffs.map(&:new_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has 10 elements' do
|
|
|
|
expect(subject.size).to eq(10)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include('files/ruby/popen.rb') }
|
|
|
|
it { is_expected.not_to include('LICENSE') }
|
|
|
|
end
|
|
|
|
end
|