2019-06-18 10:20:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe Branches::DivergingCommitCountsService do
|
2019-06-18 10:20:11 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:repository) { project.repository }
|
|
|
|
|
|
|
|
describe '#call' do
|
|
|
|
let(:diverged_branch) { repository.find_branch('fix') }
|
|
|
|
let(:root_ref_sha) { repository.raw_repository.commit(repository.root_ref).id }
|
|
|
|
let(:diverged_branch_sha) { diverged_branch.dereferenced_target.sha }
|
|
|
|
|
|
|
|
let(:service) { described_class.new(repository) }
|
|
|
|
|
|
|
|
it 'returns the commit counts behind and ahead of default branch' do
|
|
|
|
result = service.call(diverged_branch)
|
|
|
|
|
|
|
|
expect(result).to eq(behind: 29, ahead: 2)
|
|
|
|
end
|
|
|
|
|
2019-07-02 13:48:13 -04:00
|
|
|
it 'calls diverging_commit_count without max count' do
|
|
|
|
expect(repository.raw_repository)
|
|
|
|
.to receive(:diverging_commit_count)
|
|
|
|
.with(root_ref_sha, diverged_branch_sha)
|
|
|
|
.and_return([29, 2])
|
2019-06-18 10:20:11 -04:00
|
|
|
|
2019-07-02 13:48:13 -04:00
|
|
|
service.call(diverged_branch)
|
2019-06-18 10:20:11 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|