2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-20 12:18:06 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-07-10 10:24:02 -04:00
|
|
|
describe Network::Graph do
|
2017-01-26 17:44:58 -05:00
|
|
|
let(:project) { create(:project, :repository) }
|
2016-08-20 12:18:06 -04:00
|
|
|
let!(:note_on_commit) { create(:note_on_commit, project: project) }
|
|
|
|
|
|
|
|
it '#initialize' do
|
|
|
|
graph = described_class.new(project, 'refs/heads/master', project.repository.commit, nil)
|
|
|
|
|
|
|
|
expect(graph.notes).to eq( { note_on_commit.commit_id => 1 } )
|
|
|
|
end
|
2017-04-26 05:23:22 -04:00
|
|
|
|
2017-05-03 05:29:49 -04:00
|
|
|
describe '#commits' do
|
2017-04-26 05:23:22 -04:00
|
|
|
let(:graph) { described_class.new(project, 'refs/heads/master', project.repository.commit, nil) }
|
|
|
|
|
2017-05-03 05:29:49 -04:00
|
|
|
it 'returns a list of commits' do
|
2017-04-26 05:23:22 -04:00
|
|
|
commits = graph.commits
|
|
|
|
|
|
|
|
expect(commits).not_to be_empty
|
|
|
|
expect(commits).to all( be_kind_of(Network::Commit) )
|
|
|
|
end
|
|
|
|
|
2017-05-03 05:29:49 -04:00
|
|
|
it 'it the commits by commit date (descending)' do
|
2017-04-26 05:23:22 -04:00
|
|
|
# Remove duplicate timestamps because they make it harder to
|
|
|
|
# assert that the commits are sorted as expected.
|
|
|
|
commits = graph.commits.uniq(&:date)
|
|
|
|
sorted_commits = commits.sort_by(&:date).reverse
|
|
|
|
|
|
|
|
expect(commits).not_to be_empty
|
|
|
|
expect(commits.map(&:id)).to eq(sorted_commits.map(&:id))
|
|
|
|
end
|
2017-05-03 05:29:49 -04:00
|
|
|
|
|
|
|
it 'sorts children before parents for commits with the same timestamp' do
|
|
|
|
commits_by_time = graph.commits.group_by(&:date)
|
|
|
|
|
|
|
|
commits_by_time.each do |time, commits|
|
|
|
|
commit_ids = commits.map(&:id)
|
|
|
|
|
|
|
|
commits.each_with_index do |commit, index|
|
|
|
|
parent_indexes = commit.parent_ids.map { |parent_id| commit_ids.find_index(parent_id) }.compact
|
|
|
|
|
|
|
|
# All parents of the current commit should appear after it
|
|
|
|
expect(parent_indexes).to all( be > index )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-26 05:23:22 -04:00
|
|
|
end
|
2016-08-20 12:18:06 -04:00
|
|
|
end
|