Defect #33110 » 0001-Fix-sort-does-not-work-with-group-by-datetime-column.patch
app/models/query.rb | ||
---|---|---|
850 | 850 |
def group_by_sort_order |
851 | 851 |
if column = group_by_column |
852 | 852 |
order = (sort_criteria.order_for(column.name) || column.default_order || 'asc').try(:upcase) |
853 |
Array(column.sortable).map {|s| Arel.sql("#{s} #{order}")} |
|
853 | ||
854 |
column_sortable = column.sortable |
|
855 |
if column.is_a?(TimestampQueryColumn) |
|
856 |
column_sortable = Redmine::Database.timestamp_to_date(column.sortable, User.current.time_zone) |
|
857 |
end |
|
858 |
Array(column_sortable).map {|s| Arel.sql("#{s} #{order}")} |
|
854 | 859 |
end |
855 | 860 |
end |
856 | 861 |
test/unit/query_test.rb | ||
---|---|---|
1705 | 1705 |
assert_equal values.sort, values |
1706 | 1706 |
end |
1707 | 1707 | |
1708 |
def test_sort_with_group_by_timestamp_query_column_should_sort_after_date_value |
|
1709 |
User.current = User.find(1) |
|
1710 | ||
1711 |
# Touch Issue#10 in order to be the last updated issue |
|
1712 |
Issue.find(10).update_attribute(:updated_on, Issue.find(10).updated_on + 1) |
|
1713 | ||
1714 |
q = IssueQuery.new( |
|
1715 |
:name => '_', |
|
1716 |
:filters => { 'updated_on' => {:operator => 't', :values => ['']} }, |
|
1717 |
:group_by => 'updated_on', |
|
1718 |
:sort_criteria => [['subject', 'asc']] |
|
1719 |
) |
|
1720 | ||
1721 |
# The following 3 issues are updated today (ordered by updated_on): |
|
1722 |
# Issue#10: Issue Doing the Blocking |
|
1723 |
# Issue#9: Blocked Issue |
|
1724 |
# Issue#6: Issue of a private subproject |
|
1725 | ||
1726 |
# When we group by a timestamp query column, all the issues in the group have the same date value (today) |
|
1727 |
# and the time of the value should not be taken into consideration when sorting |
|
1728 |
# |
|
1729 |
# For the same issues after subject ascending should return the following: |
|
1730 |
# Issue#9: Blocked Issue |
|
1731 |
# Issue#10: Issue Doing the Blocking |
|
1732 |
# Issue#6: Issue of a private subproject |
|
1733 |
assert_equal [9, 10, 6], q.issues.map(&:id) |
|
1734 |
end |
|
1735 | ||
1708 | 1736 |
def test_sort_by_total_for_estimated_hours |
1709 | 1737 |
# Prepare issues |
1710 | 1738 |
parent = issues(:issues_001) |