Project

General

Profile

Defect #33952 » fixed-33952.patch

Yuichi HARADA, 2020-09-03 04:52

View differences:

app/models/time_entry_query.rb
25 25
    QueryColumn.new(:project, :sortable => "#{Project.table_name}.name", :groupable => true),
26 26
    QueryColumn.new(:spent_on, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :default_order => 'desc', :groupable => true),
27 27
    TimestampQueryColumn.new(:created_on, :sortable => "#{TimeEntry.table_name}.created_on", :default_order => 'desc', :groupable => true),
28
    QueryColumn.new(:tweek, :sortable => ["#{TimeEntry.table_name}.spent_on", "#{TimeEntry.table_name}.created_on"], :caption => :label_week),
28
    QueryColumn.new(:tweek, :sortable => ["#{TimeEntry.table_name}.tyear", "#{TimeEntry.table_name}.tweek"], :caption => :label_week),
29 29
    QueryColumn.new(:author, :sortable => lambda {User.fields_for_order_statement}),
30 30
    QueryColumn.new(:user, :sortable => lambda {User.fields_for_order_statement}, :groupable => true),
31 31
    QueryColumn.new(:activity, :sortable => "#{TimeEntryActivity.table_name}.position", :groupable => true),
test/functional/timelog_controller_test.rb
1128 1128
    assert_equal [t3, t1, t2].map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
1129 1129
  end
1130 1130

  
1131
  def test_index_should_sort_by_tweek_and_spent_on
1132
    t1 = TimeEntry.generate!(:spent_on => '2012-06-10') # tyear:2012, tweek:23
1133
    t2 = TimeEntry.generate!(:spent_on => '2012-06-11') # tyear:2012, tweek:24
1134
    t3 = TimeEntry.generate!(:spent_on => '2012-06-12') # tyear:2012, tweek:24
1135
    t4 = TimeEntry.generate!(:spent_on => '2013-06-12') # tyear:2013, tweek:24
1136

  
1137
    params = {
1138
      :project_id => 1,
1139
      :f => ['spent_on'],
1140
      :op => {'spent_on' => '><'},
1141
      :v => {'spent_on' => ['2012-06-10', '2013-06-12']}
1142
    }
1143

  
1144
    [
1145
      [{:sort => 'tweek,spent_on'}, [t1, t2, t3, t4]],
1146
      [{:sort => 'tweek,spent_on:desc'}, [t1, t3, t2, t4]],
1147
      [{:sort => 'tweek:desc,spent_on'}, [t4, t2, t3, t1]],
1148
      [{:sort => 'tweek:desc,spent_on:desc'}, [t4, t3, t2, t1]],
1149
    ].each do |sort_criteria, expect|
1150
      get :index, :params => params.dup.merge(sort_criteria)
1151
      assert_response :success
1152
      assert_equal expect.map(&:id).map(&:to_s), css_select('input[name="ids[]"]').map {|e| e.attr('value')}
1153
    end
1154
  end
1155

  
1131 1156
  def test_index_with_activity_filter
1132 1157
    activity = TimeEntryActivity.create!(:name => 'Activity')
1133 1158
    entry = TimeEntry.generate!(:issue_id => 1, :hours => 4.5, :activity => activity)
(3-3/4)