##// END OF EJS Templates
Sort issues by scheduled versions first then unscheduled versions....
Jean-Philippe Lang -
r9968:34cdac166949
parent child
Show More
@@ -186,9 +186,11 class Version < ActiveRecord::Base
186
186
187 def self.fields_for_order_statement(table=nil)
187 def self.fields_for_order_statement(table=nil)
188 table ||= table_name
188 table ||= table_name
189 %w(effective_date name).map {|field| "#{table}.#{field}"}
189 ["(CASE WHEN #{table}.effective_date IS NULL THEN 1 ELSE 0 END)", "#{table}.effective_date", "#{table}.name", "#{table}.id"]
190 end
190 end
191
191
192 scope :sorted, order(fields_for_order_statement)
193
192 # Returns the sharings that +user+ can set the version to
194 # Returns the sharings that +user+ can set the version to
193 def allowed_sharings(user = User.current)
195 def allowed_sharings(user = User.current)
194 VERSION_SHARINGS.select do |s|
196 VERSION_SHARINGS.select do |s|
@@ -107,6 +107,17 class VersionTest < ActiveSupport::TestCase
107 assert_progress_equal 25.0/100.0*100, v.closed_pourcent
107 assert_progress_equal 25.0/100.0*100, v.closed_pourcent
108 end
108 end
109
109
110 def test_should_sort_scheduled_then_unscheduled_versions
111 Version.delete_all
112 v4 = Version.create!(:project_id => 1, :name => 'v4')
113 v3 = Version.create!(:project_id => 1, :name => 'v2', :effective_date => '2012-07-14')
114 v2 = Version.create!(:project_id => 1, :name => 'v1')
115 v1 = Version.create!(:project_id => 1, :name => 'v3', :effective_date => '2012-08-02')
116 v5 = Version.create!(:project_id => 1, :name => 'v5', :effective_date => '2012-07-02')
117
118 assert_equal [v5, v3, v1, v2, v4], Version.sorted.all
119 end
120
110 context "#behind_schedule?" do
121 context "#behind_schedule?" do
111 setup do
122 setup do
112 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
123 ProjectCustomField.destroy_all # Custom values are a mess to isolate in tests
General Comments 0
You need to be logged in to leave comments. Login now