@@ -1,353 +1,354 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | # Redmine - project management software |
|
2 | # Redmine - project management software | |
3 | # Copyright (C) 2006-2015 Jean-Philippe Lang |
|
3 | # Copyright (C) 2006-2015 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 | :email_addresses, | |||
25 | :issues, :time_entries, :users, :trackers, :enumerations, |
|
26 | :issues, :time_entries, :users, :trackers, :enumerations, | |
26 | :issue_statuses, :custom_fields, :custom_values, |
|
27 | :issue_statuses, :custom_fields, :custom_values, | |
27 | :projects_trackers, :custom_fields_trackers, |
|
28 | :projects_trackers, :custom_fields_trackers, | |
28 | :custom_fields_projects |
|
29 | :custom_fields_projects | |
29 |
|
30 | |||
30 | include Redmine::I18n |
|
31 | include Redmine::I18n | |
31 |
|
32 | |||
32 | def setup |
|
33 | def setup | |
33 | Setting.default_language = "en" |
|
34 | Setting.default_language = "en" | |
34 | end |
|
35 | end | |
35 |
|
36 | |||
36 | def test_report_at_project_level |
|
37 | def test_report_at_project_level | |
37 | get :report, :project_id => 'ecookbook' |
|
38 | get :report, :project_id => 'ecookbook' | |
38 | assert_response :success |
|
39 | assert_response :success | |
39 | assert_template 'report' |
|
40 | assert_template 'report' | |
40 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries/report' |
|
41 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries/report' | |
41 | end |
|
42 | end | |
42 |
|
43 | |||
43 | def test_report_all_projects |
|
44 | def test_report_all_projects | |
44 | get :report |
|
45 | get :report | |
45 | assert_response :success |
|
46 | assert_response :success | |
46 | assert_template 'report' |
|
47 | assert_template 'report' | |
47 | assert_select 'form#query_form[action=?]', '/time_entries/report' |
|
48 | assert_select 'form#query_form[action=?]', '/time_entries/report' | |
48 | end |
|
49 | end | |
49 |
|
50 | |||
50 | def test_report_all_projects_denied |
|
51 | def test_report_all_projects_denied | |
51 | r = Role.anonymous |
|
52 | r = Role.anonymous | |
52 | r.permissions.delete(:view_time_entries) |
|
53 | r.permissions.delete(:view_time_entries) | |
53 | r.permissions_will_change! |
|
54 | r.permissions_will_change! | |
54 | r.save |
|
55 | r.save | |
55 | get :report |
|
56 | get :report | |
56 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' |
|
57 | assert_redirected_to '/login?back_url=http%3A%2F%2Ftest.host%2Ftime_entries%2Freport' | |
57 | end |
|
58 | end | |
58 |
|
59 | |||
59 | def test_report_all_projects_one_criteria |
|
60 | def test_report_all_projects_one_criteria | |
60 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] |
|
61 | get :report, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] | |
61 | assert_response :success |
|
62 | assert_response :success | |
62 | assert_template 'report' |
|
63 | assert_template 'report' | |
63 | assert_not_nil assigns(:report) |
|
64 | assert_not_nil assigns(:report) | |
64 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours |
|
65 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours | |
65 | end |
|
66 | end | |
66 |
|
67 | |||
67 | def test_report_all_time |
|
68 | def test_report_all_time | |
68 | get :report, :project_id => 1, :criteria => ['project', 'issue'] |
|
69 | get :report, :project_id => 1, :criteria => ['project', 'issue'] | |
69 | assert_response :success |
|
70 | assert_response :success | |
70 | assert_template 'report' |
|
71 | assert_template 'report' | |
71 | assert_not_nil assigns(:report) |
|
72 | assert_not_nil assigns(:report) | |
72 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
73 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
73 | end |
|
74 | end | |
74 |
|
75 | |||
75 | def test_report_all_time_by_day |
|
76 | def test_report_all_time_by_day | |
76 | get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day' |
|
77 | get :report, :project_id => 1, :criteria => ['project', 'issue'], :columns => 'day' | |
77 | assert_response :success |
|
78 | assert_response :success | |
78 | assert_template 'report' |
|
79 | assert_template 'report' | |
79 | assert_not_nil assigns(:report) |
|
80 | assert_not_nil assigns(:report) | |
80 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
81 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
81 | assert_select 'th', :text => '2007-03-12' |
|
82 | assert_select 'th', :text => '2007-03-12' | |
82 | end |
|
83 | end | |
83 |
|
84 | |||
84 | def test_report_one_criteria |
|
85 | def test_report_one_criteria | |
85 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] |
|
86 | get :report, :project_id => 1, :columns => 'week', :from => "2007-04-01", :to => "2007-04-30", :criteria => ['project'] | |
86 | assert_response :success |
|
87 | assert_response :success | |
87 | assert_template 'report' |
|
88 | assert_template 'report' | |
88 | assert_not_nil assigns(:report) |
|
89 | assert_not_nil assigns(:report) | |
89 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours |
|
90 | assert_equal "8.65", "%.2f" % assigns(:report).total_hours | |
90 | end |
|
91 | end | |
91 |
|
92 | |||
92 | def test_report_two_criteria |
|
93 | def test_report_two_criteria | |
93 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] |
|
94 | get :report, :project_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] | |
94 | assert_response :success |
|
95 | assert_response :success | |
95 | assert_template 'report' |
|
96 | assert_template 'report' | |
96 | assert_not_nil assigns(:report) |
|
97 | assert_not_nil assigns(:report) | |
97 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
98 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
98 | end |
|
99 | end | |
99 |
|
100 | |||
100 | def test_report_custom_field_criteria_with_multiple_values_on_single_value_custom_field_should_not_fail |
|
101 | def test_report_custom_field_criteria_with_multiple_values_on_single_value_custom_field_should_not_fail | |
101 | field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2']) |
|
102 | field = TimeEntryCustomField.create!(:name => 'multi', :field_format => 'list', :possible_values => ['value1', 'value2']) | |
102 | entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today) |
|
103 | entry = TimeEntry.create!(:project => Project.find(1), :hours => 1, :activity_id => 10, :user => User.find(2), :spent_on => Date.today) | |
103 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1') |
|
104 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value1') | |
104 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2') |
|
105 | CustomValue.create!(:customized => entry, :custom_field => field, :value => 'value2') | |
105 |
|
106 | |||
106 | get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"] |
|
107 | get :report, :project_id => 1, :columns => 'day', :criteria => ["cf_#{field.id}"] | |
107 | assert_response :success |
|
108 | assert_response :success | |
108 | end |
|
109 | end | |
109 |
|
110 | |||
110 | def test_report_multiple_values_custom_fields_should_not_be_proposed |
|
111 | def test_report_multiple_values_custom_fields_should_not_be_proposed | |
111 | TimeEntryCustomField.create!(:name => 'Single', :field_format => 'list', :possible_values => ['value1', 'value2']) |
|
112 | TimeEntryCustomField.create!(:name => 'Single', :field_format => 'list', :possible_values => ['value1', 'value2']) | |
112 | TimeEntryCustomField.create!(:name => 'Multi', :field_format => 'list', :multiple => true, :possible_values => ['value1', 'value2']) |
|
113 | TimeEntryCustomField.create!(:name => 'Multi', :field_format => 'list', :multiple => true, :possible_values => ['value1', 'value2']) | |
113 |
|
114 | |||
114 | get :report, :project_id => 1 |
|
115 | get :report, :project_id => 1 | |
115 | assert_response :success |
|
116 | assert_response :success | |
116 | assert_select 'select[name=?]', 'criteria[]' do |
|
117 | assert_select 'select[name=?]', 'criteria[]' do | |
117 | assert_select 'option', :text => 'Single' |
|
118 | assert_select 'option', :text => 'Single' | |
118 | assert_select 'option', :text => 'Multi', :count => 0 |
|
119 | assert_select 'option', :text => 'Multi', :count => 0 | |
119 | end |
|
120 | end | |
120 | end |
|
121 | end | |
121 |
|
122 | |||
122 | def test_report_one_day |
|
123 | def test_report_one_day | |
123 | get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["user", "activity"] |
|
124 | get :report, :project_id => 1, :columns => 'day', :from => "2007-03-23", :to => "2007-03-23", :criteria => ["user", "activity"] | |
124 | assert_response :success |
|
125 | assert_response :success | |
125 | assert_template 'report' |
|
126 | assert_template 'report' | |
126 | assert_not_nil assigns(:report) |
|
127 | assert_not_nil assigns(:report) | |
127 | assert_equal "4.25", "%.2f" % assigns(:report).total_hours |
|
128 | assert_equal "4.25", "%.2f" % assigns(:report).total_hours | |
128 | end |
|
129 | end | |
129 |
|
130 | |||
130 | def test_report_at_issue_level |
|
131 | def test_report_at_issue_level | |
131 | get :report, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] |
|
132 | get :report, :issue_id => 1, :columns => 'month', :from => "2007-01-01", :to => "2007-12-31", :criteria => ["user", "activity"] | |
132 | assert_response :success |
|
133 | assert_response :success | |
133 | assert_template 'report' |
|
134 | assert_template 'report' | |
134 | assert_not_nil assigns(:report) |
|
135 | assert_not_nil assigns(:report) | |
135 | assert_equal "154.25", "%.2f" % assigns(:report).total_hours |
|
136 | assert_equal "154.25", "%.2f" % assigns(:report).total_hours | |
136 | assert_select 'form#query_form[action=?]', '/issues/1/time_entries/report' |
|
137 | assert_select 'form#query_form[action=?]', '/issues/1/time_entries/report' | |
137 | end |
|
138 | end | |
138 |
|
139 | |||
139 | def test_report_by_week_should_use_commercial_year |
|
140 | def test_report_by_week_should_use_commercial_year | |
140 | TimeEntry.delete_all |
|
141 | TimeEntry.delete_all | |
141 | TimeEntry.generate!(:hours => '2', :spent_on => '2009-12-25') # 2009-52 |
|
142 | TimeEntry.generate!(:hours => '2', :spent_on => '2009-12-25') # 2009-52 | |
142 | TimeEntry.generate!(:hours => '4', :spent_on => '2009-12-31') # 2009-53 |
|
143 | TimeEntry.generate!(:hours => '4', :spent_on => '2009-12-31') # 2009-53 | |
143 | TimeEntry.generate!(:hours => '8', :spent_on => '2010-01-01') # 2009-53 |
|
144 | TimeEntry.generate!(:hours => '8', :spent_on => '2010-01-01') # 2009-53 | |
144 | TimeEntry.generate!(:hours => '16', :spent_on => '2010-01-05') # 2010-1 |
|
145 | TimeEntry.generate!(:hours => '16', :spent_on => '2010-01-05') # 2010-1 | |
145 |
|
146 | |||
146 | get :report, :columns => 'week', :from => "2009-12-25", :to => "2010-01-05", :criteria => ["project"] |
|
147 | get :report, :columns => 'week', :from => "2009-12-25", :to => "2010-01-05", :criteria => ["project"] | |
147 | assert_response :success |
|
148 | assert_response :success | |
148 |
|
149 | |||
149 | assert_select '#time-report thead tr' do |
|
150 | assert_select '#time-report thead tr' do | |
150 | assert_select 'th:nth-child(1)', :text => 'Project' |
|
151 | assert_select 'th:nth-child(1)', :text => 'Project' | |
151 | assert_select 'th:nth-child(2)', :text => '2009-52' |
|
152 | assert_select 'th:nth-child(2)', :text => '2009-52' | |
152 | assert_select 'th:nth-child(3)', :text => '2009-53' |
|
153 | assert_select 'th:nth-child(3)', :text => '2009-53' | |
153 | assert_select 'th:nth-child(4)', :text => '2010-1' |
|
154 | assert_select 'th:nth-child(4)', :text => '2010-1' | |
154 | assert_select 'th:nth-child(5)', :text => 'Total time' |
|
155 | assert_select 'th:nth-child(5)', :text => 'Total time' | |
155 | end |
|
156 | end | |
156 | assert_select '#time-report tbody tr' do |
|
157 | assert_select '#time-report tbody tr' do | |
157 | assert_select 'td:nth-child(1)', :text => 'eCookbook' |
|
158 | assert_select 'td:nth-child(1)', :text => 'eCookbook' | |
158 | assert_select 'td:nth-child(2)', :text => '2.00' |
|
159 | assert_select 'td:nth-child(2)', :text => '2.00' | |
159 | assert_select 'td:nth-child(3)', :text => '12.00' |
|
160 | assert_select 'td:nth-child(3)', :text => '12.00' | |
160 | assert_select 'td:nth-child(4)', :text => '16.00' |
|
161 | assert_select 'td:nth-child(4)', :text => '16.00' | |
161 | assert_select 'td:nth-child(5)', :text => '30.00' # Total |
|
162 | assert_select 'td:nth-child(5)', :text => '30.00' # Total | |
162 | end |
|
163 | end | |
163 | end |
|
164 | end | |
164 |
|
165 | |||
165 | def test_report_should_propose_association_custom_fields |
|
166 | def test_report_should_propose_association_custom_fields | |
166 | get :report |
|
167 | get :report | |
167 | assert_response :success |
|
168 | assert_response :success | |
168 | assert_template 'report' |
|
169 | assert_template 'report' | |
169 |
|
170 | |||
170 | assert_select 'select[name=?]', 'criteria[]' do |
|
171 | assert_select 'select[name=?]', 'criteria[]' do | |
171 | assert_select 'option[value=cf_1]', {:text => 'Database'}, 'Issue custom field not found' |
|
172 | assert_select 'option[value=cf_1]', {:text => 'Database'}, 'Issue custom field not found' | |
172 | assert_select 'option[value=cf_3]', {:text => 'Development status'}, 'Project custom field not found' |
|
173 | assert_select 'option[value=cf_3]', {:text => 'Development status'}, 'Project custom field not found' | |
173 | assert_select 'option[value=cf_7]', {:text => 'Billable'}, 'TimeEntryActivity custom field not found' |
|
174 | assert_select 'option[value=cf_7]', {:text => 'Billable'}, 'TimeEntryActivity custom field not found' | |
174 | end |
|
175 | end | |
175 | end |
|
176 | end | |
176 |
|
177 | |||
177 | def test_report_with_association_custom_fields |
|
178 | def test_report_with_association_custom_fields | |
178 | get :report, :criteria => ['cf_1', 'cf_3', 'cf_7'] |
|
179 | get :report, :criteria => ['cf_1', 'cf_3', 'cf_7'] | |
179 | assert_response :success |
|
180 | assert_response :success | |
180 | assert_template 'report' |
|
181 | assert_template 'report' | |
181 | assert_not_nil assigns(:report) |
|
182 | assert_not_nil assigns(:report) | |
182 | assert_equal 3, assigns(:report).criteria.size |
|
183 | assert_equal 3, assigns(:report).criteria.size | |
183 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours |
|
184 | assert_equal "162.90", "%.2f" % assigns(:report).total_hours | |
184 |
|
185 | |||
185 | # Custom fields columns |
|
186 | # Custom fields columns | |
186 | assert_select 'th', :text => 'Database' |
|
187 | assert_select 'th', :text => 'Database' | |
187 | assert_select 'th', :text => 'Development status' |
|
188 | assert_select 'th', :text => 'Development status' | |
188 | assert_select 'th', :text => 'Billable' |
|
189 | assert_select 'th', :text => 'Billable' | |
189 |
|
190 | |||
190 | # Custom field row |
|
191 | # Custom field row | |
191 | assert_select 'tr' do |
|
192 | assert_select 'tr' do | |
192 | assert_select 'td', :text => 'MySQL' |
|
193 | assert_select 'td', :text => 'MySQL' | |
193 | assert_select 'td.hours', :text => '1.00' |
|
194 | assert_select 'td.hours', :text => '1.00' | |
194 | end |
|
195 | end | |
195 | end |
|
196 | end | |
196 |
|
197 | |||
197 | def test_report_one_criteria_no_result |
|
198 | def test_report_one_criteria_no_result | |
198 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project'] |
|
199 | get :report, :project_id => 1, :columns => 'week', :from => "1998-04-01", :to => "1998-04-30", :criteria => ['project'] | |
199 | assert_response :success |
|
200 | assert_response :success | |
200 | assert_template 'report' |
|
201 | assert_template 'report' | |
201 | assert_not_nil assigns(:report) |
|
202 | assert_not_nil assigns(:report) | |
202 | assert_equal "0.00", "%.2f" % assigns(:report).total_hours |
|
203 | assert_equal "0.00", "%.2f" % assigns(:report).total_hours | |
203 | end |
|
204 | end | |
204 |
|
205 | |||
205 | def test_report_status_criterion |
|
206 | def test_report_status_criterion | |
206 | get :report, :project_id => 1, :criteria => ['status'] |
|
207 | get :report, :project_id => 1, :criteria => ['status'] | |
207 | assert_response :success |
|
208 | assert_response :success | |
208 | assert_template 'report' |
|
209 | assert_template 'report' | |
209 | assert_select 'th', :text => 'Status' |
|
210 | assert_select 'th', :text => 'Status' | |
210 | assert_select 'td', :text => 'New' |
|
211 | assert_select 'td', :text => 'New' | |
211 | end |
|
212 | end | |
212 |
|
213 | |||
213 | def test_report_all_projects_csv_export |
|
214 | def test_report_all_projects_csv_export | |
214 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", |
|
215 | get :report, :columns => 'month', :from => "2007-01-01", :to => "2007-06-30", | |
215 | :criteria => ["project", "user", "activity"], :format => "csv" |
|
216 | :criteria => ["project", "user", "activity"], :format => "csv" | |
216 | assert_response :success |
|
217 | assert_response :success | |
217 | assert_equal 'text/csv; header=present', @response.content_type |
|
218 | assert_equal 'text/csv; header=present', @response.content_type | |
218 | lines = @response.body.chomp.split("\n") |
|
219 | lines = @response.body.chomp.split("\n") | |
219 | # Headers |
|
220 | # Headers | |
220 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first |
|
221 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first | |
221 | # Total row |
|
222 | # Total row | |
222 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last |
|
223 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last | |
223 | end |
|
224 | end | |
224 |
|
225 | |||
225 | def test_report_csv_export |
|
226 | def test_report_csv_export | |
226 | get :report, :project_id => 1, :columns => 'month', |
|
227 | get :report, :project_id => 1, :columns => 'month', | |
227 | :from => "2007-01-01", :to => "2007-06-30", |
|
228 | :from => "2007-01-01", :to => "2007-06-30", | |
228 | :criteria => ["project", "user", "activity"], :format => "csv" |
|
229 | :criteria => ["project", "user", "activity"], :format => "csv" | |
229 | assert_response :success |
|
230 | assert_response :success | |
230 | assert_equal 'text/csv; header=present', @response.content_type |
|
231 | assert_equal 'text/csv; header=present', @response.content_type | |
231 | lines = @response.body.chomp.split("\n") |
|
232 | lines = @response.body.chomp.split("\n") | |
232 | # Headers |
|
233 | # Headers | |
233 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first |
|
234 | assert_equal 'Project,User,Activity,2007-3,2007-4,Total time', lines.first | |
234 | # Total row |
|
235 | # Total row | |
235 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last |
|
236 | assert_equal 'Total time,"","",154.25,8.65,162.90', lines.last | |
236 | end |
|
237 | end | |
237 |
|
238 | |||
238 | def test_csv_big_5 |
|
239 | def test_csv_big_5 | |
239 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8') |
|
240 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88".force_encoding('UTF-8') | |
240 | str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5') |
|
241 | str_big5 = "\xa4@\xa4\xeb".force_encoding('Big5') | |
241 | user = User.find_by_id(3) |
|
242 | user = User.find_by_id(3) | |
242 | user.firstname = str_utf8 |
|
243 | user.firstname = str_utf8 | |
243 | user.lastname = "test-lastname" |
|
244 | user.lastname = "test-lastname" | |
244 | assert user.save |
|
245 | assert user.save | |
245 | comments = "test_csv_big_5" |
|
246 | comments = "test_csv_big_5" | |
246 | te1 = TimeEntry.create(:spent_on => '2011-11-11', |
|
247 | te1 = TimeEntry.create(:spent_on => '2011-11-11', | |
247 | :hours => 7.3, |
|
248 | :hours => 7.3, | |
248 | :project => Project.find(1), |
|
249 | :project => Project.find(1), | |
249 | :user => user, |
|
250 | :user => user, | |
250 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
251 | :activity => TimeEntryActivity.find_by_name('Design'), | |
251 | :comments => comments) |
|
252 | :comments => comments) | |
252 |
|
253 | |||
253 | te2 = TimeEntry.find_by_comments(comments) |
|
254 | te2 = TimeEntry.find_by_comments(comments) | |
254 | assert_not_nil te2 |
|
255 | assert_not_nil te2 | |
255 | assert_equal 7.3, te2.hours |
|
256 | assert_equal 7.3, te2.hours | |
256 | assert_equal 3, te2.user_id |
|
257 | assert_equal 3, te2.user_id | |
257 |
|
258 | |||
258 | with_settings :default_language => "zh-TW" do |
|
259 | with_settings :default_language => "zh-TW" do | |
259 | get :report, :project_id => 1, :columns => 'day', |
|
260 | get :report, :project_id => 1, :columns => 'day', | |
260 | :from => "2011-11-11", :to => "2011-11-11", |
|
261 | :from => "2011-11-11", :to => "2011-11-11", | |
261 | :criteria => ["user"], :format => "csv" |
|
262 | :criteria => ["user"], :format => "csv" | |
262 | end |
|
263 | end | |
263 | assert_response :success |
|
264 | assert_response :success | |
264 | assert_equal 'text/csv; header=present', @response.content_type |
|
265 | assert_equal 'text/csv; header=present', @response.content_type | |
265 | lines = @response.body.chomp.split("\n") |
|
266 | lines = @response.body.chomp.split("\n") | |
266 | # Headers |
|
267 | # Headers | |
267 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') |
|
268 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') | |
268 | s2 = "\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') |
|
269 | s2 = "\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') | |
269 | assert_equal s1, lines.first |
|
270 | assert_equal s1, lines.first | |
270 | # Total row |
|
271 | # Total row | |
271 | assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1] |
|
272 | assert_equal "#{str_big5} #{user.lastname},7.30,7.30", lines[1] | |
272 | assert_equal "#{s2},7.30,7.30", lines[2] |
|
273 | assert_equal "#{s2},7.30,7.30", lines[2] | |
273 |
|
274 | |||
274 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8') |
|
275 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)".force_encoding('UTF-8') | |
275 | assert_equal str_tw, l(:general_lang_name) |
|
276 | assert_equal str_tw, l(:general_lang_name) | |
276 | assert_equal 'Big5', l(:general_csv_encoding) |
|
277 | assert_equal 'Big5', l(:general_csv_encoding) | |
277 | assert_equal ',', l(:general_csv_separator) |
|
278 | assert_equal ',', l(:general_csv_separator) | |
278 | assert_equal '.', l(:general_csv_decimal_separator) |
|
279 | assert_equal '.', l(:general_csv_decimal_separator) | |
279 | end |
|
280 | end | |
280 |
|
281 | |||
281 | def test_csv_cannot_convert_should_be_replaced_big_5 |
|
282 | def test_csv_cannot_convert_should_be_replaced_big_5 | |
282 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8') |
|
283 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85".force_encoding('UTF-8') | |
283 | user = User.find_by_id(3) |
|
284 | user = User.find_by_id(3) | |
284 | user.firstname = str_utf8 |
|
285 | user.firstname = str_utf8 | |
285 | user.lastname = "test-lastname" |
|
286 | user.lastname = "test-lastname" | |
286 | assert user.save |
|
287 | assert user.save | |
287 | comments = "test_replaced" |
|
288 | comments = "test_replaced" | |
288 | te1 = TimeEntry.create(:spent_on => '2011-11-11', |
|
289 | te1 = TimeEntry.create(:spent_on => '2011-11-11', | |
289 | :hours => 7.3, |
|
290 | :hours => 7.3, | |
290 | :project => Project.find(1), |
|
291 | :project => Project.find(1), | |
291 | :user => user, |
|
292 | :user => user, | |
292 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
293 | :activity => TimeEntryActivity.find_by_name('Design'), | |
293 | :comments => comments) |
|
294 | :comments => comments) | |
294 |
|
295 | |||
295 | te2 = TimeEntry.find_by_comments(comments) |
|
296 | te2 = TimeEntry.find_by_comments(comments) | |
296 | assert_not_nil te2 |
|
297 | assert_not_nil te2 | |
297 | assert_equal 7.3, te2.hours |
|
298 | assert_equal 7.3, te2.hours | |
298 | assert_equal 3, te2.user_id |
|
299 | assert_equal 3, te2.user_id | |
299 |
|
300 | |||
300 | with_settings :default_language => "zh-TW" do |
|
301 | with_settings :default_language => "zh-TW" do | |
301 | get :report, :project_id => 1, :columns => 'day', |
|
302 | get :report, :project_id => 1, :columns => 'day', | |
302 | :from => "2011-11-11", :to => "2011-11-11", |
|
303 | :from => "2011-11-11", :to => "2011-11-11", | |
303 | :criteria => ["user"], :format => "csv" |
|
304 | :criteria => ["user"], :format => "csv" | |
304 | end |
|
305 | end | |
305 | assert_response :success |
|
306 | assert_response :success | |
306 | assert_equal 'text/csv; header=present', @response.content_type |
|
307 | assert_equal 'text/csv; header=present', @response.content_type | |
307 | lines = @response.body.chomp.split("\n") |
|
308 | lines = @response.body.chomp.split("\n") | |
308 | # Headers |
|
309 | # Headers | |
309 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') |
|
310 | s1 = "\xa5\xce\xa4\xe1,2011-11-11,\xa4u\xae\xc9\xc1`\xadp".force_encoding('Big5') | |
310 | assert_equal s1, lines.first |
|
311 | assert_equal s1, lines.first | |
311 | # Total row |
|
312 | # Total row | |
312 | s2 = "\xa5H?".force_encoding('Big5') |
|
313 | s2 = "\xa5H?".force_encoding('Big5') | |
313 | assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1] |
|
314 | assert_equal "#{s2} #{user.lastname},7.30,7.30", lines[1] | |
314 | end |
|
315 | end | |
315 |
|
316 | |||
316 | def test_csv_fr |
|
317 | def test_csv_fr | |
317 | with_settings :default_language => "fr" do |
|
318 | with_settings :default_language => "fr" do | |
318 | str1 = "test_csv_fr" |
|
319 | str1 = "test_csv_fr" | |
319 | user = User.find_by_id(3) |
|
320 | user = User.find_by_id(3) | |
320 | te1 = TimeEntry.create(:spent_on => '2011-11-11', |
|
321 | te1 = TimeEntry.create(:spent_on => '2011-11-11', | |
321 | :hours => 7.3, |
|
322 | :hours => 7.3, | |
322 | :project => Project.find(1), |
|
323 | :project => Project.find(1), | |
323 | :user => user, |
|
324 | :user => user, | |
324 | :activity => TimeEntryActivity.find_by_name('Design'), |
|
325 | :activity => TimeEntryActivity.find_by_name('Design'), | |
325 | :comments => str1) |
|
326 | :comments => str1) | |
326 |
|
327 | |||
327 | te2 = TimeEntry.find_by_comments(str1) |
|
328 | te2 = TimeEntry.find_by_comments(str1) | |
328 | assert_not_nil te2 |
|
329 | assert_not_nil te2 | |
329 | assert_equal 7.3, te2.hours |
|
330 | assert_equal 7.3, te2.hours | |
330 | assert_equal 3, te2.user_id |
|
331 | assert_equal 3, te2.user_id | |
331 |
|
332 | |||
332 | get :report, :project_id => 1, :columns => 'day', |
|
333 | get :report, :project_id => 1, :columns => 'day', | |
333 | :from => "2011-11-11", :to => "2011-11-11", |
|
334 | :from => "2011-11-11", :to => "2011-11-11", | |
334 | :criteria => ["user"], :format => "csv" |
|
335 | :criteria => ["user"], :format => "csv" | |
335 | assert_response :success |
|
336 | assert_response :success | |
336 | assert_equal 'text/csv; header=present', @response.content_type |
|
337 | assert_equal 'text/csv; header=present', @response.content_type | |
337 | lines = @response.body.chomp.split("\n") |
|
338 | lines = @response.body.chomp.split("\n") | |
338 | # Headers |
|
339 | # Headers | |
339 | s1 = "Utilisateur;2011-11-11;Temps total".force_encoding('ISO-8859-1') |
|
340 | s1 = "Utilisateur;2011-11-11;Temps total".force_encoding('ISO-8859-1') | |
340 | s2 = "Temps total".force_encoding('ISO-8859-1') |
|
341 | s2 = "Temps total".force_encoding('ISO-8859-1') | |
341 | assert_equal s1, lines.first |
|
342 | assert_equal s1, lines.first | |
342 | # Total row |
|
343 | # Total row | |
343 | assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1] |
|
344 | assert_equal "#{user.firstname} #{user.lastname};7,30;7,30", lines[1] | |
344 | assert_equal "#{s2};7,30;7,30", lines[2] |
|
345 | assert_equal "#{s2};7,30;7,30", lines[2] | |
345 |
|
346 | |||
346 | str_fr = "French (Fran\xc3\xa7ais)".force_encoding('UTF-8') |
|
347 | str_fr = "French (Fran\xc3\xa7ais)".force_encoding('UTF-8') | |
347 | assert_equal str_fr, l(:general_lang_name) |
|
348 | assert_equal str_fr, l(:general_lang_name) | |
348 | assert_equal 'ISO-8859-1', l(:general_csv_encoding) |
|
349 | assert_equal 'ISO-8859-1', l(:general_csv_encoding) | |
349 | assert_equal ';', l(:general_csv_separator) |
|
350 | assert_equal ';', l(:general_csv_separator) | |
350 | assert_equal ',', l(:general_csv_decimal_separator) |
|
351 | assert_equal ',', l(:general_csv_decimal_separator) | |
351 | end |
|
352 | end | |
352 | end |
|
353 | end | |
353 | end |
|
354 | end |
General Comments 0
You need to be logged in to leave comments.
Login now