debian-mirror-gitlab/spec/models/network/graph_spec.rb

65 lines
1.9 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-09-13 17:45:13 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Network::Graph do
2017-08-17 22:00:37 +05:30
let(:project) { create(:project, :repository) }
2016-09-13 17:45:13 +05:30
let!(:note_on_commit) { create(:note_on_commit, project: project) }
2023-01-13 00:05:48 +05:30
describe '#initialize' do
let(:graph) do
described_class.new(project, 'refs/heads/master', project.repository.commit, nil)
end
it 'has initialized' do
expect(graph).to be_a(described_class)
end
2016-09-13 17:45:13 +05:30
2023-01-13 00:05:48 +05:30
context 'when disable_network_graph_note_counts is disabled' do
before do
stub_feature_flags(disable_network_graph_notes_count: false)
end
it 'initializes the notes hash' do
expect(graph.notes).to eq({ note_on_commit.commit_id => 1 })
end
end
2016-09-13 17:45:13 +05:30
end
2017-08-17 22:00:37 +05:30
describe '#commits' do
let(:graph) { described_class.new(project, 'refs/heads/master', project.repository.commit, nil) }
it 'returns a list of commits' do
commits = graph.commits
expect(commits).not_to be_empty
2023-01-13 00:05:48 +05:30
expect(commits).to all(be_kind_of(Network::Commit))
2017-08-17 22:00:37 +05:30
end
2019-07-07 11:18:12 +05:30
it 'sorts commits by commit date (descending)' do
2017-08-17 22:00:37 +05:30
# 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
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
2023-01-13 00:05:48 +05:30
expect(parent_indexes).to all(be > index)
2017-08-17 22:00:37 +05:30
end
end
end
end
2016-09-13 17:45:13 +05:30
end