diff options
author | Robert Speicher <rspeicher@gmail.com> | 2017-01-04 21:43:06 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2017-01-05 03:09:28 +0300 |
commit | a00578ce5cdf4bab95990bca9e806c6322bb1384 (patch) | |
tree | 5aafe058fa55086038dbb3086121ad624447c0e4 /spec/lib/gitlab/git/compare_spec.rb | |
parent | aec04a47c16665f1dfb1fb61647c3f78a4dde20f (diff) |
Absorb gitlab_git
Diffstat (limited to 'spec/lib/gitlab/git/compare_spec.rb')
-rw-r--r-- | spec/lib/gitlab/git/compare_spec.rb | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/compare_spec.rb b/spec/lib/gitlab/git/compare_spec.rb new file mode 100644 index 00000000000..f66b68e4218 --- /dev/null +++ b/spec/lib/gitlab/git/compare_spec.rb @@ -0,0 +1,109 @@ +require "spec_helper" + +describe Gitlab::Git::Compare, seed_helper: true do + let(:repository) { Gitlab::Git::Repository.new(TEST_REPO_PATH) } + let(:compare) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, false) } + let(:compare_straight) { Gitlab::Git::Compare.new(repository, SeedRepo::BigCommit::ID, SeedRepo::Commit::ID, true) } + + describe :commits do + 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 + + describe :diffs do + 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 + + describe :same do + 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 + + describe :commits_straight do + 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 + + describe :diffs_straight do + 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 |