Add specs

This commit is contained in:
Douwe Maan 2017-09-25 15:25:45 +02:00
parent 19a30595d9
commit c19030332c
2 changed files with 93 additions and 0 deletions

View File

@ -3,6 +3,61 @@ require 'spec_helper'
describe Gitlab::Diff::DiffRefs do
let(:project) { create(:project, :repository) }
describe '#==' do
let(:commit) { project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') }
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
describe '#compare_in' do
context 'with diff refs for the initial commit' do
let(:commit) { project.commit('1a0b36b3cdad1d2ee32457c102a8c0b7056fa863') }

View File

@ -429,6 +429,44 @@ describe Gitlab::Diff::Position do
end
end
describe '#==' do
let(:commit) { project.commit("570e7b2abdd848b95f2f578043fc23bd6f6fd24d") }
subject do
described_class.new(
old_path: "files/ruby/popen.rb",
new_path: "files/ruby/popen.rb",
old_line: nil,
new_line: 14,
diff_refs: commit.diff_refs
)
end
context 'when positions are equal' do
let(:other) { described_class.new(subject.to_h) }
it 'returns true' do
expect(subject).to eq(other)
end
end
context 'when positions are equal, except for truncated shas' do
let(:other) { described_class.new(subject.to_h.merge(start_sha: subject.start_sha[0, 10])) }
it 'returns true' do
expect(subject).to eq(other)
end
end
context 'when positions are unequal' do
let(:other) { described_class.new(subject.to_h.merge(start_sha: subject.start_sha.reverse)) }
it 'returns false' do
expect(subject).not_to eq(other)
end
end
end
describe "#to_json" do
let(:hash) do
{