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