]> source.dussan.org Git - redmine.git/commitdiff
Makes Version#<=> consistent with SQL sort.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 2 Aug 2012 16:47:53 +0000 (16:47 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 2 Aug 2012 16:47:53 +0000 (16:47 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10152 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/models/version.rb
test/unit/version_test.rb

index 0ea1c3c71e9627f7f6ad952927b3a4739a91a96e..6a7dae6a6b9628ffa9c6df7e56cbe3ff1a880c18 100644 (file)
@@ -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
index 8199e2542f224071812a5e4ddd42e4435dc01fcd..d80c3d10fb45b23ea58833357683bf2ef8b2b80b 100644 (file)
@@ -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