Skip to content
Snippets Groups Projects
Commit 93e26e2e authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Robert Speicher
Browse files

Fix commits ordering when using PostgreSQL

parent 91726e6f
No related branches found
No related tags found
No related merge requests found
v7.14.2 v7.14.2
- Fix commits ordering when using PostgreSQL
   
v7.14.1 v7.14.1
- Fix "skipped" svg - Fix "skipped" svg
Loading
Loading
Loading
@@ -28,7 +28,7 @@
Loading
@@ -28,7 +28,7 @@
class Project < ActiveRecord::Base class Project < ActiveRecord::Base
include ProjectStatus 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 :builds, through: :commits, dependent: :destroy
has_many :runner_projects, dependent: :destroy has_many :runner_projects, dependent: :destroy
has_many :runners, through: :runner_projects has_many :runners, through: :runner_projects
Loading
Loading
Loading
@@ -61,6 +61,24 @@ describe Project do
Loading
@@ -61,6 +61,24 @@ describe Project do
end end
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 context :valid_project do
let(:project) { FactoryGirl.create :project } let(:project) { FactoryGirl.create :project }
   
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment