@@ -1,152 +1,152 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2014 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | module Redmine |
|
18 | module Redmine | |
19 | module Helpers |
|
19 | module Helpers | |
20 | class TimeReport |
|
20 | class TimeReport | |
21 | attr_reader :criteria, :columns, :hours, :total_hours, :periods |
|
21 | attr_reader :criteria, :columns, :hours, :total_hours, :periods | |
22 |
|
22 | |||
23 | def initialize(project, issue, criteria, columns, time_entry_scope) |
|
23 | def initialize(project, issue, criteria, columns, time_entry_scope) | |
24 | @project = project |
|
24 | @project = project | |
25 | @issue = issue |
|
25 | @issue = issue | |
26 |
|
26 | |||
27 | @criteria = criteria || [] |
|
27 | @criteria = criteria || [] | |
28 | @criteria = @criteria.select{|criteria| available_criteria.has_key? criteria} |
|
28 | @criteria = @criteria.select{|criteria| available_criteria.has_key? criteria} | |
29 | @criteria.uniq! |
|
29 | @criteria.uniq! | |
30 | @criteria = @criteria[0,3] |
|
30 | @criteria = @criteria[0,3] | |
31 |
|
31 | |||
32 | @columns = (columns && %w(year month week day).include?(columns)) ? columns : 'month' |
|
32 | @columns = (columns && %w(year month week day).include?(columns)) ? columns : 'month' | |
33 | @scope = time_entry_scope |
|
33 | @scope = time_entry_scope | |
34 |
|
34 | |||
35 | run |
|
35 | run | |
36 | end |
|
36 | end | |
37 |
|
37 | |||
38 | def available_criteria |
|
38 | def available_criteria | |
39 | @available_criteria || load_available_criteria |
|
39 | @available_criteria || load_available_criteria | |
40 | end |
|
40 | end | |
41 |
|
41 | |||
42 | private |
|
42 | private | |
43 |
|
43 | |||
44 | def run |
|
44 | def run | |
45 | unless @criteria.empty? |
|
45 | unless @criteria.empty? | |
46 | time_columns = %w(tyear tmonth tweek spent_on) |
|
46 | time_columns = %w(tyear tmonth tweek spent_on) | |
47 | @hours = [] |
|
47 | @hours = [] | |
48 | @scope.includes(:issue, :activity). |
|
48 | @scope.includes(:issue, :activity). | |
49 | group(@criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns). |
|
49 | group(@criteria.collect{|criteria| @available_criteria[criteria][:sql]} + time_columns). | |
50 | joins(@criteria.collect{|criteria| @available_criteria[criteria][:joins]}.compact). |
|
50 | joins(@criteria.collect{|criteria| @available_criteria[criteria][:joins]}.compact). | |
51 | sum(:hours).each do |hash, hours| |
|
51 | sum(:hours).each do |hash, hours| | |
52 | h = {'hours' => hours} |
|
52 | h = {'hours' => hours} | |
53 | (@criteria + time_columns).each_with_index do |name, i| |
|
53 | (@criteria + time_columns).each_with_index do |name, i| | |
54 | h[name] = hash[i] |
|
54 | h[name] = hash[i] | |
55 | end |
|
55 | end | |
56 | @hours << h |
|
56 | @hours << h | |
57 | end |
|
57 | end | |
58 |
|
58 | |||
59 | @hours.each do |row| |
|
59 | @hours.each do |row| | |
60 | case @columns |
|
60 | case @columns | |
61 | when 'year' |
|
61 | when 'year' | |
62 | row['year'] = row['tyear'] |
|
62 | row['year'] = row['tyear'] | |
63 | when 'month' |
|
63 | when 'month' | |
64 | row['month'] = "#{row['tyear']}-#{row['tmonth']}" |
|
64 | row['month'] = "#{row['tyear']}-#{row['tmonth']}" | |
65 | when 'week' |
|
65 | when 'week' | |
66 | row['week'] = "#{row['spent_on'].cwyear}-#{row['tweek']}" |
|
66 | row['week'] = "#{row['spent_on'].cwyear}-#{row['tweek']}" | |
67 | when 'day' |
|
67 | when 'day' | |
68 | row['day'] = "#{row['spent_on']}" |
|
68 | row['day'] = "#{row['spent_on']}" | |
69 | end |
|
69 | end | |
70 | end |
|
70 | end | |
71 |
|
71 | |||
72 | min = @hours.collect {|row| row['spent_on']}.min |
|
72 | min = @hours.collect {|row| row['spent_on']}.min | |
73 | @from = min ? min.to_date : Date.today |
|
73 | @from = min ? min.to_date : Date.today | |
74 |
|
74 | |||
75 | max = @hours.collect {|row| row['spent_on']}.max |
|
75 | max = @hours.collect {|row| row['spent_on']}.max | |
76 | @to = max ? max.to_date : Date.today |
|
76 | @to = max ? max.to_date : Date.today | |
77 |
|
77 | |||
78 | @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} |
|
78 | @total_hours = @hours.inject(0) {|s,k| s = s + k['hours'].to_f} | |
79 |
|
79 | |||
80 | @periods = [] |
|
80 | @periods = [] | |
81 | # Date#at_beginning_of_ not supported in Rails 1.2.x |
|
81 | # Date#at_beginning_of_ not supported in Rails 1.2.x | |
82 | date_from = @from.to_time |
|
82 | date_from = @from.to_time | |
83 | # 100 columns max |
|
83 | # 100 columns max | |
84 | while date_from <= @to.to_time && @periods.length < 100 |
|
84 | while date_from <= @to.to_time && @periods.length < 100 | |
85 | case @columns |
|
85 | case @columns | |
86 | when 'year' |
|
86 | when 'year' | |
87 | @periods << "#{date_from.year}" |
|
87 | @periods << "#{date_from.year}" | |
88 | date_from = (date_from + 1.year).at_beginning_of_year |
|
88 | date_from = (date_from + 1.year).at_beginning_of_year | |
89 | when 'month' |
|
89 | when 'month' | |
90 | @periods << "#{date_from.year}-#{date_from.month}" |
|
90 | @periods << "#{date_from.year}-#{date_from.month}" | |
91 | date_from = (date_from + 1.month).at_beginning_of_month |
|
91 | date_from = (date_from + 1.month).at_beginning_of_month | |
92 | when 'week' |
|
92 | when 'week' | |
93 | @periods << "#{date_from.to_date.cwyear}-#{date_from.to_date.cweek}" |
|
93 | @periods << "#{date_from.to_date.cwyear}-#{date_from.to_date.cweek}" | |
94 | date_from = (date_from + 7.day).at_beginning_of_week |
|
94 | date_from = (date_from + 7.day).at_beginning_of_week | |
95 | when 'day' |
|
95 | when 'day' | |
96 | @periods << "#{date_from.to_date}" |
|
96 | @periods << "#{date_from.to_date}" | |
97 | date_from = date_from + 1.day |
|
97 | date_from = date_from + 1.day | |
98 | end |
|
98 | end | |
99 | end |
|
99 | end | |
100 | end |
|
100 | end | |
101 | end |
|
101 | end | |
102 |
|
102 | |||
103 | def load_available_criteria |
|
103 | def load_available_criteria | |
104 | @available_criteria = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id", |
|
104 | @available_criteria = { 'project' => {:sql => "#{TimeEntry.table_name}.project_id", | |
105 | :klass => Project, |
|
105 | :klass => Project, | |
106 | :label => :label_project}, |
|
106 | :label => :label_project}, | |
107 | 'status' => {:sql => "#{Issue.table_name}.status_id", |
|
107 | 'status' => {:sql => "#{Issue.table_name}.status_id", | |
108 | :klass => IssueStatus, |
|
108 | :klass => IssueStatus, | |
109 | :label => :field_status}, |
|
109 | :label => :field_status}, | |
110 | 'version' => {:sql => "#{Issue.table_name}.fixed_version_id", |
|
110 | 'version' => {:sql => "#{Issue.table_name}.fixed_version_id", | |
111 | :klass => Version, |
|
111 | :klass => Version, | |
112 | :label => :label_version}, |
|
112 | :label => :label_version}, | |
113 | 'category' => {:sql => "#{Issue.table_name}.category_id", |
|
113 | 'category' => {:sql => "#{Issue.table_name}.category_id", | |
114 | :klass => IssueCategory, |
|
114 | :klass => IssueCategory, | |
115 | :label => :field_category}, |
|
115 | :label => :field_category}, | |
116 | 'user' => {:sql => "#{TimeEntry.table_name}.user_id", |
|
116 | 'user' => {:sql => "#{TimeEntry.table_name}.user_id", | |
117 | :klass => User, |
|
117 | :klass => User, | |
118 | :label => :label_user}, |
|
118 | :label => :label_user}, | |
119 | 'tracker' => {:sql => "#{Issue.table_name}.tracker_id", |
|
119 | 'tracker' => {:sql => "#{Issue.table_name}.tracker_id", | |
120 | :klass => Tracker, |
|
120 | :klass => Tracker, | |
121 | :label => :label_tracker}, |
|
121 | :label => :label_tracker}, | |
122 | 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id", |
|
122 | 'activity' => {:sql => "#{TimeEntry.table_name}.activity_id", | |
123 | :klass => TimeEntryActivity, |
|
123 | :klass => TimeEntryActivity, | |
124 | :label => :label_activity}, |
|
124 | :label => :label_activity}, | |
125 | 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id", |
|
125 | 'issue' => {:sql => "#{TimeEntry.table_name}.issue_id", | |
126 | :klass => Issue, |
|
126 | :klass => Issue, | |
127 | :label => :label_issue} |
|
127 | :label => :label_issue} | |
128 | } |
|
128 | } | |
129 |
|
129 | |||
130 | # Add time entry custom fields |
|
130 | # Add time entry custom fields | |
131 | custom_fields = TimeEntryCustomField.all |
|
131 | custom_fields = TimeEntryCustomField.all | |
132 | # Add project custom fields |
|
132 | # Add project custom fields | |
133 | custom_fields += ProjectCustomField.all |
|
133 | custom_fields += ProjectCustomField.all | |
134 | # Add issue custom fields |
|
134 | # Add issue custom fields | |
135 | custom_fields += (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields) |
|
135 | custom_fields += (@project.nil? ? IssueCustomField.for_all : @project.all_issue_custom_fields) | |
136 | # Add time entry activity custom fields |
|
136 | # Add time entry activity custom fields | |
137 | custom_fields += TimeEntryActivityCustomField.all |
|
137 | custom_fields += TimeEntryActivityCustomField.all | |
138 |
|
138 | |||
139 | # Add list and boolean custom fields as available criteria |
|
139 | # Add list and boolean custom fields as available criteria | |
140 |
custom_fields.select {|cf| %w(list bool).include? |
|
140 | custom_fields.select {|cf| %w(list bool).include?(cf.field_format) && !cf.multiple?}.each do |cf| | |
141 | @available_criteria["cf_#{cf.id}"] = {:sql => cf.group_statement, |
|
141 | @available_criteria["cf_#{cf.id}"] = {:sql => cf.group_statement, | |
142 | :joins => cf.join_for_order_statement, |
|
142 | :joins => cf.join_for_order_statement, | |
143 | :format => cf.field_format, |
|
143 | :format => cf.field_format, | |
144 | :custom_field => cf, |
|
144 | :custom_field => cf, | |
145 | :label => cf.name} |
|
145 | :label => cf.name} | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | @available_criteria |
|
148 | @available_criteria | |
149 | end |
|
149 | end | |
150 | end |
|
150 | end | |
151 | end |
|
151 | end | |
152 | end |
|
152 | end |
@@ -1,374 +1,386 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | # Redmine - project management software |
|
2 | # Redmine - project management software | |
3 | # Copyright (C) 2006-2014 Jean-Philippe Lang |
|
3 | # Copyright (C) 2006-2014 Jean-Philippe Lang | |
4 | # |
|
4 | # | |
5 | # This program is free software; you can redistribute it and/or |
|
5 | # This program is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU General Public License |
|
6 | # modify it under the terms of the GNU General Public License | |
7 | # as published by the Free Software Foundation; either version 2 |
|
7 | # as published by the Free Software Foundation; either version 2 | |
8 | # of the License, or (at your option) any later version. |
|
8 | # of the License, or (at your option) any later version. | |
9 | # |
|
9 | # | |
10 | # This program is distributed in the hope that it will be useful, |
|
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. |
|
13 | # GNU General Public License for more details. | |
14 | # |
|
14 | # | |
15 | # You should have received a copy of the GNU General Public License |
|
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software |
|
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
18 |
|
18 | |||
19 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | require File.expand_path('../../test_helper', __FILE__) | |
20 |
|
20 | |||
21 | class TimeEntryReportsControllerTest < ActionController::TestCase |
|
21 | class TimeEntryReportsControllerTest < ActionController::TestCase | |
22 | tests TimelogController |
|
22 | tests TimelogController | |
23 |
|
23 | |||
24 | fixtures :projects, :enabled_modules, :roles, :members, :member_roles, |
|
24 | fixtures :projects, :enabled_modules, :roles, :members, :member_roles, | |
25 | :issues, :time_entries, :users, :trackers, :enumerations, |
|
25 | :issues, :time_entries, :users, :trackers, :enumerations, | |
26 | :issue_statuses, :custom_fields, :custom_values, |
|
26 | :issue_statuses, :custom_fields, :custom_values, | |
27 | :projects_trackers, :custom_fields_trackers, |
|
27 | :projects_trackers, :custom_fields_trackers, | |
28 | :custom_fields_projects |
|
28 | :custom_fields_projects | |
29 |
|
29 | |||
30 | include Redmine::I18n |
|
30 | include Redmine::I18n | |
31 |
|
31 | |||
32 | def setup |
|
32 | def setup | |
33 | Setting.default_language = "en" |
|
33 | Setting.default_language = "en" | |
34 | end |
|
34 | end | |
35 |
|
35 | |||
36 | def test_report_at_project_level |
|
36 | def test_report_at_project_level | |
37 | get :report, :project_id => 'ecookbook' |
|
37 | get :report, :project_id => 'ecookbook' | |
38 | assert_response :success |
|
38 | assert_response :success | |
39 | assert_template 'report' |
|
39 | assert_template 'report' | |
40 | assert_tag :form, |
|
40 | assert_tag :form, | |
41 | :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'} |
|
41 | :attributes => {:action => "/projects/ecookbook/time_entries/report", :id => 'query_form'} | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_report_all_projects |
|
44 | def test_report_all_projects | |
45 | get :report |
|
45 | get :report | |
46 | assert_response :success |
|
46 | assert_response :success | |
47 | assert_template 'report' |
|
47 | assert_template 'report' | |
48 | assert_tag :form, |
|
48 | assert_tag :form, | |
49 | :attributes => {:action => "/time_entries/report", :id => 'query_form'} |
|
49 | :attributes => {:action => "/time_entries/report", :id => 'query_form'} | |
50 | end |
|
50 | end | |
51 |
|
51 | |||
52 | def test_report_all_projects_denied |
|
52 | def test_report_all_projects_denied | |
53 | r = Role.anonymous |
|
53 | r = Role.anonymous | |
54 | r.permissions.delete(:view_time_entries) |
|
54 | r.permissions.delete(:view_time_entries) | |
55 | r.permissions_will_change! |
|
55 | r.permissions_will_change! | |
56 | r.save |
|
56 | r.save | |
57 | get :report |
|
57 | get :report | |
58 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' |
|
58 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' | |
59 | end |
|
59 | end | |
60 |
|
60 | |||
61 | def test_report_all_projects_one_criteria |
|
61 | def test_report_all_projects_one_criteria | |
62 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] |
|
62 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] | |
63 | assert_response :success |
|
63 | assert_response :success | |
64 | assert_template 'report' |
|
64 | assert_template 'report' | |
65 | assert_not_nil assigns(:report) |
|
65 | assert_not_nil assigns(:report) | |
66 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours |
|
66 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours | |
67 | end |
|
67 | end | |
68 |
|
68 | |||
69 | def test_report_all_time |
|
69 | def test_report_all_time | |
70 | get :report, :project_id => 1, :criteria => ['project', 'issue'] |
|
70 | get :report, :project_id => 1, :criteria => ['project', 'issue'] | |
71 | assert_response :success |
|
71 | assert_response :success | |
72 | assert_template 'report' |
|
72 | assert_template 'report' | |
73 | assert_not_nil assigns(:report) |
|
73 | assert_not_nil assigns(:report) | |
74 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
74 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
75 | end |
|
75 | end | |
76 |
|
76 | |||
77 | def test_report_all_time_by_day |
|
77 | def test_report_all_time_by_day | |
78 | get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day' |
|
78 | get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day' | |
79 | assert_response :success |
|
79 | assert_response :success | |
80 | assert_template 'report' |
|
80 | assert_template 'report' | |
81 | assert_not_nil assigns(:report) |
|
81 | assert_not_nil assigns(:report) | |
82 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
82 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
83 | assert_tag :tag => 'th', :content => '2007-03-12' |
|
83 | assert_tag :tag => 'th', :content => '2007-03-12' | |
84 | end |
|
84 | end | |
85 |
|
85 | |||
86 | def test_report_one_criteria |
|
86 | def test_report_one_criteria | |
87 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] |
|
87 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] | |
88 | assert_response :success |
|
88 | assert_response :success | |
89 | assert_template 'report' |
|
89 | assert_template 'report' | |
90 | assert_not_nil assigns(:report) |
|
90 | assert_not_nil assigns(:report) | |
91 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours |
|
91 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours | |
92 | end |
|
92 | end | |
93 |
|
93 | |||
94 | def test_report_two_criteria |
|
94 | def test_report_two_criteria | |
95 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] |
|
95 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] | |
96 | assert_response :success |
|
96 | assert_response :success | |
97 | assert_template 'report' |
|
97 | assert_template 'report' | |
98 | assert_not_nil assigns(:report) |
|
98 | assert_not_nil assigns(:report) | |
99 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
99 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
100 | end |
|
100 | end | |
101 |
|
101 | |||
102 | def test_report_custom_field_criteria_with_multiple_values |
|
102 | def test_report_custom_field_criteria_with_multiple_values_on_single_value_custom_field_should_not_fail | |
103 | field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2']) |
|
103 | field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2']) | |
104 | entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today) |
|
104 | entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today) | |
105 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1') |
|
105 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1') | |
106 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2') |
|
106 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2') | |
107 |
|
107 | |||
108 | get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"] |
|
108 | get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"] | |
109 | assert_response :success |
|
109 | assert_response :success | |
110 | end |
|
110 | end | |
111 |
|
111 | |||
|
112 | def test_report_multiple_values_custom_fields_should_not_be_proposed | |||
|
113 | TimeEntryCustomField.create!(:name => 'Single', :field_format => 'list', :possible_values => ['value1', 'value2']) | |||
|
114 | TimeEntryCustomField.create!(:name => 'Multi', :field_format => 'list', :multiple => true, :possible_values => ['value1', 'value2']) | |||
|
115 | ||||
|
116 | get :report, :project_id => 1 | |||
|
117 | assert_response :success | |||
|
118 | assert_select 'select[name=?]', 'criteria[]' do | |||
|
119 | assert_select 'option', :text => 'Single' | |||
|
120 | assert_select 'option', :text => 'Multi', :count => 0 | |||
|
121 | end | |||
|
122 | end | |||
|
123 | ||||
112 | def test_report_one_day |
|
124 | def test_report_one_day | |
113 | get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["user", "activity"] |
|
125 | get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["user", "activity"] | |
114 | assert_response :success |
|
126 | assert_response :success | |
115 | assert_template 'report' |
|
127 | assert_template 'report' | |
116 | assert_not_nil assigns(:report) |
|
128 | assert_not_nil assigns(:report) | |
117 | assert_equal "4.25", "%.2f" % assigns(:report).total_hours |
|
129 | assert_equal "4.25", "%.2f" % assigns(:report).total_hours | |
118 | end |
|
130 | end | |
119 |
|
131 | |||
120 | def test_report_at_issue_level |
|
132 | def test_report_at_issue_level | |
121 | get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] |
|
133 | get :report, :project_id => 1, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] | |
122 | assert_response :success |
|
134 | assert_response :success | |
123 | assert_template 'report' |
|
135 | assert_template 'report' | |
124 | assert_not_nil assigns(:report) |
|
136 | assert_not_nil assigns(:report) | |
125 | assert_equal "154.25", "%.2f" % assigns(:report).total_hours |
|
137 | assert_equal "154.25", "%.2f" % assigns(:report).total_hours | |
126 | assert_tag :form, |
|
138 | assert_tag :form, | |
127 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} |
|
139 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries/report", :id => 'query_form'} | |
128 | end |
|
140 | end | |
129 |
|
141 | |||
130 | def test_report_by_week_should_use_commercial_year |
|
142 | def test_report_by_week_should_use_commercial_year | |
131 | TimeEntry.delete_all |
|
143 | TimeEntry.delete_all | |
132 | TimeEntry.generate!(:hours => '2', :spent_on => '2009-12-25') # 2009-52 |
|
144 | TimeEntry.generate!(:hours => '2', :spent_on => '2009-12-25') # 2009-52 | |
133 | TimeEntry.generate!(:hours => '4', :spent_on => '2009-12-31') # 2009-53 |
|
145 | TimeEntry.generate!(:hours => '4', :spent_on => '2009-12-31') # 2009-53 | |
134 | TimeEntry.generate!(:hours => '8', :spent_on => '2010-01-01') # 2009-53 |
|
146 | TimeEntry.generate!(:hours => '8', :spent_on => '2010-01-01') # 2009-53 | |
135 | TimeEntry.generate!(:hours => '16', :spent_on => '2010-01-05') # 2010-1 |
|
147 | TimeEntry.generate!(:hours => '16', :spent_on => '2010-01-05') # 2010-1 | |
136 |
|
148 | |||
137 | get :report, :columns => 'week', :from => "2009-12-25", :to => "2010-01-05", :criteria => ["project"] |
|
149 | get :report, :columns => 'week', :from => "2009-12-25", :to => "2010-01-05", :criteria => ["project"] | |
138 | assert_response :success |
|
150 | assert_response :success | |
139 |
|
151 | |||
140 | assert_select '#time-report thead tr' do |
|
152 | assert_select '#time-report thead tr' do | |
141 | assert_select 'th:nth-child(1)', :text => 'Project' |
|
153 | assert_select 'th:nth-child(1)', :text => 'Project' | |
142 | assert_select 'th:nth-child(2)', :text => '2009-52' |
|
154 | assert_select 'th:nth-child(2)', :text => '2009-52' | |
143 | assert_select 'th:nth-child(3)', :text => '2009-53' |
|
155 | assert_select 'th:nth-child(3)', :text => '2009-53' | |
144 | assert_select 'th:nth-child(4)', :text => '2010-1' |
|
156 | assert_select 'th:nth-child(4)', :text => '2010-1' | |
145 | assert_select 'th:nth-child(5)', :text => 'Total time' |
|
157 | assert_select 'th:nth-child(5)', :text => 'Total time' | |
146 | end |
|
158 | end | |
147 | assert_select '#time-report tbody tr' do |
|
159 | assert_select '#time-report tbody tr' do | |
148 | assert_select 'td:nth-child(1)', :text => 'eCookbook' |
|
160 | assert_select 'td:nth-child(1)', :text => 'eCookbook' | |
149 | assert_select 'td:nth-child(2)', :text => '2.00' |
|
161 | assert_select 'td:nth-child(2)', :text => '2.00' | |
150 | assert_select 'td:nth-child(3)', :text => '12.00' |
|
162 | assert_select 'td:nth-child(3)', :text => '12.00' | |
151 | assert_select 'td:nth-child(4)', :text => '16.00' |
|
163 | assert_select 'td:nth-child(4)', :text => '16.00' | |
152 | assert_select 'td:nth-child(5)', :text => '30.00' # Total |
|
164 | assert_select 'td:nth-child(5)', :text => '30.00' # Total | |
153 | end |
|
165 | end | |
154 | end |
|
166 | end | |
155 |
|
167 | |||
156 | def test_report_should_propose_association_custom_fields |
|
168 | def test_report_should_propose_association_custom_fields | |
157 | get :report |
|
169 | get :report | |
158 | assert_response :success |
|
170 | assert_response :success | |
159 | assert_template 'report' |
|
171 | assert_template 'report' | |
160 |
|
172 | |||
161 | assert_select 'select[name=?]', 'criteria[]' do |
|
173 | assert_select 'select[name=?]', 'criteria[]' do | |
162 | assert_select 'option[value=cf_1]', {:text => 'Database'}, 'Issue custom field not found' |
|
174 | assert_select 'option[value=cf_1]', {:text => 'Database'}, 'Issue custom field not found' | |
163 | assert_select 'option[value=cf_3]', {:text => 'Development status'}, 'Project custom field not found' |
|
175 | assert_select 'option[value=cf_3]', {:text => 'Development status'}, 'Project custom field not found' | |
164 | assert_select 'option[value=cf_7]', {:text => 'Billable'}, 'TimeEntryActivity custom field not found' |
|
176 | assert_select 'option[value=cf_7]', {:text => 'Billable'}, 'TimeEntryActivity custom field not found' | |
165 | end |
|
177 | end | |
166 | end |
|
178 | end | |
167 |
|
179 | |||
168 | def test_report_with_association_custom_fields |
|
180 | def test_report_with_association_custom_fields | |
169 | get :report, :criteria => ['cf_1', 'cf_3', 'cf_7'] |
|
181 | get :report, :criteria => ['cf_1', 'cf_3', 'cf_7'] | |
170 | assert_response :success |
|
182 | assert_response :success | |
171 | assert_template 'report' |
|
183 | assert_template 'report' | |
172 | assert_not_nil assigns(:report) |
|
184 | assert_not_nil assigns(:report) | |
173 | assert_equal 3, assigns(:report).criteria.size |
|
185 | assert_equal 3, assigns(:report).criteria.size | |
174 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
186 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
175 |
|
187 | |||
176 | # Custom fields columns |
|
188 | # Custom fields columns | |
177 | assert_select 'th', :text => 'Database' |
|
189 | assert_select 'th', :text => 'Database' | |
178 | assert_select 'th', :text => 'Development status' |
|
190 | assert_select 'th', :text => 'Development status' | |
179 | assert_select 'th', :text => 'Billable' |
|
191 | assert_select 'th', :text => 'Billable' | |
180 |
|
192 | |||
181 | # Custom field row |
|
193 | # Custom field row | |
182 | assert_select 'tr' do |
|
194 | assert_select 'tr' do | |
183 | assert_select 'td', :text => 'MySQL' |
|
195 | assert_select 'td', :text => 'MySQL' | |
184 | assert_select 'td.hours', :text => '1.00' |
|
196 | assert_select 'td.hours', :text => '1.00' | |
185 | end |
|
197 | end | |
186 | end |
|
198 | end | |
187 |
|
199 | |||
188 | def test_report_one_criteria_no_result |
|
200 | def test_report_one_criteria_no_result | |
189 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project'] |
|
201 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project'] | |
190 | assert_response :success |
|
202 | assert_response :success | |
191 | assert_template 'report' |
|
203 | assert_template 'report' | |
192 | assert_not_nil assigns(:report) |
|
204 | assert_not_nil assigns(:report) | |
193 | assert_equal "0.00", "%.2f" % assigns(:report).total_hours |
|
205 | assert_equal "0.00", "%.2f" % assigns(:report).total_hours | |
194 | end |
|
206 | end | |
195 |
|
207 | |||
196 | def test_report_status_criterion |
|
208 | def test_report_status_criterion | |
197 | get :report, :project_id => 1, :criteria => ['status'] |
|
209 | get :report, :project_id => 1, :criteria => ['status'] | |
198 | assert_response :success |
|
210 | assert_response :success | |
199 | assert_template 'report' |
|
211 | assert_template 'report' | |
200 | assert_tag :tag => 'th', :content => 'Status' |
|
212 | assert_tag :tag => 'th', :content => 'Status' | |
201 | assert_tag :tag => 'td', :content => 'New' |
|
213 | assert_tag :tag => 'td', :content => 'New' | |
202 | end |
|
214 | end | |
203 |
|
215 | |||
204 | def test_report_all_projects_csv_export |
|
216 | def test_report_all_projects_csv_export | |
205 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", |
|
217 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", | |
206 | :criteria => ["project", "user", "activity"], :format => "csv" |
|
218 | :criteria => ["project", "user", "activity"], :format => "csv" | |
207 | assert_response :success |
|
219 | assert_response :success | |
208 | assert_equal 'text/csv; header=present', @response.content_type |
|
220 | assert_equal 'text/csv; header=present', @response.content_type | |
209 | lines = @response.body.chomp.split("\n") |
|
221 | lines = @response.body.chomp.split("\n") | |
210 | # Headers |
|
222 | # Headers | |
211 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first |
|
223 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first | |
212 | # Total row |
|
224 | # Total row | |
213 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last |
|
225 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last | |
214 | end |
|
226 | end | |
215 |
|
227 | |||
216 | def test_report_csv_export |
|
228 | def test_report_csv_export | |
217 | get :report, :project_id => 1, :columns => 'month', |
|
229 | get :report, :project_id => 1, :columns => 'month', | |
218 | :from => "2007-01-01", :to => "2007-06-30", |
|
230 | :from => "2007-01-01", :to => "2007-06-30", | |
219 | :criteria => ["project", "user", "activity"], :format => "csv" |
|
231 | :criteria => ["project", "user", "activity"], :format => "csv" | |
220 | assert_response :success |
|
232 | assert_response :success | |
221 | assert_equal 'text/csv; header=present', @response.content_type |
|
233 | assert_equal 'text/csv; header=present', @response.content_type | |
222 | lines = @response.body.chomp.split("\n") |
|
234 | lines = @response.body.chomp.split("\n") | |
223 | # Headers |
|
235 | # Headers | |
224 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first |
|
236 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first | |
225 | # Total row |
|
237 | # Total row | |
226 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last |
|
238 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last | |
227 | end |
|
239 | end | |
228 |
|
240 | |||
229 | def test_csv_big_5 |
|
241 | def test_csv_big_5 | |
230 | Setting.default_language = "zh-TW" |
|
242 | Setting.default_language = "zh-TW" | |
231 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" |
|
243 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" | |
232 | str_big5 = "\xa4@\xa4\xeb" |
|
244 | str_big5 = "\xa4@\xa4\xeb" | |
233 | if str_utf8.respond_to?(:force_encoding) |
|
245 | if str_utf8.respond_to?(:force_encoding) | |
234 | str_utf8.force_encoding('UTF-8') |
|
246 | str_utf8.force_encoding('UTF-8') | |
235 | str_big5.force_encoding('Big5') |
|
247 | str_big5.force_encoding('Big5') | |
236 | end |
|
248 | end | |
237 | user = User.find_by_id(3) |
|
249 | user = User.find_by_id(3) | |
238 | user.firstname = str_utf8 |
|
250 | user.firstname = str_utf8 | |
239 | user.lastname = "test-lastname" |
|
251 | user.lastname = "test-lastname" | |
240 | assert user.save |
|
252 | assert user.save | |
241 | comments = "test_csv_big_5" |
|
253 | comments = "test_csv_big_5" | |
242 | te1 = TimeEntry.create(:spent_on => '2011-11-11', |
|
254 | te1 = TimeEntry.create(:spent_on => '2011-11-11', | |
243 | :hours => 7.3, |
|
255 | :hours => 7.3, | |
244 | :project => Project.find(1), |
|
256 | :project => Project.find(1), | |
245 | :user => user, |
|
257 | :user => user, | |
246 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
258 | :activity => TimeEntryActivity.find_by_name('Design'), | |
247 | :comments => comments) |
|
259 | :comments => comments) | |
248 |
|
260 | |||
249 | te2 = TimeEntry.find_by_comments(comments) |
|
261 | te2 = TimeEntry.find_by_comments(comments) | |
250 | assert_not_nil te2 |
|
262 | assert_not_nil te2 | |
251 | assert_equal 7.3, te2.hours |
|
263 | assert_equal 7.3, te2.hours | |
252 | assert_equal 3, te2.user_id |
|
264 | assert_equal 3, te2.user_id | |
253 |
|
265 | |||
254 | get :report, :project_id => 1, :columns => 'day', |
|
266 | get :report, :project_id => 1, :columns => 'day', | |
255 | :from => "2011-11-11", :to => "2011-11-11", |
|
267 | :from => "2011-11-11", :to => "2011-11-11", | |
256 | :criteria => ["user"], :format => "csv" |
|
268 | :criteria => ["user"], :format => "csv" | |
257 | assert_response :success |
|
269 | assert_response :success | |
258 | assert_equal 'text/csv; header=present', @response.content_type |
|
270 | assert_equal 'text/csv; header=present', @response.content_type | |
259 | lines = @response.body.chomp.split("\n") |
|
271 | lines = @response.body.chomp.split("\n") | |
260 | # Headers |
|
272 | # Headers | |
261 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp" |
|
273 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp" | |
262 | s2 = "\xa4u\xae\xc9\xc1`\xadp" |
|
274 | s2 = "\xa4u\xae\xc9\xc1`\xadp" | |
263 | if s1.respond_to?(:force_encoding) |
|
275 | if s1.respond_to?(:force_encoding) | |
264 | s1.force_encoding('Big5') |
|
276 | s1.force_encoding('Big5') | |
265 | s2.force_encoding('Big5') |
|
277 | s2.force_encoding('Big5') | |
266 | end |
|
278 | end | |
267 | assert_equal s1, lines.first |
|
279 | assert_equal s1, lines.first | |
268 | # Total row |
|
280 | # Total row | |
269 | assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1] |
|
281 | assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1] | |
270 | assert_equal "#{s2},7.30,7.30", lines[2] |
|
282 | assert_equal "#{s2},7.30,7.30", lines[2] | |
271 |
|
283 | |||
272 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)" |
|
284 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)" | |
273 | if str_tw.respond_to?(:force_encoding) |
|
285 | if str_tw.respond_to?(:force_encoding) | |
274 | str_tw.force_encoding('UTF-8') |
|
286 | str_tw.force_encoding('UTF-8') | |
275 | end |
|
287 | end | |
276 | assert_equal str_tw, l(:general_lang_name) |
|
288 | assert_equal str_tw, l(:general_lang_name) | |
277 | assert_equal 'Big5', l(:general_csv_encoding) |
|
289 | assert_equal 'Big5', l(:general_csv_encoding) | |
278 | assert_equal ',', l(:general_csv_separator) |
|
290 | assert_equal ',', l(:general_csv_separator) | |
279 | assert_equal '.', l(:general_csv_decimal_separator) |
|
291 | assert_equal '.', l(:general_csv_decimal_separator) | |
280 | end |
|
292 | end | |
281 |
|
293 | |||
282 | def test_csv_cannot_convert_should_be_replaced_big_5 |
|
294 | def test_csv_cannot_convert_should_be_replaced_big_5 | |
283 | Setting.default_language = "zh-TW" |
|
295 | Setting.default_language = "zh-TW" | |
284 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" |
|
296 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" | |
285 | if str_utf8.respond_to?(:force_encoding) |
|
297 | if str_utf8.respond_to?(:force_encoding) | |
286 | str_utf8.force_encoding('UTF-8') |
|
298 | str_utf8.force_encoding('UTF-8') | |
287 | end |
|
299 | end | |
288 | user = User.find_by_id(3) |
|
300 | user = User.find_by_id(3) | |
289 | user.firstname = str_utf8 |
|
301 | user.firstname = str_utf8 | |
290 | user.lastname = "test-lastname" |
|
302 | user.lastname = "test-lastname" | |
291 | assert user.save |
|
303 | assert user.save | |
292 | comments = "test_replaced" |
|
304 | comments = "test_replaced" | |
293 | te1 = TimeEntry.create(:spent_on => '2011-11-11', |
|
305 | te1 = TimeEntry.create(:spent_on => '2011-11-11', | |
294 | :hours => 7.3, |
|
306 | :hours => 7.3, | |
295 | :project => Project.find(1), |
|
307 | :project => Project.find(1), | |
296 | :user => user, |
|
308 | :user => user, | |
297 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
309 | :activity => TimeEntryActivity.find_by_name('Design'), | |
298 | :comments => comments) |
|
310 | :comments => comments) | |
299 |
|
311 | |||
300 | te2 = TimeEntry.find_by_comments(comments) |
|
312 | te2 = TimeEntry.find_by_comments(comments) | |
301 | assert_not_nil te2 |
|
313 | assert_not_nil te2 | |
302 | assert_equal 7.3, te2.hours |
|
314 | assert_equal 7.3, te2.hours | |
303 | assert_equal 3, te2.user_id |
|
315 | assert_equal 3, te2.user_id | |
304 |
|
316 | |||
305 | get :report, :project_id => 1, :columns => 'day', |
|
317 | get :report, :project_id => 1, :columns => 'day', | |
306 | :from => "2011-11-11", :to => "2011-11-11", |
|
318 | :from => "2011-11-11", :to => "2011-11-11", | |
307 | :criteria => ["user"], :format => "csv" |
|
319 | :criteria => ["user"], :format => "csv" | |
308 | assert_response :success |
|
320 | assert_response :success | |
309 | assert_equal 'text/csv; header=present', @response.content_type |
|
321 | assert_equal 'text/csv; header=present', @response.content_type | |
310 | lines = @response.body.chomp.split("\n") |
|
322 | lines = @response.body.chomp.split("\n") | |
311 | # Headers |
|
323 | # Headers | |
312 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp" |
|
324 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp" | |
313 | if s1.respond_to?(:force_encoding) |
|
325 | if s1.respond_to?(:force_encoding) | |
314 | s1.force_encoding('Big5') |
|
326 | s1.force_encoding('Big5') | |
315 | end |
|
327 | end | |
316 | assert_equal s1, lines.first |
|
328 | assert_equal s1, lines.first | |
317 | # Total row |
|
329 | # Total row | |
318 | s2 = "" |
|
330 | s2 = "" | |
319 | if s2.respond_to?(:force_encoding) |
|
331 | if s2.respond_to?(:force_encoding) | |
320 | s2 = "\xa5H?" |
|
332 | s2 = "\xa5H?" | |
321 | s2.force_encoding('Big5') |
|
333 | s2.force_encoding('Big5') | |
322 | elsif RUBY_PLATFORM == 'java' |
|
334 | elsif RUBY_PLATFORM == 'java' | |
323 | s2 = "??" |
|
335 | s2 = "??" | |
324 | else |
|
336 | else | |
325 | s2 = "\xa5H???" |
|
337 | s2 = "\xa5H???" | |
326 | end |
|
338 | end | |
327 | assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1] |
|
339 | assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1] | |
328 | end |
|
340 | end | |
329 |
|
341 | |||
330 | def test_csv_fr |
|
342 | def test_csv_fr | |
331 | with_settings :default_language => "fr" do |
|
343 | with_settings :default_language => "fr" do | |
332 | str1 = "test_csv_fr" |
|
344 | str1 = "test_csv_fr" | |
333 | user = User.find_by_id(3) |
|
345 | user = User.find_by_id(3) | |
334 | te1 = TimeEntry.create(:spent_on => '2011-11-11', |
|
346 | te1 = TimeEntry.create(:spent_on => '2011-11-11', | |
335 | :hours => 7.3, |
|
347 | :hours => 7.3, | |
336 | :project => Project.find(1), |
|
348 | :project => Project.find(1), | |
337 | :user => user, |
|
349 | :user => user, | |
338 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
350 | :activity => TimeEntryActivity.find_by_name('Design'), | |
339 | :comments => str1) |
|
351 | :comments => str1) | |
340 |
|
352 | |||
341 | te2 = TimeEntry.find_by_comments(str1) |
|
353 | te2 = TimeEntry.find_by_comments(str1) | |
342 | assert_not_nil te2 |
|
354 | assert_not_nil te2 | |
343 | assert_equal 7.3, te2.hours |
|
355 | assert_equal 7.3, te2.hours | |
344 | assert_equal 3, te2.user_id |
|
356 | assert_equal 3, te2.user_id | |
345 |
|
357 | |||
346 | get :report, :project_id => 1, :columns => 'day', |
|
358 | get :report, :project_id => 1, :columns => 'day', | |
347 | :from => "2011-11-11", :to => "2011-11-11", |
|
359 | :from => "2011-11-11", :to => "2011-11-11", | |
348 | :criteria => ["user"], :format => "csv" |
|
360 | :criteria => ["user"], :format => "csv" | |
349 | assert_response :success |
|
361 | assert_response :success | |
350 | assert_equal 'text/csv; header=present', @response.content_type |
|
362 | assert_equal 'text/csv; header=present', @response.content_type | |
351 | lines = @response.body.chomp.split("\n") |
|
363 | lines = @response.body.chomp.split("\n") | |
352 | # Headers |
|
364 | # Headers | |
353 | s1 = "Utilisateur;2011-11-11;Temps total" |
|
365 | s1 = "Utilisateur;2011-11-11;Temps total" | |
354 | s2 = "Temps total" |
|
366 | s2 = "Temps total" | |
355 | if s1.respond_to?(:force_encoding) |
|
367 | if s1.respond_to?(:force_encoding) | |
356 | s1.force_encoding('ISO-8859-1') |
|
368 | s1.force_encoding('ISO-8859-1') | |
357 | s2.force_encoding('ISO-8859-1') |
|
369 | s2.force_encoding('ISO-8859-1') | |
358 | end |
|
370 | end | |
359 | assert_equal s1, lines.first |
|
371 | assert_equal s1, lines.first | |
360 | # Total row |
|
372 | # Total row | |
361 | assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1] |
|
373 | assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1] | |
362 | assert_equal "#{s2};7,30;7,30", lines[2] |
|
374 | assert_equal "#{s2};7,30;7,30", lines[2] | |
363 |
|
375 | |||
364 | str_fr = "Fran\xc3\xa7ais" |
|
376 | str_fr = "Fran\xc3\xa7ais" | |
365 | if str_fr.respond_to?(:force_encoding) |
|
377 | if str_fr.respond_to?(:force_encoding) | |
366 | str_fr.force_encoding('UTF-8') |
|
378 | str_fr.force_encoding('UTF-8') | |
367 | end |
|
379 | end | |
368 | assert_equal str_fr, l(:general_lang_name) |
|
380 | assert_equal str_fr, l(:general_lang_name) | |
369 | assert_equal 'ISO-8859-1', l(:general_csv_encoding) |
|
381 | assert_equal 'ISO-8859-1', l(:general_csv_encoding) | |
370 | assert_equal ';', l(:general_csv_separator) |
|
382 | assert_equal ';', l(:general_csv_separator) | |
371 | assert_equal ',', l(:general_csv_decimal_separator) |
|
383 | assert_equal ',', l(:general_csv_decimal_separator) | |
372 | end |
|
384 | end | |
373 | end |
|
385 | end | |
374 | end |
|
386 | end |
General Comments 0
You need to be logged in to leave comments.
Login now