Makes Version#<=> consistent with SQL sort.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10152 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
34cdac1669
commit
2275f46138
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue