summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTimothy Andrew <mail@timothyandrew.net>2017-04-26 09:23:22 +0000
committerTimothy Andrew <mail@timothyandrew.net>2017-04-27 13:09:54 +0000
commita7e67604b3c64a4a9e0cea6e0f9b1fa85d1c30af (patch)
tree2f581d58f6cb0fa20b5c83ef988835ee75a70b9c /spec
parent3c6fad64296738239582ad449bb202cfd99ba7ff (diff)
downloadgitlab-ce-a7e67604b3c64a4a9e0cea6e0f9b1fa85d1c30af.tar.gz
Fix ordering of commits in the network graph.
- We upgraded `rugged` to 0.25.1.1 in !10286 for %9.1 - Prior to this upgrade, the default sort order for commits returned by `Gitlab::Git::Repository#find_commits` was `Rugged::SORT_DATE`, which the graph relied on. - While upgrading `rugged`, the MR also changed this default to `Rugged::SORT_NONE`, which broke commit ordering in the graph. - This commit adds an option to `Gitlab::Git::Repository#find_commits` to sort by date, and changes the graph builder `Network::Graph` so it explictly requests the `:date` sort order
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/git/repository_spec.rb29
-rw-r--r--spec/models/network/graph_spec.rb21
2 files changed, 50 insertions, 0 deletions
diff --git a/spec/lib/gitlab/git/repository_spec.rb b/spec/lib/gitlab/git/repository_spec.rb
index 3d6d7292b42..f88653cb1fe 100644
--- a/spec/lib/gitlab/git/repository_spec.rb
+++ b/spec/lib/gitlab/git/repository_spec.rb
@@ -1031,6 +1031,35 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
+ describe '#find_commits' do
+ it 'should return a return a collection of commits' do
+ commits = repository.find_commits
+
+ expect(commits).not_to be_empty
+ expect(commits).to all( be_a_kind_of(Gitlab::Git::Commit) )
+ end
+
+ context 'while applying a sort order based on the `order` option' do
+ it "allows ordering topologically (no parents shown before their children)" do
+ expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_TOPO)
+
+ repository.find_commits(order: :topo)
+ end
+
+ it "allows ordering by date" do
+ expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_DATE)
+
+ repository.find_commits(order: :date)
+ end
+
+ it "applies no sorting by default" do
+ expect_any_instance_of(Rugged::Walker).to receive(:sorting).with(Rugged::SORT_NONE)
+
+ repository.find_commits
+ end
+ end
+ end
+
describe '#branches with deleted branch' do
before(:each) do
ref = double()
diff --git a/spec/models/network/graph_spec.rb b/spec/models/network/graph_spec.rb
index 492c4e01bd8..46b36e11c23 100644
--- a/spec/models/network/graph_spec.rb
+++ b/spec/models/network/graph_spec.rb
@@ -9,4 +9,25 @@ describe Network::Graph, models: true do
expect(graph.notes).to eq( { note_on_commit.commit_id => 1 } )
end
+
+ 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
+ expect(commits).to all( be_kind_of(Network::Commit) )
+ end
+
+ it "sorts the commits by commit date (descending)" do
+ # 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
+ end
end