diff options
author | Robert Speicher <robert@gitlab.com> | 2015-09-05 22:00:03 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2015-09-05 22:00:03 +0000 |
commit | 305d9e20cc048a83bd4799942357cd690dacdef3 (patch) | |
tree | 4863d4ce22191be6320887dc25bc0da1f8ae84f1 | |
parent | 5e3985ebd11ecc3d44d722eb41804e7017cea46b (diff) | |
parent | f8eca1724901cd5b8949c6bdff362405ff7ed754 (diff) | |
download | gitlab-ci-305d9e20cc048a83bd4799942357cd690dacdef3.tar.gz |
Merge branch 'fix-commits-ordering-for-postgresql' into 'master'
Fix commits ordering when using PostgreSQL
See merge request !243
-rw-r--r-- | CHANGELOG | 3 | ||||
-rw-r--r-- | app/models/project.rb | 2 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 18 |
3 files changed, 22 insertions, 1 deletions
@@ -1,5 +1,8 @@ v8.0.0 (unreleased) +v7.14.2 + - Fix commits ordering when using PostgreSQL + v7.14.1 - Fix skipped svg - Fix commits ordering diff --git a/app/models/project.rb b/app/models/project.rb index f0cf3a5..9b8815e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -28,7 +28,7 @@ class Project < ActiveRecord::Base include ProjectStatus - has_many :commits, ->() { order(:committed_at, :id) }, dependent: :destroy + has_many :commits, ->() { order('CASE WHEN commits.committed_at IS NULL THEN 0 ELSE 1 END', :committed_at, :id) }, dependent: :destroy has_many :builds, through: :commits, dependent: :destroy has_many :runner_projects, dependent: :destroy has_many :runners, through: :runner_projects diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index aa76b99..b6027a8 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -61,6 +61,24 @@ describe Project do end end + describe 'ordered commits' do + let (:project) { FactoryGirl.create :project } + + it 'returns ordered list of commits' do + commit1 = FactoryGirl.create :commit, committed_at: 1.hour.ago, project: project + commit2 = FactoryGirl.create :commit, committed_at: 2.hour.ago, project: project + project.commits.should == [commit2, commit1] + end + + it 'returns commits ordered by committed_at and id, with nulls last' do + commit1 = FactoryGirl.create :commit, committed_at: 1.hour.ago, project: project + commit2 = FactoryGirl.create :commit, committed_at: nil, project: project + commit3 = FactoryGirl.create :commit, committed_at: 2.hour.ago, project: project + commit4 = FactoryGirl.create :commit, committed_at: nil, project: project + project.commits.should == [commit2, commit4, commit3, commit1] + end + end + context :valid_project do let(:project) { FactoryGirl.create :project } |