fix-29581-v3.patch

Mizuki ISHIKAWA, 2019-06-19 02:17

Download (3.67 KB)

View differences:

app/models/issue_query.rb
297 297
  # Valid options are :order, :offset, :limit, :include, :conditions
298 298
  def issues(options={})
299 299
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
300
    # The default order of IssueQuery is issues.id DESC(by IssueQuery#default_sort_criteria)
301
    unless ["#{Issue.table_name}.id ASC", "#{Issue.table_name}.id DESC"].any?{|i| order_option.include?(i)}
302
      order_option << "#{Issue.table_name}.id DESC"
303
    end
300 304

  
301 305
    scope = Issue.visible.
302 306
      joins(:status, :project).
......
339 343
  # Returns the issues ids
340 344
  def issue_ids(options={})
341 345
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
346
    # The default order of IssueQuery is issues.id DESC(by IssueQuery#default_sort_criteria)
347
    unless ["#{Issue.table_name}.id ASC", "#{Issue.table_name}.id DESC"].any?{|i| order_option.include?(i)}
348
      order_option << "#{Issue.table_name}.id DESC"
349
    end
342 350

  
343 351
    Issue.visible.
344 352
      joins(:status, :project).
app/models/time_entry_query.rb
148 148
  def results_scope(options={})
149 149
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
150 150

  
151
    order_option << "#{TimeEntry.table_name}.id ASC"
151 152
    base_scope.
152 153
      order(order_option).
153 154
      joins(joins_for_order_statement(order_option.join(',')))
test/unit/query_test.rb
2329 2329
    query.filters = {'spent_time' => {:operator => '><', :values => ['1', '2']}}
2330 2330
    assert_equal [3], query.issues.pluck(:id)
2331 2331
  end
2332

  
2333
  def test_issues_should_be_in_the_same_order_when_paginating
2334
    q = IssueQuery.new
2335
    q.sort_criteria = {'0' => ['priority', 'desc']}
2336
    issue_ids = q.issues.pluck(:id)
2337
    paginated_issue_ids = []
2338
    # Test with a maximum of 2 records per page.
2339
    ((q.issue_count / 2) + 1).times do |i|
2340
      paginated_issue_ids += q.issues(:offset => (i * 2), :limit => 2).pluck(:id)
2341
    end
2342

  
2343
    # Non-paginated issue ids and paginated issue ids should be in the same order.
2344
    assert_equal issue_ids, paginated_issue_ids
2345
  end
2332 2346
end
test/unit/time_entry_query_test.rb
129 129
    query = TimeEntryQuery.new(:project => Project.find(2), :name => '_')
130 130
    assert !query.available_filters.has_key?('project.status')
131 131
  end
132

  
133
  def test_results_scope_should_be_in_the_same_order_when_paginating
134
    4.times { TimeEntry.generate! }
135
    q = TimeEntryQuery.new
136
    q.sort_criteria = {'0' => ['user', 'asc']}
137
    time_entry_ids = q.results_scope.pluck(:id)
138
    paginated_time_entry_ids = []
139
    # Test with a maximum of 2 records per page.
140
    ((q.results_scope.count / 2) + 1).times do |i|
141
      paginated_time_entry_ids += q.results_scope.offset((i * 2)).limit(2).pluck(:id)
142
    end
143

  
144
    # Non-paginated time entry ids and paginated time entry ids should be in the same order.
145
    assert_equal time_entry_ids, paginated_time_entry_ids
146
  end
132 147
end