##// END OF EJS Templates
Fixed that activities option tags on the time entry bulk edit form are escaped....
Jean-Philippe Lang -
r9460:ee8dcab9db0a
parent child
Show More
@@ -1,50 +1,50
1 <h2><%= l(:label_bulk_edit_selected_time_entries) %></h2>
1 <h2><%= l(:label_bulk_edit_selected_time_entries) %></h2>
2
2
3 <ul>
3 <ul>
4 <%= @time_entries.collect {|i| content_tag('li',
4 <%= @time_entries.collect {|i| content_tag('li',
5 link_to(h("#{i.spent_on.strftime("%Y-%m-%d")} - #{i.project}: #{l(:label_f_hour_plural, :value => i.hours)}"),
5 link_to(h("#{i.spent_on.strftime("%Y-%m-%d")} - #{i.project}: #{l(:label_f_hour_plural, :value => i.hours)}"),
6 { :action => 'edit', :id => i })
6 { :action => 'edit', :id => i })
7 )}.join("\n").html_safe %>
7 )}.join("\n").html_safe %>
8 </ul>
8 </ul>
9
9
10 <%= form_tag(:action => 'bulk_update') do %>
10 <%= form_tag(:action => 'bulk_update') do %>
11 <%= @time_entries.collect {|i| hidden_field_tag('ids[]', i.id)}.join.html_safe %>
11 <%= @time_entries.collect {|i| hidden_field_tag('ids[]', i.id)}.join.html_safe %>
12 <div class="box tabular">
12 <div class="box tabular">
13 <div>
13 <div>
14 <p>
14 <p>
15 <label><%= l(:field_issue) %></label>
15 <label><%= l(:field_issue) %></label>
16 <%= text_field :time_entry, :issue_id, :size => 6 %>
16 <%= text_field :time_entry, :issue_id, :size => 6 %>
17 </p>
17 </p>
18
18
19 <p>
19 <p>
20 <label><%= l(:field_spent_on) %></label>
20 <label><%= l(:field_spent_on) %></label>
21 <%= text_field :time_entry, :spent_on, :size => 10 %><%= calendar_for('time_entry_spent_on') %>
21 <%= text_field :time_entry, :spent_on, :size => 10 %><%= calendar_for('time_entry_spent_on') %>
22 </p>
22 </p>
23
23
24 <p>
24 <p>
25 <label><%= l(:field_hours) %></label>
25 <label><%= l(:field_hours) %></label>
26 <%= text_field :time_entry, :hours, :size => 6 %>
26 <%= text_field :time_entry, :hours, :size => 6 %>
27 </p>
27 </p>
28
28
29 <% if @available_activities.any? %>
29 <% if @available_activities.any? %>
30 <p>
30 <p>
31 <label><%= l(:field_activity) %></label>
31 <label><%= l(:field_activity) %></label>
32 <%= select_tag('time_entry[activity_id]', "<option value=\"\">#{l(:label_no_change_option)}</option>" + options_from_collection_for_select(@available_activities, :id, :name)) %>
32 <%= select_tag('time_entry[activity_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_activities, :id, :name)) %>
33 </p>
33 </p>
34 <% end %>
34 <% end %>
35
35
36 <p>
36 <p>
37 <label><%= l(:field_comments) %></label>
37 <label><%= l(:field_comments) %></label>
38 <%= text_field(:time_entry, :comments, :size => 100) %>
38 <%= text_field(:time_entry, :comments, :size => 100) %>
39 </p>
39 </p>
40
40
41 <% @custom_fields.each do |custom_field| %>
41 <% @custom_fields.each do |custom_field| %>
42 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @projects) %></p>
42 <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @projects) %></p>
43 <% end %>
43 <% end %>
44
44
45 <%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %>
45 <%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %>
46 </div>
46 </div>
47 </div>
47 </div>
48
48
49 <p><%= submit_tag l(:button_submit) %></p>
49 <p><%= submit_tag l(:button_submit) %></p>
50 <% end %>
50 <% end %>
@@ -1,742 +1,748
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # Redmine - project management software
2 # Redmine - project management software
3 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # Copyright (C) 2006-2012 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 require 'timelog_controller'
20 require 'timelog_controller'
21
21
22 # Re-raise errors caught by the controller.
22 # Re-raise errors caught by the controller.
23 class TimelogController; def rescue_action(e) raise e end; end
23 class TimelogController; def rescue_action(e) raise e end; end
24
24
25 class TimelogControllerTest < ActionController::TestCase
25 class TimelogControllerTest < ActionController::TestCase
26 fixtures :projects, :enabled_modules, :roles, :members,
26 fixtures :projects, :enabled_modules, :roles, :members,
27 :member_roles, :issues, :time_entries, :users,
27 :member_roles, :issues, :time_entries, :users,
28 :trackers, :enumerations, :issue_statuses,
28 :trackers, :enumerations, :issue_statuses,
29 :custom_fields, :custom_values
29 :custom_fields, :custom_values
30
30
31 include Redmine::I18n
31 include Redmine::I18n
32
32
33 def setup
33 def setup
34 @controller = TimelogController.new
34 @controller = TimelogController.new
35 @request = ActionController::TestRequest.new
35 @request = ActionController::TestRequest.new
36 @response = ActionController::TestResponse.new
36 @response = ActionController::TestResponse.new
37 end
37 end
38
38
39 def test_get_new
39 def test_get_new
40 @request.session[:user_id] = 3
40 @request.session[:user_id] = 3
41 get :new, :project_id => 1
41 get :new, :project_id => 1
42 assert_response :success
42 assert_response :success
43 assert_template 'new'
43 assert_template 'new'
44 # Default activity selected
44 # Default activity selected
45 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
45 assert_tag :tag => 'option', :attributes => { :selected => 'selected' },
46 :content => 'Development'
46 :content => 'Development'
47 end
47 end
48
48
49 def test_get_new_should_only_show_active_time_entry_activities
49 def test_get_new_should_only_show_active_time_entry_activities
50 @request.session[:user_id] = 3
50 @request.session[:user_id] = 3
51 get :new, :project_id => 1
51 get :new, :project_id => 1
52 assert_response :success
52 assert_response :success
53 assert_template 'new'
53 assert_template 'new'
54 assert_no_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
54 assert_no_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
55 assert_no_tag 'option', :content => 'Inactive Activity'
55 assert_no_tag 'option', :content => 'Inactive Activity'
56 end
56 end
57
57
58 def test_new_without_project
58 def test_new_without_project
59 @request.session[:user_id] = 3
59 @request.session[:user_id] = 3
60 get :new
60 get :new
61 assert_response :success
61 assert_response :success
62 assert_template 'new'
62 assert_template 'new'
63 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
63 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'}
64 end
64 end
65
65
66 def test_new_without_project_should_deny_without_permission
66 def test_new_without_project_should_deny_without_permission
67 Role.all.each {|role| role.remove_permission! :log_time}
67 Role.all.each {|role| role.remove_permission! :log_time}
68 @request.session[:user_id] = 3
68 @request.session[:user_id] = 3
69
69
70 get :new
70 get :new
71 assert_response 403
71 assert_response 403
72 end
72 end
73
73
74 def test_get_edit_existing_time
74 def test_get_edit_existing_time
75 @request.session[:user_id] = 2
75 @request.session[:user_id] = 2
76 get :edit, :id => 2, :project_id => nil
76 get :edit, :id => 2, :project_id => nil
77 assert_response :success
77 assert_response :success
78 assert_template 'edit'
78 assert_template 'edit'
79 # Default activity selected
79 # Default activity selected
80 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
80 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
81 end
81 end
82
82
83 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
83 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
84 te = TimeEntry.find(1)
84 te = TimeEntry.find(1)
85 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
85 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
86 te.save!
86 te.save!
87
87
88 @request.session[:user_id] = 1
88 @request.session[:user_id] = 1
89 get :edit, :project_id => 1, :id => 1
89 get :edit, :project_id => 1, :id => 1
90 assert_response :success
90 assert_response :success
91 assert_template 'edit'
91 assert_template 'edit'
92 # Blank option since nothing is pre-selected
92 # Blank option since nothing is pre-selected
93 assert_tag :tag => 'option', :content => '--- Please select ---'
93 assert_tag :tag => 'option', :content => '--- Please select ---'
94 end
94 end
95
95
96 def test_post_create
96 def test_post_create
97 # TODO: should POST to issues’ time log instead of project. change form
97 # TODO: should POST to issues’ time log instead of project. change form
98 # and routing
98 # and routing
99 @request.session[:user_id] = 3
99 @request.session[:user_id] = 3
100 post :create, :project_id => 1,
100 post :create, :project_id => 1,
101 :time_entry => {:comments => 'Some work on TimelogControllerTest',
101 :time_entry => {:comments => 'Some work on TimelogControllerTest',
102 # Not the default activity
102 # Not the default activity
103 :activity_id => '11',
103 :activity_id => '11',
104 :spent_on => '2008-03-14',
104 :spent_on => '2008-03-14',
105 :issue_id => '1',
105 :issue_id => '1',
106 :hours => '7.3'}
106 :hours => '7.3'}
107 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
107 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
108
108
109 i = Issue.find(1)
109 i = Issue.find(1)
110 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
110 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
111 assert_not_nil t
111 assert_not_nil t
112 assert_equal 11, t.activity_id
112 assert_equal 11, t.activity_id
113 assert_equal 7.3, t.hours
113 assert_equal 7.3, t.hours
114 assert_equal 3, t.user_id
114 assert_equal 3, t.user_id
115 assert_equal i, t.issue
115 assert_equal i, t.issue
116 assert_equal i.project, t.project
116 assert_equal i.project, t.project
117 end
117 end
118
118
119 def test_post_create_with_blank_issue
119 def test_post_create_with_blank_issue
120 # TODO: should POST to issues’ time log instead of project. change form
120 # TODO: should POST to issues’ time log instead of project. change form
121 # and routing
121 # and routing
122 @request.session[:user_id] = 3
122 @request.session[:user_id] = 3
123 post :create, :project_id => 1,
123 post :create, :project_id => 1,
124 :time_entry => {:comments => 'Some work on TimelogControllerTest',
124 :time_entry => {:comments => 'Some work on TimelogControllerTest',
125 # Not the default activity
125 # Not the default activity
126 :activity_id => '11',
126 :activity_id => '11',
127 :issue_id => '',
127 :issue_id => '',
128 :spent_on => '2008-03-14',
128 :spent_on => '2008-03-14',
129 :hours => '7.3'}
129 :hours => '7.3'}
130 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
130 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
131
131
132 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
132 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
133 assert_not_nil t
133 assert_not_nil t
134 assert_equal 11, t.activity_id
134 assert_equal 11, t.activity_id
135 assert_equal 7.3, t.hours
135 assert_equal 7.3, t.hours
136 assert_equal 3, t.user_id
136 assert_equal 3, t.user_id
137 end
137 end
138
138
139 def test_create_and_continue
139 def test_create_and_continue
140 @request.session[:user_id] = 2
140 @request.session[:user_id] = 2
141 post :create, :project_id => 1,
141 post :create, :project_id => 1,
142 :time_entry => {:activity_id => '11',
142 :time_entry => {:activity_id => '11',
143 :issue_id => '',
143 :issue_id => '',
144 :spent_on => '2008-03-14',
144 :spent_on => '2008-03-14',
145 :hours => '7.3'},
145 :hours => '7.3'},
146 :continue => '1'
146 :continue => '1'
147 assert_redirected_to '/projects/ecookbook/time_entries/new'
147 assert_redirected_to '/projects/ecookbook/time_entries/new'
148 end
148 end
149
149
150 def test_create_and_continue_with_issue_id
150 def test_create_and_continue_with_issue_id
151 @request.session[:user_id] = 2
151 @request.session[:user_id] = 2
152 post :create, :project_id => 1,
152 post :create, :project_id => 1,
153 :time_entry => {:activity_id => '11',
153 :time_entry => {:activity_id => '11',
154 :issue_id => '1',
154 :issue_id => '1',
155 :spent_on => '2008-03-14',
155 :spent_on => '2008-03-14',
156 :hours => '7.3'},
156 :hours => '7.3'},
157 :continue => '1'
157 :continue => '1'
158 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
158 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new'
159 end
159 end
160
160
161 def test_create_and_continue_without_project
161 def test_create_and_continue_without_project
162 @request.session[:user_id] = 2
162 @request.session[:user_id] = 2
163 post :create, :time_entry => {:project_id => '1',
163 post :create, :time_entry => {:project_id => '1',
164 :activity_id => '11',
164 :activity_id => '11',
165 :issue_id => '',
165 :issue_id => '',
166 :spent_on => '2008-03-14',
166 :spent_on => '2008-03-14',
167 :hours => '7.3'},
167 :hours => '7.3'},
168 :continue => '1'
168 :continue => '1'
169
169
170 assert_redirected_to '/time_entries/new'
170 assert_redirected_to '/time_entries/new'
171 end
171 end
172
172
173 def test_create_without_log_time_permission_should_be_denied
173 def test_create_without_log_time_permission_should_be_denied
174 @request.session[:user_id] = 2
174 @request.session[:user_id] = 2
175 Role.find_by_name('Manager').remove_permission! :log_time
175 Role.find_by_name('Manager').remove_permission! :log_time
176 post :create, :project_id => 1,
176 post :create, :project_id => 1,
177 :time_entry => {:activity_id => '11',
177 :time_entry => {:activity_id => '11',
178 :issue_id => '',
178 :issue_id => '',
179 :spent_on => '2008-03-14',
179 :spent_on => '2008-03-14',
180 :hours => '7.3'}
180 :hours => '7.3'}
181
181
182 assert_response 403
182 assert_response 403
183 end
183 end
184
184
185 def test_create_with_failure
185 def test_create_with_failure
186 @request.session[:user_id] = 2
186 @request.session[:user_id] = 2
187 post :create, :project_id => 1,
187 post :create, :project_id => 1,
188 :time_entry => {:activity_id => '',
188 :time_entry => {:activity_id => '',
189 :issue_id => '',
189 :issue_id => '',
190 :spent_on => '2008-03-14',
190 :spent_on => '2008-03-14',
191 :hours => '7.3'}
191 :hours => '7.3'}
192
192
193 assert_response :success
193 assert_response :success
194 assert_template 'new'
194 assert_template 'new'
195 end
195 end
196
196
197 def test_create_without_project
197 def test_create_without_project
198 @request.session[:user_id] = 2
198 @request.session[:user_id] = 2
199 assert_difference 'TimeEntry.count' do
199 assert_difference 'TimeEntry.count' do
200 post :create, :time_entry => {:project_id => '1',
200 post :create, :time_entry => {:project_id => '1',
201 :activity_id => '11',
201 :activity_id => '11',
202 :issue_id => '',
202 :issue_id => '',
203 :spent_on => '2008-03-14',
203 :spent_on => '2008-03-14',
204 :hours => '7.3'}
204 :hours => '7.3'}
205 end
205 end
206
206
207 assert_redirected_to '/projects/ecookbook/time_entries'
207 assert_redirected_to '/projects/ecookbook/time_entries'
208 time_entry = TimeEntry.first(:order => 'id DESC')
208 time_entry = TimeEntry.first(:order => 'id DESC')
209 assert_equal 1, time_entry.project_id
209 assert_equal 1, time_entry.project_id
210 end
210 end
211
211
212 def test_create_without_project_should_fail_with_issue_not_inside_project
212 def test_create_without_project_should_fail_with_issue_not_inside_project
213 @request.session[:user_id] = 2
213 @request.session[:user_id] = 2
214 assert_no_difference 'TimeEntry.count' do
214 assert_no_difference 'TimeEntry.count' do
215 post :create, :time_entry => {:project_id => '1',
215 post :create, :time_entry => {:project_id => '1',
216 :activity_id => '11',
216 :activity_id => '11',
217 :issue_id => '5',
217 :issue_id => '5',
218 :spent_on => '2008-03-14',
218 :spent_on => '2008-03-14',
219 :hours => '7.3'}
219 :hours => '7.3'}
220 end
220 end
221
221
222 assert_response :success
222 assert_response :success
223 assert assigns(:time_entry).errors[:issue_id].present?
223 assert assigns(:time_entry).errors[:issue_id].present?
224 end
224 end
225
225
226 def test_create_without_project_should_deny_without_permission
226 def test_create_without_project_should_deny_without_permission
227 @request.session[:user_id] = 2
227 @request.session[:user_id] = 2
228 Project.find(3).disable_module!(:time_tracking)
228 Project.find(3).disable_module!(:time_tracking)
229
229
230 assert_no_difference 'TimeEntry.count' do
230 assert_no_difference 'TimeEntry.count' do
231 post :create, :time_entry => {:project_id => '3',
231 post :create, :time_entry => {:project_id => '3',
232 :activity_id => '11',
232 :activity_id => '11',
233 :issue_id => '',
233 :issue_id => '',
234 :spent_on => '2008-03-14',
234 :spent_on => '2008-03-14',
235 :hours => '7.3'}
235 :hours => '7.3'}
236 end
236 end
237
237
238 assert_response 403
238 assert_response 403
239 end
239 end
240
240
241 def test_create_without_project_with_failure
241 def test_create_without_project_with_failure
242 @request.session[:user_id] = 2
242 @request.session[:user_id] = 2
243 assert_no_difference 'TimeEntry.count' do
243 assert_no_difference 'TimeEntry.count' do
244 post :create, :time_entry => {:project_id => '1',
244 post :create, :time_entry => {:project_id => '1',
245 :activity_id => '11',
245 :activity_id => '11',
246 :issue_id => '',
246 :issue_id => '',
247 :spent_on => '2008-03-14',
247 :spent_on => '2008-03-14',
248 :hours => ''}
248 :hours => ''}
249 end
249 end
250
250
251 assert_response :success
251 assert_response :success
252 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
252 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
253 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
253 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
254 end
254 end
255
255
256 def test_update
256 def test_update
257 entry = TimeEntry.find(1)
257 entry = TimeEntry.find(1)
258 assert_equal 1, entry.issue_id
258 assert_equal 1, entry.issue_id
259 assert_equal 2, entry.user_id
259 assert_equal 2, entry.user_id
260
260
261 @request.session[:user_id] = 1
261 @request.session[:user_id] = 1
262 put :update, :id => 1,
262 put :update, :id => 1,
263 :time_entry => {:issue_id => '2',
263 :time_entry => {:issue_id => '2',
264 :hours => '8'}
264 :hours => '8'}
265 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
265 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
266 entry.reload
266 entry.reload
267
267
268 assert_equal 8, entry.hours
268 assert_equal 8, entry.hours
269 assert_equal 2, entry.issue_id
269 assert_equal 2, entry.issue_id
270 assert_equal 2, entry.user_id
270 assert_equal 2, entry.user_id
271 end
271 end
272
272
273 def test_get_bulk_edit
273 def test_get_bulk_edit
274 @request.session[:user_id] = 2
274 @request.session[:user_id] = 2
275 get :bulk_edit, :ids => [1, 2]
275 get :bulk_edit, :ids => [1, 2]
276 assert_response :success
276 assert_response :success
277 assert_template 'bulk_edit'
277 assert_template 'bulk_edit'
278
278
279 # System wide custom field
279 # System wide custom field
280 assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'}
280 assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'}
281
282 # Activities
283 assert_select 'select[name=?]', 'time_entry[activity_id]' do
284 assert_select 'option[value=]', :text => '(No change)'
285 assert_select 'option[value=9]', :text => 'Design'
286 end
281 end
287 end
282
288
283 def test_get_bulk_edit_on_different_projects
289 def test_get_bulk_edit_on_different_projects
284 @request.session[:user_id] = 2
290 @request.session[:user_id] = 2
285 get :bulk_edit, :ids => [1, 2, 6]
291 get :bulk_edit, :ids => [1, 2, 6]
286 assert_response :success
292 assert_response :success
287 assert_template 'bulk_edit'
293 assert_template 'bulk_edit'
288 end
294 end
289
295
290 def test_bulk_update
296 def test_bulk_update
291 @request.session[:user_id] = 2
297 @request.session[:user_id] = 2
292 # update time entry activity
298 # update time entry activity
293 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
299 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
294
300
295 assert_response 302
301 assert_response 302
296 # check that the issues were updated
302 # check that the issues were updated
297 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
303 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
298 end
304 end
299
305
300 def test_bulk_update_with_failure
306 def test_bulk_update_with_failure
301 @request.session[:user_id] = 2
307 @request.session[:user_id] = 2
302 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
308 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
303
309
304 assert_response 302
310 assert_response 302
305 assert_match /Failed to save 2 time entrie/, flash[:error]
311 assert_match /Failed to save 2 time entrie/, flash[:error]
306 end
312 end
307
313
308 def test_bulk_update_on_different_projects
314 def test_bulk_update_on_different_projects
309 @request.session[:user_id] = 2
315 @request.session[:user_id] = 2
310 # makes user a manager on the other project
316 # makes user a manager on the other project
311 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
317 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
312
318
313 # update time entry activity
319 # update time entry activity
314 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
320 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
315
321
316 assert_response 302
322 assert_response 302
317 # check that the issues were updated
323 # check that the issues were updated
318 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
324 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
319 end
325 end
320
326
321 def test_bulk_update_on_different_projects_without_rights
327 def test_bulk_update_on_different_projects_without_rights
322 @request.session[:user_id] = 3
328 @request.session[:user_id] = 3
323 user = User.find(3)
329 user = User.find(3)
324 action = { :controller => "timelog", :action => "bulk_update" }
330 action = { :controller => "timelog", :action => "bulk_update" }
325 assert user.allowed_to?(action, TimeEntry.find(1).project)
331 assert user.allowed_to?(action, TimeEntry.find(1).project)
326 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
332 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
327 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
333 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
328 assert_response 403
334 assert_response 403
329 end
335 end
330
336
331 def test_bulk_update_custom_field
337 def test_bulk_update_custom_field
332 @request.session[:user_id] = 2
338 @request.session[:user_id] = 2
333 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
339 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
334
340
335 assert_response 302
341 assert_response 302
336 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
342 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
337 end
343 end
338
344
339 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
345 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
340 @request.session[:user_id] = 2
346 @request.session[:user_id] = 2
341 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
347 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
342
348
343 assert_response :redirect
349 assert_response :redirect
344 assert_redirected_to '/time_entries'
350 assert_redirected_to '/time_entries'
345 end
351 end
346
352
347 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
353 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
348 @request.session[:user_id] = 2
354 @request.session[:user_id] = 2
349 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
355 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
350
356
351 assert_response :redirect
357 assert_response :redirect
352 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
358 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
353 end
359 end
354
360
355 def test_post_bulk_update_without_edit_permission_should_be_denied
361 def test_post_bulk_update_without_edit_permission_should_be_denied
356 @request.session[:user_id] = 2
362 @request.session[:user_id] = 2
357 Role.find_by_name('Manager').remove_permission! :edit_time_entries
363 Role.find_by_name('Manager').remove_permission! :edit_time_entries
358 post :bulk_update, :ids => [1,2]
364 post :bulk_update, :ids => [1,2]
359
365
360 assert_response 403
366 assert_response 403
361 end
367 end
362
368
363 def test_destroy
369 def test_destroy
364 @request.session[:user_id] = 2
370 @request.session[:user_id] = 2
365 delete :destroy, :id => 1
371 delete :destroy, :id => 1
366 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
372 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
367 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
373 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
368 assert_nil TimeEntry.find_by_id(1)
374 assert_nil TimeEntry.find_by_id(1)
369 end
375 end
370
376
371 def test_destroy_should_fail
377 def test_destroy_should_fail
372 # simulate that this fails (e.g. due to a plugin), see #5700
378 # simulate that this fails (e.g. due to a plugin), see #5700
373 TimeEntry.any_instance.expects(:destroy).returns(false)
379 TimeEntry.any_instance.expects(:destroy).returns(false)
374
380
375 @request.session[:user_id] = 2
381 @request.session[:user_id] = 2
376 delete :destroy, :id => 1
382 delete :destroy, :id => 1
377 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
383 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
378 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
384 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
379 assert_not_nil TimeEntry.find_by_id(1)
385 assert_not_nil TimeEntry.find_by_id(1)
380 end
386 end
381
387
382 def test_index_all_projects
388 def test_index_all_projects
383 get :index
389 get :index
384 assert_response :success
390 assert_response :success
385 assert_template 'index'
391 assert_template 'index'
386 assert_not_nil assigns(:total_hours)
392 assert_not_nil assigns(:total_hours)
387 assert_equal "162.90", "%.2f" % assigns(:total_hours)
393 assert_equal "162.90", "%.2f" % assigns(:total_hours)
388 assert_tag :form,
394 assert_tag :form,
389 :attributes => {:action => "/time_entries", :id => 'query_form'}
395 :attributes => {:action => "/time_entries", :id => 'query_form'}
390 end
396 end
391
397
392 def test_index_all_projects_should_show_log_time_link
398 def test_index_all_projects_should_show_log_time_link
393 @request.session[:user_id] = 2
399 @request.session[:user_id] = 2
394 get :index
400 get :index
395 assert_response :success
401 assert_response :success
396 assert_template 'index'
402 assert_template 'index'
397 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
403 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
398 end
404 end
399
405
400 def test_index_at_project_level
406 def test_index_at_project_level
401 get :index, :project_id => 'ecookbook'
407 get :index, :project_id => 'ecookbook'
402 assert_response :success
408 assert_response :success
403 assert_template 'index'
409 assert_template 'index'
404 assert_not_nil assigns(:entries)
410 assert_not_nil assigns(:entries)
405 assert_equal 4, assigns(:entries).size
411 assert_equal 4, assigns(:entries).size
406 # project and subproject
412 # project and subproject
407 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
413 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
408 assert_not_nil assigns(:total_hours)
414 assert_not_nil assigns(:total_hours)
409 assert_equal "162.90", "%.2f" % assigns(:total_hours)
415 assert_equal "162.90", "%.2f" % assigns(:total_hours)
410 # display all time by default
416 # display all time by default
411 assert_nil assigns(:from)
417 assert_nil assigns(:from)
412 assert_nil assigns(:to)
418 assert_nil assigns(:to)
413 assert_tag :form,
419 assert_tag :form,
414 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
420 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
415 end
421 end
416
422
417 def test_index_at_project_level_with_date_range
423 def test_index_at_project_level_with_date_range
418 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
424 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
419 assert_response :success
425 assert_response :success
420 assert_template 'index'
426 assert_template 'index'
421 assert_not_nil assigns(:entries)
427 assert_not_nil assigns(:entries)
422 assert_equal 3, assigns(:entries).size
428 assert_equal 3, assigns(:entries).size
423 assert_not_nil assigns(:total_hours)
429 assert_not_nil assigns(:total_hours)
424 assert_equal "12.90", "%.2f" % assigns(:total_hours)
430 assert_equal "12.90", "%.2f" % assigns(:total_hours)
425 assert_equal '2007-03-20'.to_date, assigns(:from)
431 assert_equal '2007-03-20'.to_date, assigns(:from)
426 assert_equal '2007-04-30'.to_date, assigns(:to)
432 assert_equal '2007-04-30'.to_date, assigns(:to)
427 assert_tag :form,
433 assert_tag :form,
428 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
434 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
429 end
435 end
430
436
431 def test_index_at_project_level_with_period
437 def test_index_at_project_level_with_period
432 get :index, :project_id => 'ecookbook', :period => '7_days'
438 get :index, :project_id => 'ecookbook', :period => '7_days'
433 assert_response :success
439 assert_response :success
434 assert_template 'index'
440 assert_template 'index'
435 assert_not_nil assigns(:entries)
441 assert_not_nil assigns(:entries)
436 assert_not_nil assigns(:total_hours)
442 assert_not_nil assigns(:total_hours)
437 assert_equal Date.today - 7, assigns(:from)
443 assert_equal Date.today - 7, assigns(:from)
438 assert_equal Date.today, assigns(:to)
444 assert_equal Date.today, assigns(:to)
439 assert_tag :form,
445 assert_tag :form,
440 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
446 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
441 end
447 end
442
448
443 def test_index_one_day
449 def test_index_one_day
444 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23"
450 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23"
445 assert_response :success
451 assert_response :success
446 assert_template 'index'
452 assert_template 'index'
447 assert_not_nil assigns(:total_hours)
453 assert_not_nil assigns(:total_hours)
448 assert_equal "4.25", "%.2f" % assigns(:total_hours)
454 assert_equal "4.25", "%.2f" % assigns(:total_hours)
449 assert_tag :form,
455 assert_tag :form,
450 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
456 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
451 end
457 end
452
458
453 def test_index_from_a_date
459 def test_index_from_a_date
454 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => ""
460 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => ""
455 assert_equal '2007-03-23'.to_date, assigns(:from)
461 assert_equal '2007-03-23'.to_date, assigns(:from)
456 assert_nil assigns(:to)
462 assert_nil assigns(:to)
457 end
463 end
458
464
459 def test_index_to_a_date
465 def test_index_to_a_date
460 get :index, :project_id => 'ecookbook', :from => "", :to => "2007-03-23"
466 get :index, :project_id => 'ecookbook', :from => "", :to => "2007-03-23"
461 assert_nil assigns(:from)
467 assert_nil assigns(:from)
462 assert_equal '2007-03-23'.to_date, assigns(:to)
468 assert_equal '2007-03-23'.to_date, assigns(:to)
463 end
469 end
464
470
465 def test_index_today
471 def test_index_today
466 Date.stubs(:today).returns('2011-12-15'.to_date)
472 Date.stubs(:today).returns('2011-12-15'.to_date)
467 get :index, :period => 'today'
473 get :index, :period => 'today'
468 assert_equal '2011-12-15'.to_date, assigns(:from)
474 assert_equal '2011-12-15'.to_date, assigns(:from)
469 assert_equal '2011-12-15'.to_date, assigns(:to)
475 assert_equal '2011-12-15'.to_date, assigns(:to)
470 end
476 end
471
477
472 def test_index_yesterday
478 def test_index_yesterday
473 Date.stubs(:today).returns('2011-12-15'.to_date)
479 Date.stubs(:today).returns('2011-12-15'.to_date)
474 get :index, :period => 'yesterday'
480 get :index, :period => 'yesterday'
475 assert_equal '2011-12-14'.to_date, assigns(:from)
481 assert_equal '2011-12-14'.to_date, assigns(:from)
476 assert_equal '2011-12-14'.to_date, assigns(:to)
482 assert_equal '2011-12-14'.to_date, assigns(:to)
477 end
483 end
478
484
479 def test_index_current_week
485 def test_index_current_week
480 Date.stubs(:today).returns('2011-12-15'.to_date)
486 Date.stubs(:today).returns('2011-12-15'.to_date)
481 get :index, :period => 'current_week'
487 get :index, :period => 'current_week'
482 assert_equal '2011-12-12'.to_date, assigns(:from)
488 assert_equal '2011-12-12'.to_date, assigns(:from)
483 assert_equal '2011-12-18'.to_date, assigns(:to)
489 assert_equal '2011-12-18'.to_date, assigns(:to)
484 end
490 end
485
491
486 def test_index_last_week
492 def test_index_last_week
487 Date.stubs(:today).returns('2011-12-15'.to_date)
493 Date.stubs(:today).returns('2011-12-15'.to_date)
488 get :index, :period => 'current_week'
494 get :index, :period => 'current_week'
489 assert_equal '2011-12-05'.to_date, assigns(:from)
495 assert_equal '2011-12-05'.to_date, assigns(:from)
490 assert_equal '2011-12-11'.to_date, assigns(:to)
496 assert_equal '2011-12-11'.to_date, assigns(:to)
491 end
497 end
492
498
493 def test_index_last_week
499 def test_index_last_week
494 Date.stubs(:today).returns('2011-12-15'.to_date)
500 Date.stubs(:today).returns('2011-12-15'.to_date)
495 get :index, :period => 'last_week'
501 get :index, :period => 'last_week'
496 assert_equal '2011-12-05'.to_date, assigns(:from)
502 assert_equal '2011-12-05'.to_date, assigns(:from)
497 assert_equal '2011-12-11'.to_date, assigns(:to)
503 assert_equal '2011-12-11'.to_date, assigns(:to)
498 end
504 end
499
505
500 def test_index_7_days
506 def test_index_7_days
501 Date.stubs(:today).returns('2011-12-15'.to_date)
507 Date.stubs(:today).returns('2011-12-15'.to_date)
502 get :index, :period => '7_days'
508 get :index, :period => '7_days'
503 assert_equal '2011-12-08'.to_date, assigns(:from)
509 assert_equal '2011-12-08'.to_date, assigns(:from)
504 assert_equal '2011-12-15'.to_date, assigns(:to)
510 assert_equal '2011-12-15'.to_date, assigns(:to)
505 end
511 end
506
512
507 def test_index_current_month
513 def test_index_current_month
508 Date.stubs(:today).returns('2011-12-15'.to_date)
514 Date.stubs(:today).returns('2011-12-15'.to_date)
509 get :index, :period => 'current_month'
515 get :index, :period => 'current_month'
510 assert_equal '2011-12-01'.to_date, assigns(:from)
516 assert_equal '2011-12-01'.to_date, assigns(:from)
511 assert_equal '2011-12-31'.to_date, assigns(:to)
517 assert_equal '2011-12-31'.to_date, assigns(:to)
512 end
518 end
513
519
514 def test_index_last_month
520 def test_index_last_month
515 Date.stubs(:today).returns('2011-12-15'.to_date)
521 Date.stubs(:today).returns('2011-12-15'.to_date)
516 get :index, :period => 'last_month'
522 get :index, :period => 'last_month'
517 assert_equal '2011-11-01'.to_date, assigns(:from)
523 assert_equal '2011-11-01'.to_date, assigns(:from)
518 assert_equal '2011-11-30'.to_date, assigns(:to)
524 assert_equal '2011-11-30'.to_date, assigns(:to)
519 end
525 end
520
526
521 def test_index_30_days
527 def test_index_30_days
522 Date.stubs(:today).returns('2011-12-15'.to_date)
528 Date.stubs(:today).returns('2011-12-15'.to_date)
523 get :index, :period => '30_days'
529 get :index, :period => '30_days'
524 assert_equal '2011-11-15'.to_date, assigns(:from)
530 assert_equal '2011-11-15'.to_date, assigns(:from)
525 assert_equal '2011-12-15'.to_date, assigns(:to)
531 assert_equal '2011-12-15'.to_date, assigns(:to)
526 end
532 end
527
533
528 def test_index_current_year
534 def test_index_current_year
529 Date.stubs(:today).returns('2011-12-15'.to_date)
535 Date.stubs(:today).returns('2011-12-15'.to_date)
530 get :index, :period => 'current_year'
536 get :index, :period => 'current_year'
531 assert_equal '2011-01-01'.to_date, assigns(:from)
537 assert_equal '2011-01-01'.to_date, assigns(:from)
532 assert_equal '2011-12-31'.to_date, assigns(:to)
538 assert_equal '2011-12-31'.to_date, assigns(:to)
533 end
539 end
534
540
535 def test_index_at_issue_level
541 def test_index_at_issue_level
536 get :index, :issue_id => 1
542 get :index, :issue_id => 1
537 assert_response :success
543 assert_response :success
538 assert_template 'index'
544 assert_template 'index'
539 assert_not_nil assigns(:entries)
545 assert_not_nil assigns(:entries)
540 assert_equal 2, assigns(:entries).size
546 assert_equal 2, assigns(:entries).size
541 assert_not_nil assigns(:total_hours)
547 assert_not_nil assigns(:total_hours)
542 assert_equal 154.25, assigns(:total_hours)
548 assert_equal 154.25, assigns(:total_hours)
543 # display all time
549 # display all time
544 assert_nil assigns(:from)
550 assert_nil assigns(:from)
545 assert_nil assigns(:to)
551 assert_nil assigns(:to)
546 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
552 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
547 # to use /issues/:issue_id/time_entries
553 # to use /issues/:issue_id/time_entries
548 assert_tag :form,
554 assert_tag :form,
549 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
555 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
550 end
556 end
551
557
552 def test_index_atom_feed
558 def test_index_atom_feed
553 get :index, :project_id => 1, :format => 'atom'
559 get :index, :project_id => 1, :format => 'atom'
554 assert_response :success
560 assert_response :success
555 assert_equal 'application/atom+xml', @response.content_type
561 assert_equal 'application/atom+xml', @response.content_type
556 assert_not_nil assigns(:items)
562 assert_not_nil assigns(:items)
557 assert assigns(:items).first.is_a?(TimeEntry)
563 assert assigns(:items).first.is_a?(TimeEntry)
558 end
564 end
559
565
560 def test_index_all_projects_csv_export
566 def test_index_all_projects_csv_export
561 Setting.date_format = '%m/%d/%Y'
567 Setting.date_format = '%m/%d/%Y'
562 get :index, :format => 'csv'
568 get :index, :format => 'csv'
563 assert_response :success
569 assert_response :success
564 assert_equal 'text/csv; header=present', @response.content_type
570 assert_equal 'text/csv; header=present', @response.content_type
565 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
571 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
566 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
572 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
567 end
573 end
568
574
569 def test_index_csv_export
575 def test_index_csv_export
570 Setting.date_format = '%m/%d/%Y'
576 Setting.date_format = '%m/%d/%Y'
571 get :index, :project_id => 1, :format => 'csv'
577 get :index, :project_id => 1, :format => 'csv'
572 assert_response :success
578 assert_response :success
573 assert_equal 'text/csv; header=present', @response.content_type
579 assert_equal 'text/csv; header=present', @response.content_type
574 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
580 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
575 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
581 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
576 end
582 end
577
583
578 def test_index_csv_export_with_multi_custom_field
584 def test_index_csv_export_with_multi_custom_field
579 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list',
585 field = TimeEntryCustomField.create!(:name => 'Test', :field_format => 'list',
580 :multiple => true, :possible_values => ['value1', 'value2'])
586 :multiple => true, :possible_values => ['value1', 'value2'])
581 entry = TimeEntry.find(1)
587 entry = TimeEntry.find(1)
582 entry.custom_field_values = {field.id => ['value1', 'value2']}
588 entry.custom_field_values = {field.id => ['value1', 'value2']}
583 entry.save!
589 entry.save!
584
590
585 get :index, :project_id => 1, :format => 'csv'
591 get :index, :project_id => 1, :format => 'csv'
586 assert_response :success
592 assert_response :success
587 assert_include '"value1, value2"', @response.body
593 assert_include '"value1, value2"', @response.body
588 end
594 end
589
595
590 def test_csv_big_5
596 def test_csv_big_5
591 user = User.find_by_id(3)
597 user = User.find_by_id(3)
592 user.language = "zh-TW"
598 user.language = "zh-TW"
593 assert user.save
599 assert user.save
594 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
600 str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88"
595 str_big5 = "\xa4@\xa4\xeb"
601 str_big5 = "\xa4@\xa4\xeb"
596 if str_utf8.respond_to?(:force_encoding)
602 if str_utf8.respond_to?(:force_encoding)
597 str_utf8.force_encoding('UTF-8')
603 str_utf8.force_encoding('UTF-8')
598 str_big5.force_encoding('Big5')
604 str_big5.force_encoding('Big5')
599 end
605 end
600 @request.session[:user_id] = 3
606 @request.session[:user_id] = 3
601 post :create, :project_id => 1,
607 post :create, :project_id => 1,
602 :time_entry => {:comments => str_utf8,
608 :time_entry => {:comments => str_utf8,
603 # Not the default activity
609 # Not the default activity
604 :activity_id => '11',
610 :activity_id => '11',
605 :issue_id => '',
611 :issue_id => '',
606 :spent_on => '2011-11-10',
612 :spent_on => '2011-11-10',
607 :hours => '7.3'}
613 :hours => '7.3'}
608 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
614 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
609
615
610 t = TimeEntry.find_by_comments(str_utf8)
616 t = TimeEntry.find_by_comments(str_utf8)
611 assert_not_nil t
617 assert_not_nil t
612 assert_equal 11, t.activity_id
618 assert_equal 11, t.activity_id
613 assert_equal 7.3, t.hours
619 assert_equal 7.3, t.hours
614 assert_equal 3, t.user_id
620 assert_equal 3, t.user_id
615
621
616 get :index, :project_id => 1, :format => 'csv',
622 get :index, :project_id => 1, :format => 'csv',
617 :from => '2011-11-10', :to => '2011-11-10'
623 :from => '2011-11-10', :to => '2011-11-10'
618 assert_response :success
624 assert_response :success
619 assert_equal 'text/csv; header=present', @response.content_type
625 assert_equal 'text/csv; header=present', @response.content_type
620 ar = @response.body.chomp.split("\n")
626 ar = @response.body.chomp.split("\n")
621 s1 = "\xa4\xe9\xb4\xc1"
627 s1 = "\xa4\xe9\xb4\xc1"
622 if str_utf8.respond_to?(:force_encoding)
628 if str_utf8.respond_to?(:force_encoding)
623 s1.force_encoding('Big5')
629 s1.force_encoding('Big5')
624 end
630 end
625 assert ar[0].include?(s1)
631 assert ar[0].include?(s1)
626 assert ar[1].include?(str_big5)
632 assert ar[1].include?(str_big5)
627 end
633 end
628
634
629 def test_csv_cannot_convert_should_be_replaced_big_5
635 def test_csv_cannot_convert_should_be_replaced_big_5
630 user = User.find_by_id(3)
636 user = User.find_by_id(3)
631 user.language = "zh-TW"
637 user.language = "zh-TW"
632 assert user.save
638 assert user.save
633 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
639 str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85"
634 if str_utf8.respond_to?(:force_encoding)
640 if str_utf8.respond_to?(:force_encoding)
635 str_utf8.force_encoding('UTF-8')
641 str_utf8.force_encoding('UTF-8')
636 end
642 end
637 @request.session[:user_id] = 3
643 @request.session[:user_id] = 3
638 post :create, :project_id => 1,
644 post :create, :project_id => 1,
639 :time_entry => {:comments => str_utf8,
645 :time_entry => {:comments => str_utf8,
640 # Not the default activity
646 # Not the default activity
641 :activity_id => '11',
647 :activity_id => '11',
642 :issue_id => '',
648 :issue_id => '',
643 :spent_on => '2011-11-10',
649 :spent_on => '2011-11-10',
644 :hours => '7.3'}
650 :hours => '7.3'}
645 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
651 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
646
652
647 t = TimeEntry.find_by_comments(str_utf8)
653 t = TimeEntry.find_by_comments(str_utf8)
648 assert_not_nil t
654 assert_not_nil t
649 assert_equal 11, t.activity_id
655 assert_equal 11, t.activity_id
650 assert_equal 7.3, t.hours
656 assert_equal 7.3, t.hours
651 assert_equal 3, t.user_id
657 assert_equal 3, t.user_id
652
658
653 get :index, :project_id => 1, :format => 'csv',
659 get :index, :project_id => 1, :format => 'csv',
654 :from => '2011-11-10', :to => '2011-11-10'
660 :from => '2011-11-10', :to => '2011-11-10'
655 assert_response :success
661 assert_response :success
656 assert_equal 'text/csv; header=present', @response.content_type
662 assert_equal 'text/csv; header=present', @response.content_type
657 ar = @response.body.chomp.split("\n")
663 ar = @response.body.chomp.split("\n")
658 s1 = "\xa4\xe9\xb4\xc1"
664 s1 = "\xa4\xe9\xb4\xc1"
659 if str_utf8.respond_to?(:force_encoding)
665 if str_utf8.respond_to?(:force_encoding)
660 s1.force_encoding('Big5')
666 s1.force_encoding('Big5')
661 end
667 end
662 assert ar[0].include?(s1)
668 assert ar[0].include?(s1)
663 s2 = ar[1].split(",")[8]
669 s2 = ar[1].split(",")[8]
664 if s2.respond_to?(:force_encoding)
670 if s2.respond_to?(:force_encoding)
665 s3 = "\xa5H?"
671 s3 = "\xa5H?"
666 s3.force_encoding('Big5')
672 s3.force_encoding('Big5')
667 assert_equal s3, s2
673 assert_equal s3, s2
668 elsif RUBY_PLATFORM == 'java'
674 elsif RUBY_PLATFORM == 'java'
669 assert_equal "??", s2
675 assert_equal "??", s2
670 else
676 else
671 assert_equal "\xa5H???", s2
677 assert_equal "\xa5H???", s2
672 end
678 end
673 end
679 end
674
680
675 def test_csv_tw
681 def test_csv_tw
676 with_settings :default_language => "zh-TW" do
682 with_settings :default_language => "zh-TW" do
677 str1 = "test_csv_tw"
683 str1 = "test_csv_tw"
678 user = User.find_by_id(3)
684 user = User.find_by_id(3)
679 te1 = TimeEntry.create(:spent_on => '2011-11-10',
685 te1 = TimeEntry.create(:spent_on => '2011-11-10',
680 :hours => 999.9,
686 :hours => 999.9,
681 :project => Project.find(1),
687 :project => Project.find(1),
682 :user => user,
688 :user => user,
683 :activity => TimeEntryActivity.find_by_name('Design'),
689 :activity => TimeEntryActivity.find_by_name('Design'),
684 :comments => str1)
690 :comments => str1)
685 te2 = TimeEntry.find_by_comments(str1)
691 te2 = TimeEntry.find_by_comments(str1)
686 assert_not_nil te2
692 assert_not_nil te2
687 assert_equal 999.9, te2.hours
693 assert_equal 999.9, te2.hours
688 assert_equal 3, te2.user_id
694 assert_equal 3, te2.user_id
689
695
690 get :index, :project_id => 1, :format => 'csv',
696 get :index, :project_id => 1, :format => 'csv',
691 :from => '2011-11-10', :to => '2011-11-10'
697 :from => '2011-11-10', :to => '2011-11-10'
692 assert_response :success
698 assert_response :success
693 assert_equal 'text/csv; header=present', @response.content_type
699 assert_equal 'text/csv; header=present', @response.content_type
694
700
695 ar = @response.body.chomp.split("\n")
701 ar = @response.body.chomp.split("\n")
696 s2 = ar[1].split(",")[7]
702 s2 = ar[1].split(",")[7]
697 assert_equal '999.9', s2
703 assert_equal '999.9', s2
698
704
699 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
705 str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)"
700 if str_tw.respond_to?(:force_encoding)
706 if str_tw.respond_to?(:force_encoding)
701 str_tw.force_encoding('UTF-8')
707 str_tw.force_encoding('UTF-8')
702 end
708 end
703 assert_equal str_tw, l(:general_lang_name)
709 assert_equal str_tw, l(:general_lang_name)
704 assert_equal ',', l(:general_csv_separator)
710 assert_equal ',', l(:general_csv_separator)
705 assert_equal '.', l(:general_csv_decimal_separator)
711 assert_equal '.', l(:general_csv_decimal_separator)
706 end
712 end
707 end
713 end
708
714
709 def test_csv_fr
715 def test_csv_fr
710 with_settings :default_language => "fr" do
716 with_settings :default_language => "fr" do
711 str1 = "test_csv_fr"
717 str1 = "test_csv_fr"
712 user = User.find_by_id(3)
718 user = User.find_by_id(3)
713 te1 = TimeEntry.create(:spent_on => '2011-11-10',
719 te1 = TimeEntry.create(:spent_on => '2011-11-10',
714 :hours => 999.9,
720 :hours => 999.9,
715 :project => Project.find(1),
721 :project => Project.find(1),
716 :user => user,
722 :user => user,
717 :activity => TimeEntryActivity.find_by_name('Design'),
723 :activity => TimeEntryActivity.find_by_name('Design'),
718 :comments => str1)
724 :comments => str1)
719 te2 = TimeEntry.find_by_comments(str1)
725 te2 = TimeEntry.find_by_comments(str1)
720 assert_not_nil te2
726 assert_not_nil te2
721 assert_equal 999.9, te2.hours
727 assert_equal 999.9, te2.hours
722 assert_equal 3, te2.user_id
728 assert_equal 3, te2.user_id
723
729
724 get :index, :project_id => 1, :format => 'csv',
730 get :index, :project_id => 1, :format => 'csv',
725 :from => '2011-11-10', :to => '2011-11-10'
731 :from => '2011-11-10', :to => '2011-11-10'
726 assert_response :success
732 assert_response :success
727 assert_equal 'text/csv; header=present', @response.content_type
733 assert_equal 'text/csv; header=present', @response.content_type
728
734
729 ar = @response.body.chomp.split("\n")
735 ar = @response.body.chomp.split("\n")
730 s2 = ar[1].split(";")[7]
736 s2 = ar[1].split(";")[7]
731 assert_equal '999,9', s2
737 assert_equal '999,9', s2
732
738
733 str_fr = "Fran\xc3\xa7ais"
739 str_fr = "Fran\xc3\xa7ais"
734 if str_fr.respond_to?(:force_encoding)
740 if str_fr.respond_to?(:force_encoding)
735 str_fr.force_encoding('UTF-8')
741 str_fr.force_encoding('UTF-8')
736 end
742 end
737 assert_equal str_fr, l(:general_lang_name)
743 assert_equal str_fr, l(:general_lang_name)
738 assert_equal ';', l(:general_csv_separator)
744 assert_equal ';', l(:general_csv_separator)
739 assert_equal ',', l(:general_csv_decimal_separator)
745 assert_equal ',', l(:general_csv_decimal_separator)
740 end
746 end
741 end
747 end
742 end
748 end
General Comments 0
You need to be logged in to leave comments. Login now