From 02e440f4e710080da784246e886aa51b93c2362e Mon Sep 17 00:00:00 2001 From: Kevin Fischer Date: Sat, 22 Aug 2020 15:11:28 +0900 Subject: [PATCH 1/6] Add failing test for Project order --- test/unit/time_report_test.rb | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/unit/time_report_test.rb diff --git a/test/unit/time_report_test.rb b/test/unit/time_report_test.rb new file mode 100644 index 0000000000..e10f512317 --- /dev/null +++ b/test/unit/time_report_test.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +# Redmine - project management software +# Copyright (C) 2006-2020 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +require File.expand_path('../../test_helper', __FILE__) + +class TimeReportTest < ActiveSupport::TestCase + fixtures :trackers, :users + + def setup + User.current = nil + end + + def report_by(criteria) + project = nil + issue = nil # Unused argument. TODO: Remove + Redmine::Helpers::TimeReport.new(project, issue, criteria, 'month', TimeEntry.all) + end + + def test_project_sorted_by_name + project_b = Project.generate!(name: 'Project B') + project_a = Project.generate!(name: 'Project A') + TimeEntry.generate!(project: project_b) + TimeEntry.generate!(project: project_a) + report = report_by(['project']) + + result_projects = report.hours.map { |row| row['project'] } + + assert_equal result_projects, [project_a.id, project_b.id] + end +end From 94e95992a10c460461839e246bb740c541de24d1 Mon Sep 17 00:00:00 2001 From: Kevin Fischer Date: Sat, 22 Aug 2020 15:22:47 +0900 Subject: [PATCH 2/6] Fix order for Project --- lib/redmine/helpers/time_report.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/redmine/helpers/time_report.rb b/lib/redmine/helpers/time_report.rb index 2ae5fd8eb4..c935e82e3e 100644 --- a/lib/redmine/helpers/time_report.rb +++ b/lib/redmine/helpers/time_report.rb @@ -50,6 +50,7 @@ def run reorder(nil). group(@criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns). joins(@criteria.collect{|criteria| @available_criteria[criteria][:joins]}.compact). + order(@criteria.collect{|criteria| @available_criteria[criteria][:order]}.compact). sum(:hours).each do |hash, hours| h = {'hours' => hours} (@criteria + time_columns).each_with_index do |name, i| @@ -106,7 +107,10 @@ def load_available_criteria @available_criteria = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id", :klass => Project, - :label => :label_project}, + :label => :label_project, + :joins => :project, + :order => "#{Project.table_name}.name" + }, 'status' => {:sql => "#{Issue.table_name}.status_id", :klass => IssueStatus, :label => :field_status}, From 680ec36b098b03cacb660769750127c3922fa525 Mon Sep 17 00:00:00 2001 From: Kevin Fischer Date: Sat, 22 Aug 2020 16:31:10 +0900 Subject: [PATCH 3/6] Add query scope --- test/unit/time_report_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unit/time_report_test.rb b/test/unit/time_report_test.rb index e10f512317..24d9b1de91 100644 --- a/test/unit/time_report_test.rb +++ b/test/unit/time_report_test.rb @@ -29,7 +29,8 @@ def setup def report_by(criteria) project = nil issue = nil # Unused argument. TODO: Remove - Redmine::Helpers::TimeReport.new(project, issue, criteria, 'month', TimeEntry.all) + query = TimeEntryQuery.new + Redmine::Helpers::TimeReport.new(project, issue, criteria, 'month', query.results_scope) end def test_project_sorted_by_name From 258f5250904e84a54c2c5fb399dbd25bf8db3321 Mon Sep 17 00:00:00 2001 From: Kevin Fischer Date: Sat, 22 Aug 2020 16:31:41 +0900 Subject: [PATCH 4/6] Add test for status order --- test/unit/time_report_test.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/unit/time_report_test.rb b/test/unit/time_report_test.rb index 24d9b1de91..059581dd19 100644 --- a/test/unit/time_report_test.rb +++ b/test/unit/time_report_test.rb @@ -44,4 +44,23 @@ def test_project_sorted_by_name assert_equal result_projects, [project_a.id, project_b.id] end + + # TODO: This test is passing. Why??? + # def test_status_sorted_by_position + # status_b = IssueStatus.generate!(position: 2) + # status_a = IssueStatus.generate!(position: 1) + + # issue_b = Issue.generate! + # issue_b.update(status: status_b) + # issue_a = Issue.generate! + # issue_a.update(status: status_a) + + # TimeEntry.generate!(issue: issue_a) + # TimeEntry.generate!(issue: issue_b) + # report = report_by(['status']) + + # result_statuses = report.hours.map { |row| row['status'] } + + # assert_equal [status_a.id, status_b.id], result_statuses + # end end From 983b3e4dd1eac56a5382493a3cddb9332bb4af86 Mon Sep 17 00:00:00 2001 From: Kevin Fischer Date: Sat, 5 Sep 2020 10:43:42 +0900 Subject: [PATCH 5/6] Put expected values to the front --- test/unit/time_report_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/time_report_test.rb b/test/unit/time_report_test.rb index 059581dd19..f05a12f514 100644 --- a/test/unit/time_report_test.rb +++ b/test/unit/time_report_test.rb @@ -42,7 +42,7 @@ def test_project_sorted_by_name result_projects = report.hours.map { |row| row['project'] } - assert_equal result_projects, [project_a.id, project_b.id] + assert_equal [project_a.id, project_b.id], result_projects end # TODO: This test is passing. Why??? From fc91d7ccaf410bedc660945498180325573bd62f Mon Sep 17 00:00:00 2001 From: Kevin Fischer Date: Sat, 5 Sep 2020 10:43:52 +0900 Subject: [PATCH 6/6] Reset TimeEntries before test --- test/unit/time_report_test.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/time_report_test.rb b/test/unit/time_report_test.rb index f05a12f514..396ec4a0b7 100644 --- a/test/unit/time_report_test.rb +++ b/test/unit/time_report_test.rb @@ -24,6 +24,7 @@ class TimeReportTest < ActiveSupport::TestCase def setup User.current = nil + TimeEntry.destroy_all end def report_by(criteria)