]> source.dussan.org Git - redmine.git/commitdiff
Sort issues by scheduled versions first then unscheduled versions.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 2 Aug 2012 16:47:06 +0000 (16:47 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 2 Aug 2012 16:47:06 +0000 (16:47 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@10151 e93f8b46-1217-0410-a6f0-8f06a7374b81

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

index bb0e7ec4248fb2e8d095b1665e83ad64096cfe6d..0ea1c3c71e9627f7f6ad952927b3a4739a91a96e 100644 (file)
@@ -186,9 +186,11 @@ class Version < ActiveRecord::Base
 
   def self.fields_for_order_statement(table=nil)
     table ||= table_name
-    %w(effective_date name).map {|field| "#{table}.#{field}"}
+    ["(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)", "#{table}.effective_date", "#{table}.name", "#{table}.id"]
   end
 
+  scope :sorted, order(fields_for_order_statement)
+
   # Returns the sharings that +user+ can set the version to
   def allowed_sharings(user = User.current)
     VERSION_SHARINGS.select do |s|
index 588a699d9f1d18e9a250ebce0e4e5344fc764b7e..8199e2542f224071812a5e4ddd42e4435dc01fcd 100644 (file)
@@ -107,6 +107,17 @@ class VersionTest < ActiveSupport::TestCase
     assert_progress_equal 25.0/100.0*100, v.closed_pourcent
   end
 
+  def test_should_sort_scheduled_then_unscheduled_versions
+    Version.delete_all
+    v4 = Version.create!(:project_id => 1, :name => 'v4')
+    v3 = Version.create!(:project_id => 1, :name => 'v2', :effective_date => '2012-07-14')
+    v2 = Version.create!(:project_id => 1, :name => 'v1')
+    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], Version.sorted.all
+  end
+
   context "#behind_schedule?" do
     setup do
       ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests