From: Jean-Philippe Lang Date: Thu, 2 Aug 2012 16:47:53 +0000 (+0000) Subject: Makes Version#<=> consistent with SQL sort. X-Git-Tag: 2.1.0~174 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2275f46138758c2cf10511901a59c555e14a046f;p=redmine.git Makes Version#<=> consistent with SQL sort. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10152 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/models/version.rb b/app/models/version.rb index 0ea1c3c71..6a7dae6a6 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -168,7 +168,7 @@ class Version < ActiveRecord::Base if self.effective_date if version.effective_date if self.effective_date == version.effective_date - "#{self.project.name} - #{self.name}" <=> "#{version.project.name} - #{version.name}" + name == version.name ? id <=> version.id : name <=> version.name else self.effective_date <=> version.effective_date end @@ -179,7 +179,7 @@ class Version < ActiveRecord::Base if version.effective_date 1 else - "#{self.project.name} - #{self.name}" <=> "#{version.project.name} - #{version.name}" + name == version.name ? id <=> version.id : name <=> version.name end end end diff --git a/test/unit/version_test.rb b/test/unit/version_test.rb index 8199e2542..d80c3d10f 100644 --- a/test/unit/version_test.rb +++ b/test/unit/version_test.rb @@ -115,6 +115,7 @@ class VersionTest < ActiveSupport::TestCase v1 = Version.create!(:project_id => 1, :name => 'v3', :effective_date => '2012-08-02') v5 = Version.create!(:project_id => 1, :name => 'v5', :effective_date => '2012-07-02') + assert_equal [v5, v3, v1, v2, v4], [v1, v2, v3, v4, v5].sort assert_equal [v5, v3, v1, v2, v4], Version.sorted.all end