From 1871378648e1a35aa3afa8b80335215a22a956ec Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 9 Nov 2013 08:54:45 +0000 Subject: [PATCH] Gantt: sort versions like on the roadmap (#7335). git-svn-id: http://svn.redmine.org/redmine/trunk@12247 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/helpers/gantt.rb | 6 +----- test/unit/lib/redmine/helpers/gantt_test.rb | 23 ++++----------------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb index 198de20a0..e9e77ff91 100644 --- a/lib/redmine/helpers/gantt.rb +++ b/lib/redmine/helpers/gantt.rb @@ -693,11 +693,7 @@ module Redmine end def self.sort_versions!(versions) - versions.sort! {|a, b| sort_version_logic(a) <=> sort_version_logic(b)} - end - - def self.sort_version_logic(version) - [(version.start_date || Date.new()), version.id] + versions.sort! end def current_limit diff --git a/test/unit/lib/redmine/helpers/gantt_test.rb b/test/unit/lib/redmine/helpers/gantt_test.rb index 1c46c6098..2354b1b5e 100644 --- a/test/unit/lib/redmine/helpers/gantt_test.rb +++ b/test/unit/lib/redmine/helpers/gantt_test.rb @@ -832,25 +832,10 @@ class Redmine::Helpers::GanttHelperTest < ActionView::TestCase def test_sort_versions project = Project.generate! version1 = Version.create!(:project => project, :name => 'test1') - version2 = Version.create!(:project => project, :name => 'test2') + version2 = Version.create!(:project => project, :name => 'test2', :effective_date => '2013-10-25') version3 = Version.create!(:project => project, :name => 'test3') - version4 = Version.create!(:project => project, :name => 'test4') - issue1 = Issue.generate!(:subject => "test", :project => project, - :fixed_version => version1) - issue2 = Issue.generate!(:subject => "test", :project => project, - :fixed_version => version2) - issue3 = Issue.generate!(:subject => "test", :project => project, - :fixed_version => version3, :start_date => (today - 1)) - issue4 = Issue.generate!(:subject => "test", :project => project, - :fixed_version => version4, :start_date => (today - 2)) - assert_nil version1.start_date - assert_nil version2.start_date - assert version1.id < version2.id - assert_equal today - 1, version3.start_date - assert_equal today - 2, version4.start_date - versions = [version4, version3, version2, version1] - Redmine::Helpers::Gantt.sort_versions!(versions) - assert_equal [version1.id, version2.id, version4.id, version3.id], - versions.map{|v| v.id} + version4 = Version.create!(:project => project, :name => 'test4', :effective_date => '2013-10-02') + + assert_equal versions.sort, Redmine::Helpers::Gantt.sort_versions!(versions) end end -- 2.39.5