##// END OF EJS Templates
Code cleanup, use named routes....
Jean-Philippe Lang -
r10841:ad246e81ad52
parent child
Show More

The requested changes are too big and content was truncated. Show full diff

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