##// END OF EJS Templates
Adds a link on "My Page" to view all my spent time (#13157)....
Jean-Philippe Lang -
r11629:6b03c741acfc
parent child
Show More
@@ -1,49 +1,52
1 <h3><%=l(:label_spent_time)%> (<%= l(:label_last_n_days, 7) %>)</h3>
1 <h3>
2 <%= link_to l(:label_spent_time), time_entries_path(:user_id => 'me') %>
3 (<%= l(:label_last_n_days, 7) %>)
4 </h3>
2 <%
5 <%
3 entries = timelog_items
6 entries = timelog_items
4 entries_by_day = entries.group_by(&:spent_on)
7 entries_by_day = entries.group_by(&:spent_on)
5 %>
8 %>
6
9
7 <div class="total-hours">
10 <div class="total-hours">
8 <p><%= l(:label_total_time) %>: <%= html_hours("%.2f" % entries.sum(&:hours).to_f) %></p>
11 <p><%= l(:label_total_time) %>: <%= html_hours("%.2f" % entries.sum(&:hours).to_f) %></p>
9 </div>
12 </div>
10
13
11 <% if entries.any? %>
14 <% if entries.any? %>
12 <table class="list time-entries">
15 <table class="list time-entries">
13 <thead><tr>
16 <thead><tr>
14 <th><%= l(:label_activity) %></th>
17 <th><%= l(:label_activity) %></th>
15 <th><%= l(:label_project) %></th>
18 <th><%= l(:label_project) %></th>
16 <th><%= l(:field_comments) %></th>
19 <th><%= l(:field_comments) %></th>
17 <th><%= l(:field_hours) %></th>
20 <th><%= l(:field_hours) %></th>
18 <th></th>
21 <th></th>
19 </tr></thead>
22 </tr></thead>
20 <tbody>
23 <tbody>
21 <% entries_by_day.keys.sort.reverse.each do |day| %>
24 <% entries_by_day.keys.sort.reverse.each do |day| %>
22 <tr class="odd">
25 <tr class="odd">
23 <td><strong><%= day == Date.today ? l(:label_today).titleize : format_date(day) %></strong></td>
26 <td><strong><%= day == Date.today ? l(:label_today).titleize : format_date(day) %></strong></td>
24 <td colspan="2"></td>
27 <td colspan="2"></td>
25 <td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td>
28 <td class="hours"><em><%= html_hours("%.2f" % entries_by_day[day].sum(&:hours).to_f) %></em></td>
26 <td></td>
29 <td></td>
27 </tr>
30 </tr>
28 <% entries_by_day[day].each do |entry| -%>
31 <% entries_by_day[day].each do |entry| -%>
29 <tr class="time-entry" style="border-bottom: 1px solid #f5f5f5;">
32 <tr class="time-entry" style="border-bottom: 1px solid #f5f5f5;">
30 <td class="activity"><%=h entry.activity %></td>
33 <td class="activity"><%=h entry.activity %></td>
31 <td class="subject"><%=h entry.project %> <%= h(' - ') + link_to_issue(entry.issue, :truncate => 50) if entry.issue %></td>
34 <td class="subject"><%=h entry.project %> <%= h(' - ') + link_to_issue(entry.issue, :truncate => 50) if entry.issue %></td>
32 <td class="comments"><%=h entry.comments %></td>
35 <td class="comments"><%=h entry.comments %></td>
33 <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
36 <td class="hours"><%= html_hours("%.2f" % entry.hours) %></td>
34 <td align="center">
37 <td align="center">
35 <% if entry.editable_by?(@user) -%>
38 <% if entry.editable_by?(@user) -%>
36 <%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => entry},
39 <%= link_to image_tag('edit.png'), {:controller => 'timelog', :action => 'edit', :id => entry},
37 :title => l(:button_edit) %>
40 :title => l(:button_edit) %>
38 <%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => entry},
41 <%= link_to image_tag('delete.png'), {:controller => 'timelog', :action => 'destroy', :id => entry},
39 :data => {:confirm => l(:text_are_you_sure)},
42 :data => {:confirm => l(:text_are_you_sure)},
40 :method => :delete,
43 :method => :delete,
41 :title => l(:button_delete) %>
44 :title => l(:button_delete) %>
42 <% end -%>
45 <% end -%>
43 </td>
46 </td>
44 </tr>
47 </tr>
45 <% end -%>
48 <% end -%>
46 <% end -%>
49 <% end -%>
47 </tbody>
50 </tbody>
48 </table>
51 </table>
49 <% end %>
52 <% end %>
@@ -1,604 +1,612
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 # Redmine - project management software
2 # Redmine - project management software
3 # Copyright (C) 2006-2013 Jean-Philippe Lang
3 # Copyright (C) 2006-2013 Jean-Philippe Lang
4 #
4 #
5 # This program is free software; you can redistribute it and/or
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
8 # of the License, or (at your option) any later version.
9 #
9 #
10 # This program is distributed in the hope that it will be useful,
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
13 # GNU General Public License for more details.
14 #
14 #
15 # You should have received a copy of the GNU General Public License
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
18
19 require File.expand_path('../../test_helper', __FILE__)
19 require File.expand_path('../../test_helper', __FILE__)
20
20
21 class TimelogControllerTest < ActionController::TestCase
21 class TimelogControllerTest < ActionController::TestCase
22 fixtures :projects, :enabled_modules, :roles, :members,
22 fixtures :projects, :enabled_modules, :roles, :members,
23 :member_roles, :issues, :time_entries, :users,
23 :member_roles, :issues, :time_entries, :users,
24 :trackers, :enumerations, :issue_statuses,
24 :trackers, :enumerations, :issue_statuses,
25 :custom_fields, :custom_values,
25 :custom_fields, :custom_values,
26 :projects_trackers, :custom_fields_trackers,
26 :projects_trackers, :custom_fields_trackers,
27 :custom_fields_projects
27 :custom_fields_projects
28
28
29 include Redmine::I18n
29 include Redmine::I18n
30
30
31 def test_new_with_project_id
31 def test_new_with_project_id
32 @request.session[:user_id] = 3
32 @request.session[:user_id] = 3
33 get :new, :project_id => 1
33 get :new, :project_id => 1
34 assert_response :success
34 assert_response :success
35 assert_template 'new'
35 assert_template 'new'
36 assert_select 'select[name=?]', 'time_entry[project_id]', 0
36 assert_select 'select[name=?]', 'time_entry[project_id]', 0
37 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
37 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
38 end
38 end
39
39
40 def test_new_with_issue_id
40 def test_new_with_issue_id
41 @request.session[:user_id] = 3
41 @request.session[:user_id] = 3
42 get :new, :issue_id => 2
42 get :new, :issue_id => 2
43 assert_response :success
43 assert_response :success
44 assert_template 'new'
44 assert_template 'new'
45 assert_select 'select[name=?]', 'time_entry[project_id]', 0
45 assert_select 'select[name=?]', 'time_entry[project_id]', 0
46 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
46 assert_select 'input[name=?][value=1][type=hidden]', 'time_entry[project_id]'
47 end
47 end
48
48
49 def test_new_without_project
49 def test_new_without_project
50 @request.session[:user_id] = 3
50 @request.session[:user_id] = 3
51 get :new
51 get :new
52 assert_response :success
52 assert_response :success
53 assert_template 'new'
53 assert_template 'new'
54 assert_select 'select[name=?]', 'time_entry[project_id]'
54 assert_select 'select[name=?]', 'time_entry[project_id]'
55 assert_select 'input[name=?]', 'time_entry[project_id]', 0
55 assert_select 'input[name=?]', 'time_entry[project_id]', 0
56 end
56 end
57
57
58 def test_new_without_project_should_prefill_the_form
58 def test_new_without_project_should_prefill_the_form
59 @request.session[:user_id] = 3
59 @request.session[:user_id] = 3
60 get :new, :time_entry => {:project_id => '1'}
60 get :new, :time_entry => {:project_id => '1'}
61 assert_response :success
61 assert_response :success
62 assert_template 'new'
62 assert_template 'new'
63 assert_select 'select[name=?]', 'time_entry[project_id]' do
63 assert_select 'select[name=?]', 'time_entry[project_id]' do
64 assert_select 'option[value=1][selected=selected]'
64 assert_select 'option[value=1][selected=selected]'
65 end
65 end
66 assert_select 'input[name=?]', 'time_entry[project_id]', 0
66 assert_select 'input[name=?]', 'time_entry[project_id]', 0
67 end
67 end
68
68
69 def test_new_without_project_should_deny_without_permission
69 def test_new_without_project_should_deny_without_permission
70 Role.all.each {|role| role.remove_permission! :log_time}
70 Role.all.each {|role| role.remove_permission! :log_time}
71 @request.session[:user_id] = 3
71 @request.session[:user_id] = 3
72
72
73 get :new
73 get :new
74 assert_response 403
74 assert_response 403
75 end
75 end
76
76
77 def test_new_should_select_default_activity
77 def test_new_should_select_default_activity
78 @request.session[:user_id] = 3
78 @request.session[:user_id] = 3
79 get :new, :project_id => 1
79 get :new, :project_id => 1
80 assert_response :success
80 assert_response :success
81 assert_select 'select[name=?]', 'time_entry[activity_id]' do
81 assert_select 'select[name=?]', 'time_entry[activity_id]' do
82 assert_select 'option[selected=selected]', :text => 'Development'
82 assert_select 'option[selected=selected]', :text => 'Development'
83 end
83 end
84 end
84 end
85
85
86 def test_new_should_only_show_active_time_entry_activities
86 def test_new_should_only_show_active_time_entry_activities
87 @request.session[:user_id] = 3
87 @request.session[:user_id] = 3
88 get :new, :project_id => 1
88 get :new, :project_id => 1
89 assert_response :success
89 assert_response :success
90 assert_no_tag 'option', :content => 'Inactive Activity'
90 assert_no_tag 'option', :content => 'Inactive Activity'
91 end
91 end
92
92
93 def test_get_edit_existing_time
93 def test_get_edit_existing_time
94 @request.session[:user_id] = 2
94 @request.session[:user_id] = 2
95 get :edit, :id => 2, :project_id => nil
95 get :edit, :id => 2, :project_id => nil
96 assert_response :success
96 assert_response :success
97 assert_template 'edit'
97 assert_template 'edit'
98 # Default activity selected
98 # Default activity selected
99 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
99 assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' }
100 end
100 end
101
101
102 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
102 def test_get_edit_with_an_existing_time_entry_with_inactive_activity
103 te = TimeEntry.find(1)
103 te = TimeEntry.find(1)
104 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
104 te.activity = TimeEntryActivity.find_by_name("Inactive Activity")
105 te.save!
105 te.save!
106
106
107 @request.session[:user_id] = 1
107 @request.session[:user_id] = 1
108 get :edit, :project_id => 1, :id => 1
108 get :edit, :project_id => 1, :id => 1
109 assert_response :success
109 assert_response :success
110 assert_template 'edit'
110 assert_template 'edit'
111 # Blank option since nothing is pre-selected
111 # Blank option since nothing is pre-selected
112 assert_tag :tag => 'option', :content => '--- Please select ---'
112 assert_tag :tag => 'option', :content => '--- Please select ---'
113 end
113 end
114
114
115 def test_post_create
115 def test_post_create
116 # TODO: should POST to issues’ time log instead of project. change form
116 # TODO: should POST to issues’ time log instead of project. change form
117 # and routing
117 # and routing
118 @request.session[:user_id] = 3
118 @request.session[:user_id] = 3
119 post :create, :project_id => 1,
119 post :create, :project_id => 1,
120 :time_entry => {:comments => 'Some work on TimelogControllerTest',
120 :time_entry => {:comments => 'Some work on TimelogControllerTest',
121 # Not the default activity
121 # Not the default activity
122 :activity_id => '11',
122 :activity_id => '11',
123 :spent_on => '2008-03-14',
123 :spent_on => '2008-03-14',
124 :issue_id => '1',
124 :issue_id => '1',
125 :hours => '7.3'}
125 :hours => '7.3'}
126 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
126 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
127
127
128 i = Issue.find(1)
128 i = Issue.find(1)
129 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
129 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
130 assert_not_nil t
130 assert_not_nil t
131 assert_equal 11, t.activity_id
131 assert_equal 11, t.activity_id
132 assert_equal 7.3, t.hours
132 assert_equal 7.3, t.hours
133 assert_equal 3, t.user_id
133 assert_equal 3, t.user_id
134 assert_equal i, t.issue
134 assert_equal i, t.issue
135 assert_equal i.project, t.project
135 assert_equal i.project, t.project
136 end
136 end
137
137
138 def test_post_create_with_blank_issue
138 def test_post_create_with_blank_issue
139 # TODO: should POST to issues’ time log instead of project. change form
139 # TODO: should POST to issues’ time log instead of project. change form
140 # and routing
140 # and routing
141 @request.session[:user_id] = 3
141 @request.session[:user_id] = 3
142 post :create, :project_id => 1,
142 post :create, :project_id => 1,
143 :time_entry => {:comments => 'Some work on TimelogControllerTest',
143 :time_entry => {:comments => 'Some work on TimelogControllerTest',
144 # Not the default activity
144 # Not the default activity
145 :activity_id => '11',
145 :activity_id => '11',
146 :issue_id => '',
146 :issue_id => '',
147 :spent_on => '2008-03-14',
147 :spent_on => '2008-03-14',
148 :hours => '7.3'}
148 :hours => '7.3'}
149 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
149 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
150
150
151 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
151 t = TimeEntry.find_by_comments('Some work on TimelogControllerTest')
152 assert_not_nil t
152 assert_not_nil t
153 assert_equal 11, t.activity_id
153 assert_equal 11, t.activity_id
154 assert_equal 7.3, t.hours
154 assert_equal 7.3, t.hours
155 assert_equal 3, t.user_id
155 assert_equal 3, t.user_id
156 end
156 end
157
157
158 def test_create_and_continue
158 def test_create_and_continue
159 @request.session[:user_id] = 2
159 @request.session[:user_id] = 2
160 post :create, :project_id => 1,
160 post :create, :project_id => 1,
161 :time_entry => {:activity_id => '11',
161 :time_entry => {:activity_id => '11',
162 :issue_id => '',
162 :issue_id => '',
163 :spent_on => '2008-03-14',
163 :spent_on => '2008-03-14',
164 :hours => '7.3'},
164 :hours => '7.3'},
165 :continue => '1'
165 :continue => '1'
166 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
166 assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D='
167 end
167 end
168
168
169 def test_create_and_continue_with_issue_id
169 def test_create_and_continue_with_issue_id
170 @request.session[:user_id] = 2
170 @request.session[:user_id] = 2
171 post :create, :project_id => 1,
171 post :create, :project_id => 1,
172 :time_entry => {:activity_id => '11',
172 :time_entry => {:activity_id => '11',
173 :issue_id => '1',
173 :issue_id => '1',
174 :spent_on => '2008-03-14',
174 :spent_on => '2008-03-14',
175 :hours => '7.3'},
175 :hours => '7.3'},
176 :continue => '1'
176 :continue => '1'
177 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
177 assert_redirected_to '/projects/ecookbook/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1'
178 end
178 end
179
179
180 def test_create_and_continue_without_project
180 def test_create_and_continue_without_project
181 @request.session[:user_id] = 2
181 @request.session[:user_id] = 2
182 post :create, :time_entry => {:project_id => '1',
182 post :create, :time_entry => {:project_id => '1',
183 :activity_id => '11',
183 :activity_id => '11',
184 :issue_id => '',
184 :issue_id => '',
185 :spent_on => '2008-03-14',
185 :spent_on => '2008-03-14',
186 :hours => '7.3'},
186 :hours => '7.3'},
187 :continue => '1'
187 :continue => '1'
188
188
189 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
189 assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1'
190 end
190 end
191
191
192 def test_create_without_log_time_permission_should_be_denied
192 def test_create_without_log_time_permission_should_be_denied
193 @request.session[:user_id] = 2
193 @request.session[:user_id] = 2
194 Role.find_by_name('Manager').remove_permission! :log_time
194 Role.find_by_name('Manager').remove_permission! :log_time
195 post :create, :project_id => 1,
195 post :create, :project_id => 1,
196 :time_entry => {:activity_id => '11',
196 :time_entry => {:activity_id => '11',
197 :issue_id => '',
197 :issue_id => '',
198 :spent_on => '2008-03-14',
198 :spent_on => '2008-03-14',
199 :hours => '7.3'}
199 :hours => '7.3'}
200
200
201 assert_response 403
201 assert_response 403
202 end
202 end
203
203
204 def test_create_with_failure
204 def test_create_with_failure
205 @request.session[:user_id] = 2
205 @request.session[:user_id] = 2
206 post :create, :project_id => 1,
206 post :create, :project_id => 1,
207 :time_entry => {:activity_id => '',
207 :time_entry => {:activity_id => '',
208 :issue_id => '',
208 :issue_id => '',
209 :spent_on => '2008-03-14',
209 :spent_on => '2008-03-14',
210 :hours => '7.3'}
210 :hours => '7.3'}
211
211
212 assert_response :success
212 assert_response :success
213 assert_template 'new'
213 assert_template 'new'
214 end
214 end
215
215
216 def test_create_without_project
216 def test_create_without_project
217 @request.session[:user_id] = 2
217 @request.session[:user_id] = 2
218 assert_difference 'TimeEntry.count' do
218 assert_difference 'TimeEntry.count' do
219 post :create, :time_entry => {:project_id => '1',
219 post :create, :time_entry => {:project_id => '1',
220 :activity_id => '11',
220 :activity_id => '11',
221 :issue_id => '',
221 :issue_id => '',
222 :spent_on => '2008-03-14',
222 :spent_on => '2008-03-14',
223 :hours => '7.3'}
223 :hours => '7.3'}
224 end
224 end
225
225
226 assert_redirected_to '/projects/ecookbook/time_entries'
226 assert_redirected_to '/projects/ecookbook/time_entries'
227 time_entry = TimeEntry.first(:order => 'id DESC')
227 time_entry = TimeEntry.first(:order => 'id DESC')
228 assert_equal 1, time_entry.project_id
228 assert_equal 1, time_entry.project_id
229 end
229 end
230
230
231 def test_create_without_project_should_fail_with_issue_not_inside_project
231 def test_create_without_project_should_fail_with_issue_not_inside_project
232 @request.session[:user_id] = 2
232 @request.session[:user_id] = 2
233 assert_no_difference 'TimeEntry.count' do
233 assert_no_difference 'TimeEntry.count' do
234 post :create, :time_entry => {:project_id => '1',
234 post :create, :time_entry => {:project_id => '1',
235 :activity_id => '11',
235 :activity_id => '11',
236 :issue_id => '5',
236 :issue_id => '5',
237 :spent_on => '2008-03-14',
237 :spent_on => '2008-03-14',
238 :hours => '7.3'}
238 :hours => '7.3'}
239 end
239 end
240
240
241 assert_response :success
241 assert_response :success
242 assert assigns(:time_entry).errors[:issue_id].present?
242 assert assigns(:time_entry).errors[:issue_id].present?
243 end
243 end
244
244
245 def test_create_without_project_should_deny_without_permission
245 def test_create_without_project_should_deny_without_permission
246 @request.session[:user_id] = 2
246 @request.session[:user_id] = 2
247 Project.find(3).disable_module!(:time_tracking)
247 Project.find(3).disable_module!(:time_tracking)
248
248
249 assert_no_difference 'TimeEntry.count' do
249 assert_no_difference 'TimeEntry.count' do
250 post :create, :time_entry => {:project_id => '3',
250 post :create, :time_entry => {:project_id => '3',
251 :activity_id => '11',
251 :activity_id => '11',
252 :issue_id => '',
252 :issue_id => '',
253 :spent_on => '2008-03-14',
253 :spent_on => '2008-03-14',
254 :hours => '7.3'}
254 :hours => '7.3'}
255 end
255 end
256
256
257 assert_response 403
257 assert_response 403
258 end
258 end
259
259
260 def test_create_without_project_with_failure
260 def test_create_without_project_with_failure
261 @request.session[:user_id] = 2
261 @request.session[:user_id] = 2
262 assert_no_difference 'TimeEntry.count' do
262 assert_no_difference 'TimeEntry.count' do
263 post :create, :time_entry => {:project_id => '1',
263 post :create, :time_entry => {:project_id => '1',
264 :activity_id => '11',
264 :activity_id => '11',
265 :issue_id => '',
265 :issue_id => '',
266 :spent_on => '2008-03-14',
266 :spent_on => '2008-03-14',
267 :hours => ''}
267 :hours => ''}
268 end
268 end
269
269
270 assert_response :success
270 assert_response :success
271 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
271 assert_tag 'select', :attributes => {:name => 'time_entry[project_id]'},
272 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
272 :child => {:tag => 'option', :attributes => {:value => '1', :selected => 'selected'}}
273 end
273 end
274
274
275 def test_update
275 def test_update
276 entry = TimeEntry.find(1)
276 entry = TimeEntry.find(1)
277 assert_equal 1, entry.issue_id
277 assert_equal 1, entry.issue_id
278 assert_equal 2, entry.user_id
278 assert_equal 2, entry.user_id
279
279
280 @request.session[:user_id] = 1
280 @request.session[:user_id] = 1
281 put :update, :id => 1,
281 put :update, :id => 1,
282 :time_entry => {:issue_id => '2',
282 :time_entry => {:issue_id => '2',
283 :hours => '8'}
283 :hours => '8'}
284 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
284 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
285 entry.reload
285 entry.reload
286
286
287 assert_equal 8, entry.hours
287 assert_equal 8, entry.hours
288 assert_equal 2, entry.issue_id
288 assert_equal 2, entry.issue_id
289 assert_equal 2, entry.user_id
289 assert_equal 2, entry.user_id
290 end
290 end
291
291
292 def test_get_bulk_edit
292 def test_get_bulk_edit
293 @request.session[:user_id] = 2
293 @request.session[:user_id] = 2
294 get :bulk_edit, :ids => [1, 2]
294 get :bulk_edit, :ids => [1, 2]
295 assert_response :success
295 assert_response :success
296 assert_template 'bulk_edit'
296 assert_template 'bulk_edit'
297
297
298 assert_select 'ul#bulk-selection' do
298 assert_select 'ul#bulk-selection' do
299 assert_select 'li', 2
299 assert_select 'li', 2
300 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
300 assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours'
301 end
301 end
302
302
303 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
303 assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do
304 # System wide custom field
304 # System wide custom field
305 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
305 assert_select 'select[name=?]', 'time_entry[custom_field_values][10]'
306
306
307 # Activities
307 # Activities
308 assert_select 'select[name=?]', 'time_entry[activity_id]' do
308 assert_select 'select[name=?]', 'time_entry[activity_id]' do
309 assert_select 'option[value=]', :text => '(No change)'
309 assert_select 'option[value=]', :text => '(No change)'
310 assert_select 'option[value=9]', :text => 'Design'
310 assert_select 'option[value=9]', :text => 'Design'
311 end
311 end
312 end
312 end
313 end
313 end
314
314
315 def test_get_bulk_edit_on_different_projects
315 def test_get_bulk_edit_on_different_projects
316 @request.session[:user_id] = 2
316 @request.session[:user_id] = 2
317 get :bulk_edit, :ids => [1, 2, 6]
317 get :bulk_edit, :ids => [1, 2, 6]
318 assert_response :success
318 assert_response :success
319 assert_template 'bulk_edit'
319 assert_template 'bulk_edit'
320 end
320 end
321
321
322 def test_bulk_update
322 def test_bulk_update
323 @request.session[:user_id] = 2
323 @request.session[:user_id] = 2
324 # update time entry activity
324 # update time entry activity
325 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
325 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
326
326
327 assert_response 302
327 assert_response 302
328 # check that the issues were updated
328 # check that the issues were updated
329 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
329 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
330 end
330 end
331
331
332 def test_bulk_update_with_failure
332 def test_bulk_update_with_failure
333 @request.session[:user_id] = 2
333 @request.session[:user_id] = 2
334 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
334 post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'}
335
335
336 assert_response 302
336 assert_response 302
337 assert_match /Failed to save 2 time entrie/, flash[:error]
337 assert_match /Failed to save 2 time entrie/, flash[:error]
338 end
338 end
339
339
340 def test_bulk_update_on_different_projects
340 def test_bulk_update_on_different_projects
341 @request.session[:user_id] = 2
341 @request.session[:user_id] = 2
342 # makes user a manager on the other project
342 # makes user a manager on the other project
343 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
343 Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1])
344
344
345 # update time entry activity
345 # update time entry activity
346 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
346 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
347
347
348 assert_response 302
348 assert_response 302
349 # check that the issues were updated
349 # check that the issues were updated
350 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
350 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
351 end
351 end
352
352
353 def test_bulk_update_on_different_projects_without_rights
353 def test_bulk_update_on_different_projects_without_rights
354 @request.session[:user_id] = 3
354 @request.session[:user_id] = 3
355 user = User.find(3)
355 user = User.find(3)
356 action = { :controller => "timelog", :action => "bulk_update" }
356 action = { :controller => "timelog", :action => "bulk_update" }
357 assert user.allowed_to?(action, TimeEntry.find(1).project)
357 assert user.allowed_to?(action, TimeEntry.find(1).project)
358 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
358 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
359 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
359 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
360 assert_response 403
360 assert_response 403
361 end
361 end
362
362
363 def test_bulk_update_custom_field
363 def test_bulk_update_custom_field
364 @request.session[:user_id] = 2
364 @request.session[:user_id] = 2
365 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
365 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
366
366
367 assert_response 302
367 assert_response 302
368 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
368 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
369 end
369 end
370
370
371 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
371 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
372 @request.session[:user_id] = 2
372 @request.session[:user_id] = 2
373 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
373 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
374
374
375 assert_response :redirect
375 assert_response :redirect
376 assert_redirected_to '/time_entries'
376 assert_redirected_to '/time_entries'
377 end
377 end
378
378
379 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
379 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
380 @request.session[:user_id] = 2
380 @request.session[:user_id] = 2
381 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
381 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
382
382
383 assert_response :redirect
383 assert_response :redirect
384 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
384 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
385 end
385 end
386
386
387 def test_post_bulk_update_without_edit_permission_should_be_denied
387 def test_post_bulk_update_without_edit_permission_should_be_denied
388 @request.session[:user_id] = 2
388 @request.session[:user_id] = 2
389 Role.find_by_name('Manager').remove_permission! :edit_time_entries
389 Role.find_by_name('Manager').remove_permission! :edit_time_entries
390 post :bulk_update, :ids => [1,2]
390 post :bulk_update, :ids => [1,2]
391
391
392 assert_response 403
392 assert_response 403
393 end
393 end
394
394
395 def test_destroy
395 def test_destroy
396 @request.session[:user_id] = 2
396 @request.session[:user_id] = 2
397 delete :destroy, :id => 1
397 delete :destroy, :id => 1
398 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
398 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
399 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
399 assert_equal I18n.t(:notice_successful_delete), flash[:notice]
400 assert_nil TimeEntry.find_by_id(1)
400 assert_nil TimeEntry.find_by_id(1)
401 end
401 end
402
402
403 def test_destroy_should_fail
403 def test_destroy_should_fail
404 # simulate that this fails (e.g. due to a plugin), see #5700
404 # simulate that this fails (e.g. due to a plugin), see #5700
405 TimeEntry.any_instance.expects(:destroy).returns(false)
405 TimeEntry.any_instance.expects(:destroy).returns(false)
406
406
407 @request.session[:user_id] = 2
407 @request.session[:user_id] = 2
408 delete :destroy, :id => 1
408 delete :destroy, :id => 1
409 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
409 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
410 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
410 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
411 assert_not_nil TimeEntry.find_by_id(1)
411 assert_not_nil TimeEntry.find_by_id(1)
412 end
412 end
413
413
414 def test_index_all_projects
414 def test_index_all_projects
415 get :index
415 get :index
416 assert_response :success
416 assert_response :success
417 assert_template 'index'
417 assert_template 'index'
418 assert_not_nil assigns(:total_hours)
418 assert_not_nil assigns(:total_hours)
419 assert_equal "162.90", "%.2f" % assigns(:total_hours)
419 assert_equal "162.90", "%.2f" % assigns(:total_hours)
420 assert_tag :form,
420 assert_tag :form,
421 :attributes => {:action => "/time_entries", :id => 'query_form'}
421 :attributes => {:action => "/time_entries", :id => 'query_form'}
422 end
422 end
423
423
424 def test_index_all_projects_should_show_log_time_link
424 def test_index_all_projects_should_show_log_time_link
425 @request.session[:user_id] = 2
425 @request.session[:user_id] = 2
426 get :index
426 get :index
427 assert_response :success
427 assert_response :success
428 assert_template 'index'
428 assert_template 'index'
429 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
429 assert_tag 'a', :attributes => {:href => '/time_entries/new'}, :content => /Log time/
430 end
430 end
431
431
432 def test_index_my_spent_time
433 @request.session[:user_id] = 2
434 get :index, :user_id => 'me'
435 assert_response :success
436 assert_template 'index'
437 assert assigns(:entries).all? {|entry| entry.user_id == 2}
438 end
439
432 def test_index_at_project_level
440 def test_index_at_project_level
433 get :index, :project_id => 'ecookbook'
441 get :index, :project_id => 'ecookbook'
434 assert_response :success
442 assert_response :success
435 assert_template 'index'
443 assert_template 'index'
436 assert_not_nil assigns(:entries)
444 assert_not_nil assigns(:entries)
437 assert_equal 4, assigns(:entries).size
445 assert_equal 4, assigns(:entries).size
438 # project and subproject
446 # project and subproject
439 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
447 assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort
440 assert_not_nil assigns(:total_hours)
448 assert_not_nil assigns(:total_hours)
441 assert_equal "162.90", "%.2f" % assigns(:total_hours)
449 assert_equal "162.90", "%.2f" % assigns(:total_hours)
442 assert_tag :form,
450 assert_tag :form,
443 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
451 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
444 end
452 end
445
453
446 def test_index_at_project_level_with_date_range
454 def test_index_at_project_level_with_date_range
447 get :index, :project_id => 'ecookbook',
455 get :index, :project_id => 'ecookbook',
448 :f => ['spent_on'],
456 :f => ['spent_on'],
449 :op => {'spent_on' => '><'},
457 :op => {'spent_on' => '><'},
450 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
458 :v => {'spent_on' => ['2007-03-20', '2007-04-30']}
451 assert_response :success
459 assert_response :success
452 assert_template 'index'
460 assert_template 'index'
453 assert_not_nil assigns(:entries)
461 assert_not_nil assigns(:entries)
454 assert_equal 3, assigns(:entries).size
462 assert_equal 3, assigns(:entries).size
455 assert_not_nil assigns(:total_hours)
463 assert_not_nil assigns(:total_hours)
456 assert_equal "12.90", "%.2f" % assigns(:total_hours)
464 assert_equal "12.90", "%.2f" % assigns(:total_hours)
457 assert_tag :form,
465 assert_tag :form,
458 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
466 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
459 end
467 end
460
468
461 def test_index_at_project_level_with_date_range_using_from_and_to_params
469 def test_index_at_project_level_with_date_range_using_from_and_to_params
462 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
470 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
463 assert_response :success
471 assert_response :success
464 assert_template 'index'
472 assert_template 'index'
465 assert_not_nil assigns(:entries)
473 assert_not_nil assigns(:entries)
466 assert_equal 3, assigns(:entries).size
474 assert_equal 3, assigns(:entries).size
467 assert_not_nil assigns(:total_hours)
475 assert_not_nil assigns(:total_hours)
468 assert_equal "12.90", "%.2f" % assigns(:total_hours)
476 assert_equal "12.90", "%.2f" % assigns(:total_hours)
469 assert_tag :form,
477 assert_tag :form,
470 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
478 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
471 end
479 end
472
480
473 def test_index_at_project_level_with_period
481 def test_index_at_project_level_with_period
474 get :index, :project_id => 'ecookbook',
482 get :index, :project_id => 'ecookbook',
475 :f => ['spent_on'],
483 :f => ['spent_on'],
476 :op => {'spent_on' => '>t-'},
484 :op => {'spent_on' => '>t-'},
477 :v => {'spent_on' => ['7']}
485 :v => {'spent_on' => ['7']}
478 assert_response :success
486 assert_response :success
479 assert_template 'index'
487 assert_template 'index'
480 assert_not_nil assigns(:entries)
488 assert_not_nil assigns(:entries)
481 assert_not_nil assigns(:total_hours)
489 assert_not_nil assigns(:total_hours)
482 assert_tag :form,
490 assert_tag :form,
483 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
491 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
484 end
492 end
485
493
486 def test_index_at_issue_level
494 def test_index_at_issue_level
487 get :index, :issue_id => 1
495 get :index, :issue_id => 1
488 assert_response :success
496 assert_response :success
489 assert_template 'index'
497 assert_template 'index'
490 assert_not_nil assigns(:entries)
498 assert_not_nil assigns(:entries)
491 assert_equal 2, assigns(:entries).size
499 assert_equal 2, assigns(:entries).size
492 assert_not_nil assigns(:total_hours)
500 assert_not_nil assigns(:total_hours)
493 assert_equal 154.25, assigns(:total_hours)
501 assert_equal 154.25, assigns(:total_hours)
494 # display all time
502 # display all time
495 assert_nil assigns(:from)
503 assert_nil assigns(:from)
496 assert_nil assigns(:to)
504 assert_nil assigns(:to)
497 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
505 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
498 # to use /issues/:issue_id/time_entries
506 # to use /issues/:issue_id/time_entries
499 assert_tag :form,
507 assert_tag :form,
500 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
508 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
501 end
509 end
502
510
503 def test_index_should_sort_by_spent_on_and_created_on
511 def test_index_should_sort_by_spent_on_and_created_on
504 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)
512 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)
505 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)
513 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)
506 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)
514 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)
507
515
508 get :index, :project_id => 1,
516 get :index, :project_id => 1,
509 :f => ['spent_on'],
517 :f => ['spent_on'],
510 :op => {'spent_on' => '><'},
518 :op => {'spent_on' => '><'},
511 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
519 :v => {'spent_on' => ['2012-06-15', '2012-06-16']}
512 assert_response :success
520 assert_response :success
513 assert_equal [t2, t1, t3], assigns(:entries)
521 assert_equal [t2, t1, t3], assigns(:entries)
514
522
515 get :index, :project_id => 1,
523 get :index, :project_id => 1,
516 :f => ['spent_on'],
524 :f => ['spent_on'],
517 :op => {'spent_on' => '><'},
525 :op => {'spent_on' => '><'},
518 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
526 :v => {'spent_on' => ['2012-06-15', '2012-06-16']},
519 :sort => 'spent_on'
527 :sort => 'spent_on'
520 assert_response :success
528 assert_response :success
521 assert_equal [t3, t1, t2], assigns(:entries)
529 assert_equal [t3, t1, t2], assigns(:entries)
522 end
530 end
523
531
524 def test_index_with_filter_on_issue_custom_field
532 def test_index_with_filter_on_issue_custom_field
525 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
533 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
526 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
534 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
527
535
528 get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
536 get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']}
529 assert_response :success
537 assert_response :success
530 assert_equal [entry], assigns(:entries)
538 assert_equal [entry], assigns(:entries)
531 end
539 end
532
540
533 def test_index_with_issue_custom_field_column
541 def test_index_with_issue_custom_field_column
534 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
542 issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'})
535 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
543 entry = TimeEntry.generate!(:issue => issue, :hours => 2.5)
536
544
537 get :index, :c => %w(project spent_on issue comments hours issue.cf_2)
545 get :index, :c => %w(project spent_on issue comments hours issue.cf_2)
538 assert_response :success
546 assert_response :success
539 assert_include :'issue.cf_2', assigns(:query).column_names
547 assert_include :'issue.cf_2', assigns(:query).column_names
540 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
548 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
541 end
549 end
542
550
543 def test_index_atom_feed
551 def test_index_atom_feed
544 get :index, :project_id => 1, :format => 'atom'
552 get :index, :project_id => 1, :format => 'atom'
545 assert_response :success
553 assert_response :success
546 assert_equal 'application/atom+xml', @response.content_type
554 assert_equal 'application/atom+xml', @response.content_type
547 assert_not_nil assigns(:items)
555 assert_not_nil assigns(:items)
548 assert assigns(:items).first.is_a?(TimeEntry)
556 assert assigns(:items).first.is_a?(TimeEntry)
549 end
557 end
550
558
551 def test_index_at_project_level_should_include_csv_export_dialog
559 def test_index_at_project_level_should_include_csv_export_dialog
552 get :index, :project_id => 'ecookbook',
560 get :index, :project_id => 'ecookbook',
553 :f => ['spent_on'],
561 :f => ['spent_on'],
554 :op => {'spent_on' => '>='},
562 :op => {'spent_on' => '>='},
555 :v => {'spent_on' => ['2007-04-01']},
563 :v => {'spent_on' => ['2007-04-01']},
556 :c => ['spent_on', 'user']
564 :c => ['spent_on', 'user']
557 assert_response :success
565 assert_response :success
558
566
559 assert_select '#csv-export-options' do
567 assert_select '#csv-export-options' do
560 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do
568 assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do
561 # filter
569 # filter
562 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on'
570 assert_select 'input[name=?][value=?]', 'f[]', 'spent_on'
563 assert_select 'input[name=?][value=?]', 'op[spent_on]', '&gt;='
571 assert_select 'input[name=?][value=?]', 'op[spent_on]', '&gt;='
564 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01'
572 assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01'
565 # columns
573 # columns
566 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on'
574 assert_select 'input[name=?][value=?]', 'c[]', 'spent_on'
567 assert_select 'input[name=?][value=?]', 'c[]', 'user'
575 assert_select 'input[name=?][value=?]', 'c[]', 'user'
568 assert_select 'input[name=?]', 'c[]', 2
576 assert_select 'input[name=?]', 'c[]', 2
569 end
577 end
570 end
578 end
571 end
579 end
572
580
573 def test_index_cross_project_should_include_csv_export_dialog
581 def test_index_cross_project_should_include_csv_export_dialog
574 get :index
582 get :index
575 assert_response :success
583 assert_response :success
576
584
577 assert_select '#csv-export-options' do
585 assert_select '#csv-export-options' do
578 assert_select 'form[action=?][method=get]', '/time_entries.csv'
586 assert_select 'form[action=?][method=get]', '/time_entries.csv'
579 end
587 end
580 end
588 end
581
589
582 def test_index_at_issue_level_should_include_csv_export_dialog
590 def test_index_at_issue_level_should_include_csv_export_dialog
583 get :index, :project_id => 'ecookbook', :issue_id => 3
591 get :index, :project_id => 'ecookbook', :issue_id => 3
584 assert_response :success
592 assert_response :success
585
593
586 assert_select '#csv-export-options' do
594 assert_select '#csv-export-options' do
587 assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv'
595 assert_select 'form[action=?][method=get]', '/projects/ecookbook/issues/3/time_entries.csv'
588 end
596 end
589 end
597 end
590
598
591 def test_index_csv_all_projects
599 def test_index_csv_all_projects
592 Setting.date_format = '%m/%d/%Y'
600 Setting.date_format = '%m/%d/%Y'
593 get :index, :format => 'csv'
601 get :index, :format => 'csv'
594 assert_response :success
602 assert_response :success
595 assert_equal 'text/csv; header=present', response.content_type
603 assert_equal 'text/csv; header=present', response.content_type
596 end
604 end
597
605
598 def test_index_csv
606 def test_index_csv
599 Setting.date_format = '%m/%d/%Y'
607 Setting.date_format = '%m/%d/%Y'
600 get :index, :project_id => 1, :format => 'csv'
608 get :index, :project_id => 1, :format => 'csv'
601 assert_response :success
609 assert_response :success
602 assert_equal 'text/csv; header=present', response.content_type
610 assert_equal 'text/csv; header=present', response.content_type
603 end
611 end
604 end
612 end
General Comments 0
You need to be logged in to leave comments. Login now