fix-29581.patch

Mizuki ISHIKAWA, 2018-09-20 10:21

Download (3.36 KB)

View differences:

app/models/issue_query.rb
273 273
  # Valid options are :order, :offset, :limit, :include, :conditions
274 274
  def issues(options={})
275 275
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
276
    order_option += ['issues.id ASC']  unless order_option.include?("issues.id DESC") || order_option.include?("issues.id ASC")
276 277

  
277 278
    scope = Issue.visible.
278 279
      joins(:status, :project).
......
315 316
  # Returns the issues ids
316 317
  def issue_ids(options={})
317 318
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
319
    order_option += ['issues.id ASC']  unless order_option.include?("issues.id DESC") || order_option.include?("issues.id ASC")
318 320

  
319 321
    Issue.visible.
320 322
      joins(:status, :project).
app/models/time_entry_query.rb
136 136
  def results_scope(options={})
137 137
    order_option = [group_by_sort_order, (options[:order] || sort_clause)].flatten.reject(&:blank?)
138 138

  
139
    order_option += ['time_entries.id ASC']
139 140
    base_scope.
140 141
      order(order_option).
141 142
      joins(joins_for_order_statement(order_option.join(',')))
test/unit/query_test.rb
2184 2184

  
2185 2185
    assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second)
2186 2186
  end
2187

  
2188
  def test_issues_should_be_in_the_same_order_when_paginating
2189
    q = IssueQuery.new
2190
    q.sort_criteria = {'0' => ['priority', 'desc']}
2191
    issue_ids = q.issues.pluck(:id)
2192
    paginated_issue_ids = []
2193
    # Test with a maximum of 2 records per page.
2194
    ((q.issue_count / 2) + 1).times do |i|
2195
      paginated_issue_ids += q.issues(:offset => (i * 2), :limit => 2).pluck(:id)
2196
    end
2197

  
2198
    # Non-paginated issue ids and paginated issue ids should be in the same order.
2199
    assert_equal issue_ids, paginated_issue_ids
2200
  end
2187 2201
end
test/unit/time_entry_query_test.rb
107 107
    query = TimeEntryQuery.new(:project => nil, :name => '_')
108 108
    assert !query.available_filters.has_key?('issue.category_id')
109 109
  end
110

  
111
  def test_results_scope_should_be_in_the_same_order_when_paginating
112
    4.times { TimeEntry.generate! }
113
    q = TimeEntryQuery.new
114
    q.sort_criteria = {'0' => ['user', 'asc']}
115
    time_entry_ids = q.results_scope.pluck(:id)
116
    paginated_time_entry_ids = []
117
    # Test with a maximum of 2 records per page.
118
    ((q.results_scope.count / 2) + 1).times do |i|
119
      paginated_time_entry_ids += q.results_scope.offset((i * 2)).limit(2).pluck(:id)
120
    end
121

  
122
    # Non-paginated time entry ids and paginated time entry ids should be in the same order.
123
    assert_equal time_entry_ids, paginated_time_entry_ids
124
  end
110 125
end