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