@@ -1,826 +1,835 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | # Redmine - project management software |
|
2 | # Redmine - project management software | |
3 | # Copyright (C) 2006-2016 Jean-Philippe Lang |
|
3 | # Copyright (C) 2006-2016 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 |
|
31 | def test_new | |
32 | @request.session[:user_id] = 3 |
|
32 | @request.session[:user_id] = 3 | |
33 | get :new |
|
33 | get :new | |
34 | assert_response :success |
|
34 | assert_response :success | |
35 | assert_template 'new' |
|
35 | assert_template 'new' | |
36 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 |
|
36 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 | |
37 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 |
|
37 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 | |
38 | assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
38 | assert_select 'select[name=?]', 'time_entry[project_id]' do | |
39 | # blank option for project |
|
39 | # blank option for project | |
40 | assert_select 'option[value=""]' |
|
40 | assert_select 'option[value=""]' | |
41 | end |
|
41 | end | |
42 | end |
|
42 | end | |
43 |
|
43 | |||
44 | def test_new_with_project_id |
|
44 | def test_new_with_project_id | |
45 | @request.session[:user_id] = 3 |
|
45 | @request.session[:user_id] = 3 | |
46 | get :new, :project_id => 1 |
|
46 | get :new, :project_id => 1 | |
47 | assert_response :success |
|
47 | assert_response :success | |
48 | assert_template 'new' |
|
48 | assert_template 'new' | |
49 | assert_select 'input[name=?][type=hidden]', 'project_id' |
|
49 | assert_select 'input[name=?][type=hidden]', 'project_id' | |
50 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 |
|
50 | assert_select 'input[name=?][type=hidden]', 'issue_id', 0 | |
51 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
51 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 | |
52 | end |
|
52 | end | |
53 |
|
53 | |||
54 | def test_new_with_issue_id |
|
54 | def test_new_with_issue_id | |
55 | @request.session[:user_id] = 3 |
|
55 | @request.session[:user_id] = 3 | |
56 | get :new, :issue_id => 2 |
|
56 | get :new, :issue_id => 2 | |
57 | assert_response :success |
|
57 | assert_response :success | |
58 | assert_template 'new' |
|
58 | assert_template 'new' | |
59 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 |
|
59 | assert_select 'input[name=?][type=hidden]', 'project_id', 0 | |
60 | assert_select 'input[name=?][type=hidden]', 'issue_id' |
|
60 | assert_select 'input[name=?][type=hidden]', 'issue_id' | |
61 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 |
|
61 | assert_select 'select[name=?]', 'time_entry[project_id]', 0 | |
62 | end |
|
62 | end | |
63 |
|
63 | |||
64 | def test_new_without_project_should_prefill_the_form |
|
64 | def test_new_without_project_should_prefill_the_form | |
65 | @request.session[:user_id] = 3 |
|
65 | @request.session[:user_id] = 3 | |
66 | get :new, :time_entry => {:project_id => '1'} |
|
66 | get :new, :time_entry => {:project_id => '1'} | |
67 | assert_response :success |
|
67 | assert_response :success | |
68 | assert_template 'new' |
|
68 | assert_template 'new' | |
69 | assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
69 | assert_select 'select[name=?]', 'time_entry[project_id]' do | |
70 | assert_select 'option[value="1"][selected=selected]' |
|
70 | assert_select 'option[value="1"][selected=selected]' | |
71 | end |
|
71 | end | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def test_new_without_project_should_deny_without_permission |
|
74 | def test_new_without_project_should_deny_without_permission | |
75 | Role.all.each {|role| role.remove_permission! :log_time} |
|
75 | Role.all.each {|role| role.remove_permission! :log_time} | |
76 | @request.session[:user_id] = 3 |
|
76 | @request.session[:user_id] = 3 | |
77 |
|
77 | |||
78 | get :new |
|
78 | get :new | |
79 | assert_response 403 |
|
79 | assert_response 403 | |
80 | end |
|
80 | end | |
81 |
|
81 | |||
82 | def test_new_should_select_default_activity |
|
82 | def test_new_should_select_default_activity | |
83 | @request.session[:user_id] = 3 |
|
83 | @request.session[:user_id] = 3 | |
84 | get :new, :project_id => 1 |
|
84 | get :new, :project_id => 1 | |
85 | assert_response :success |
|
85 | assert_response :success | |
86 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
86 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
87 | assert_select 'option[selected=selected]', :text => 'Development' |
|
87 | assert_select 'option[selected=selected]', :text => 'Development' | |
88 | end |
|
88 | end | |
89 | end |
|
89 | end | |
90 |
|
90 | |||
91 | def test_new_should_only_show_active_time_entry_activities |
|
91 | def test_new_should_only_show_active_time_entry_activities | |
92 | @request.session[:user_id] = 3 |
|
92 | @request.session[:user_id] = 3 | |
93 | get :new, :project_id => 1 |
|
93 | get :new, :project_id => 1 | |
94 | assert_response :success |
|
94 | assert_response :success | |
95 | assert_select 'option', :text => 'Inactive Activity', :count => 0 |
|
95 | assert_select 'option', :text => 'Inactive Activity', :count => 0 | |
96 | end |
|
96 | end | |
97 |
|
97 | |||
98 | def test_post_new_as_js_should_update_activity_options |
|
98 | def test_post_new_as_js_should_update_activity_options | |
99 | @request.session[:user_id] = 3 |
|
99 | @request.session[:user_id] = 3 | |
100 | post :new, :time_entry => {:project_id => 1}, :format => 'js' |
|
100 | post :new, :time_entry => {:project_id => 1}, :format => 'js' | |
101 | assert_response :success |
|
101 | assert_response :success | |
102 | assert_include '#time_entry_activity_id', response.body |
|
102 | assert_include '#time_entry_activity_id', response.body | |
103 | end |
|
103 | end | |
104 |
|
104 | |||
105 | def test_get_edit_existing_time |
|
105 | def test_get_edit_existing_time | |
106 | @request.session[:user_id] = 2 |
|
106 | @request.session[:user_id] = 2 | |
107 | get :edit, :id => 2, :project_id => nil |
|
107 | get :edit, :id => 2, :project_id => nil | |
108 | assert_response :success |
|
108 | assert_response :success | |
109 | assert_template 'edit' |
|
109 | assert_template 'edit' | |
110 | assert_select 'form[action=?]', '/time_entries/2' |
|
110 | assert_select 'form[action=?]', '/time_entries/2' | |
111 | end |
|
111 | end | |
112 |
|
112 | |||
113 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity |
|
113 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity | |
114 | te = TimeEntry.find(1) |
|
114 | te = TimeEntry.find(1) | |
115 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") |
|
115 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") | |
116 | te.save!(:validate => false) |
|
116 | te.save!(:validate => false) | |
117 |
|
117 | |||
118 | @request.session[:user_id] = 1 |
|
118 | @request.session[:user_id] = 1 | |
119 | get :edit, :project_id => 1, :id => 1 |
|
119 | get :edit, :project_id => 1, :id => 1 | |
120 | assert_response :success |
|
120 | assert_response :success | |
121 | assert_template 'edit' |
|
121 | assert_template 'edit' | |
122 | # Blank option since nothing is pre-selected |
|
122 | # Blank option since nothing is pre-selected | |
123 | assert_select 'option', :text => '--- Please select ---' |
|
123 | assert_select 'option', :text => '--- Please select ---' | |
124 | end |
|
124 | end | |
125 |
|
125 | |||
126 | def test_post_create |
|
126 | def test_post_create | |
127 | @request.session[:user_id] = 3 |
|
127 | @request.session[:user_id] = 3 | |
128 | assert_difference 'TimeEntry.count' do |
|
128 | assert_difference 'TimeEntry.count' do | |
129 | post :create, :project_id => 1, |
|
129 | post :create, :project_id => 1, | |
130 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
130 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
131 | # Not the default activity |
|
131 | # Not the default activity | |
132 | :activity_id => '11', |
|
132 | :activity_id => '11', | |
133 | :spent_on => '2008-03-14', |
|
133 | :spent_on => '2008-03-14', | |
134 | :issue_id => '1', |
|
134 | :issue_id => '1', | |
135 | :hours => '7.3'} |
|
135 | :hours => '7.3'} | |
136 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
136 | assert_redirected_to '/projects/ecookbook/time_entries' | |
137 | end |
|
137 | end | |
138 |
|
138 | |||
139 | t = TimeEntry.order('id DESC').first |
|
139 | t = TimeEntry.order('id DESC').first | |
140 | assert_not_nil t |
|
140 | assert_not_nil t | |
141 | assert_equal 'Some work on TimelogControllerTest', t.comments |
|
141 | assert_equal 'Some work on TimelogControllerTest', t.comments | |
142 | assert_equal 1, t.project_id |
|
142 | assert_equal 1, t.project_id | |
143 | assert_equal 1, t.issue_id |
|
143 | assert_equal 1, t.issue_id | |
144 | assert_equal 11, t.activity_id |
|
144 | assert_equal 11, t.activity_id | |
145 | assert_equal 7.3, t.hours |
|
145 | assert_equal 7.3, t.hours | |
146 | assert_equal 3, t.user_id |
|
146 | assert_equal 3, t.user_id | |
147 | end |
|
147 | end | |
148 |
|
148 | |||
149 | def test_post_create_with_blank_issue |
|
149 | def test_post_create_with_blank_issue | |
150 | @request.session[:user_id] = 3 |
|
150 | @request.session[:user_id] = 3 | |
151 | assert_difference 'TimeEntry.count' do |
|
151 | assert_difference 'TimeEntry.count' do | |
152 | post :create, :project_id => 1, |
|
152 | post :create, :project_id => 1, | |
153 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
153 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
154 | # Not the default activity |
|
154 | # Not the default activity | |
155 | :activity_id => '11', |
|
155 | :activity_id => '11', | |
156 | :issue_id => '', |
|
156 | :issue_id => '', | |
157 | :spent_on => '2008-03-14', |
|
157 | :spent_on => '2008-03-14', | |
158 | :hours => '7.3'} |
|
158 | :hours => '7.3'} | |
159 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
159 | assert_redirected_to '/projects/ecookbook/time_entries' | |
160 | end |
|
160 | end | |
161 |
|
161 | |||
162 | t = TimeEntry.order('id DESC').first |
|
162 | t = TimeEntry.order('id DESC').first | |
163 | assert_not_nil t |
|
163 | assert_not_nil t | |
164 | assert_equal 'Some work on TimelogControllerTest', t.comments |
|
164 | assert_equal 'Some work on TimelogControllerTest', t.comments | |
165 | assert_equal 1, t.project_id |
|
165 | assert_equal 1, t.project_id | |
166 | assert_nil t.issue_id |
|
166 | assert_nil t.issue_id | |
167 | assert_equal 11, t.activity_id |
|
167 | assert_equal 11, t.activity_id | |
168 | assert_equal 7.3, t.hours |
|
168 | assert_equal 7.3, t.hours | |
169 | assert_equal 3, t.user_id |
|
169 | assert_equal 3, t.user_id | |
170 | end |
|
170 | end | |
171 |
|
171 | |||
172 | def test_create_on_project_with_time_tracking_disabled_should_fail |
|
172 | def test_create_on_project_with_time_tracking_disabled_should_fail | |
173 | Project.find(1).disable_module! :time_tracking |
|
173 | Project.find(1).disable_module! :time_tracking | |
174 |
|
174 | |||
175 | @request.session[:user_id] = 2 |
|
175 | @request.session[:user_id] = 2 | |
176 | assert_no_difference 'TimeEntry.count' do |
|
176 | assert_no_difference 'TimeEntry.count' do | |
177 | post :create, :time_entry => { |
|
177 | post :create, :time_entry => { | |
178 | :project_id => '1', :issue_id => '', |
|
178 | :project_id => '1', :issue_id => '', | |
179 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
179 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
180 | } |
|
180 | } | |
181 | end |
|
181 | end | |
182 | end |
|
182 | end | |
183 |
|
183 | |||
184 | def test_create_on_project_without_permission_should_fail |
|
184 | def test_create_on_project_without_permission_should_fail | |
185 | Role.find(1).remove_permission! :log_time |
|
185 | Role.find(1).remove_permission! :log_time | |
186 |
|
186 | |||
187 | @request.session[:user_id] = 2 |
|
187 | @request.session[:user_id] = 2 | |
188 | assert_no_difference 'TimeEntry.count' do |
|
188 | assert_no_difference 'TimeEntry.count' do | |
189 | post :create, :time_entry => { |
|
189 | post :create, :time_entry => { | |
190 | :project_id => '1', :issue_id => '', |
|
190 | :project_id => '1', :issue_id => '', | |
191 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
191 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
192 | } |
|
192 | } | |
193 | end |
|
193 | end | |
194 | end |
|
194 | end | |
195 |
|
195 | |||
196 | def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail |
|
196 | def test_create_on_issue_in_project_with_time_tracking_disabled_should_fail | |
197 | Project.find(1).disable_module! :time_tracking |
|
197 | Project.find(1).disable_module! :time_tracking | |
198 |
|
198 | |||
199 | @request.session[:user_id] = 2 |
|
199 | @request.session[:user_id] = 2 | |
200 | assert_no_difference 'TimeEntry.count' do |
|
200 | assert_no_difference 'TimeEntry.count' do | |
201 | post :create, :time_entry => { |
|
201 | post :create, :time_entry => { | |
202 | :project_id => '', :issue_id => '1', |
|
202 | :project_id => '', :issue_id => '1', | |
203 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
203 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
204 | } |
|
204 | } | |
205 | assert_select_error /Issue is invalid/ |
|
205 | assert_select_error /Issue is invalid/ | |
206 | end |
|
206 | end | |
207 | end |
|
207 | end | |
208 |
|
208 | |||
209 | def test_create_on_issue_in_project_without_permission_should_fail |
|
209 | def test_create_on_issue_in_project_without_permission_should_fail | |
210 | Role.find(1).remove_permission! :log_time |
|
210 | Role.find(1).remove_permission! :log_time | |
211 |
|
211 | |||
212 | @request.session[:user_id] = 2 |
|
212 | @request.session[:user_id] = 2 | |
213 | assert_no_difference 'TimeEntry.count' do |
|
213 | assert_no_difference 'TimeEntry.count' do | |
214 | post :create, :time_entry => { |
|
214 | post :create, :time_entry => { | |
215 | :project_id => '', :issue_id => '1', |
|
215 | :project_id => '', :issue_id => '1', | |
216 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
216 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
217 | } |
|
217 | } | |
218 | assert_select_error /Issue is invalid/ |
|
218 | assert_select_error /Issue is invalid/ | |
219 | end |
|
219 | end | |
220 | end |
|
220 | end | |
221 |
|
221 | |||
222 | def test_create_on_issue_that_is_not_visible_should_not_disclose_subject |
|
222 | def test_create_on_issue_that_is_not_visible_should_not_disclose_subject | |
223 | issue = Issue.generate!(:subject => "issue_that_is_not_visible", :is_private => true) |
|
223 | issue = Issue.generate!(:subject => "issue_that_is_not_visible", :is_private => true) | |
224 | assert !issue.visible?(User.find(3)) |
|
224 | assert !issue.visible?(User.find(3)) | |
225 |
|
225 | |||
226 | @request.session[:user_id] = 3 |
|
226 | @request.session[:user_id] = 3 | |
227 | assert_no_difference 'TimeEntry.count' do |
|
227 | assert_no_difference 'TimeEntry.count' do | |
228 | post :create, :time_entry => { |
|
228 | post :create, :time_entry => { | |
229 | :project_id => '', :issue_id => issue.id.to_s, |
|
229 | :project_id => '', :issue_id => issue.id.to_s, | |
230 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' |
|
230 | :activity_id => '11', :spent_on => '2008-03-14', :hours => '7.3' | |
231 | } |
|
231 | } | |
232 | end |
|
232 | end | |
233 | assert_select_error /Issue is invalid/ |
|
233 | assert_select_error /Issue is invalid/ | |
234 | assert_select "input[name=?][value=?]", "time_entry[issue_id]", issue.id.to_s |
|
234 | assert_select "input[name=?][value=?]", "time_entry[issue_id]", issue.id.to_s | |
235 | assert_select "#time_entry_issue", 0 |
|
235 | assert_select "#time_entry_issue", 0 | |
236 | assert !response.body.include?('issue_that_is_not_visible') |
|
236 | assert !response.body.include?('issue_that_is_not_visible') | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | def test_create_and_continue_at_project_level |
|
239 | def test_create_and_continue_at_project_level | |
240 | @request.session[:user_id] = 2 |
|
240 | @request.session[:user_id] = 2 | |
241 | assert_difference 'TimeEntry.count' do |
|
241 | assert_difference 'TimeEntry.count' do | |
242 | post :create, :time_entry => {:project_id => '1', |
|
242 | post :create, :time_entry => {:project_id => '1', | |
243 | :activity_id => '11', |
|
243 | :activity_id => '11', | |
244 | :issue_id => '', |
|
244 | :issue_id => '', | |
245 | :spent_on => '2008-03-14', |
|
245 | :spent_on => '2008-03-14', | |
246 | :hours => '7.3'}, |
|
246 | :hours => '7.3'}, | |
247 | :continue => '1' |
|
247 | :continue => '1' | |
248 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' |
|
248 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=1' | |
249 | end |
|
249 | end | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | def test_create_and_continue_at_issue_level |
|
252 | def test_create_and_continue_at_issue_level | |
253 | @request.session[:user_id] = 2 |
|
253 | @request.session[:user_id] = 2 | |
254 | assert_difference 'TimeEntry.count' do |
|
254 | assert_difference 'TimeEntry.count' do | |
255 | post :create, :time_entry => {:project_id => '', |
|
255 | post :create, :time_entry => {:project_id => '', | |
256 | :activity_id => '11', |
|
256 | :activity_id => '11', | |
257 | :issue_id => '1', |
|
257 | :issue_id => '1', | |
258 | :spent_on => '2008-03-14', |
|
258 | :spent_on => '2008-03-14', | |
259 | :hours => '7.3'}, |
|
259 | :hours => '7.3'}, | |
260 | :continue => '1' |
|
260 | :continue => '1' | |
261 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' |
|
261 | assert_redirected_to '/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' | |
262 | end |
|
262 | end | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | def test_create_and_continue_with_project_id |
|
265 | def test_create_and_continue_with_project_id | |
266 | @request.session[:user_id] = 2 |
|
266 | @request.session[:user_id] = 2 | |
267 | assert_difference 'TimeEntry.count' do |
|
267 | assert_difference 'TimeEntry.count' do | |
268 | post :create, :project_id => 1, |
|
268 | post :create, :project_id => 1, | |
269 | :time_entry => {:activity_id => '11', |
|
269 | :time_entry => {:activity_id => '11', | |
270 | :issue_id => '', |
|
270 | :issue_id => '', | |
271 | :spent_on => '2008-03-14', |
|
271 | :spent_on => '2008-03-14', | |
272 | :hours => '7.3'}, |
|
272 | :hours => '7.3'}, | |
273 | :continue => '1' |
|
273 | :continue => '1' | |
274 | assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=' |
|
274 | assert_redirected_to '/projects/ecookbook/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=&time_entry%5Bproject_id%5D=' | |
275 | end |
|
275 | end | |
276 | end |
|
276 | end | |
277 |
|
277 | |||
278 | def test_create_and_continue_with_issue_id |
|
278 | def test_create_and_continue_with_issue_id | |
279 | @request.session[:user_id] = 2 |
|
279 | @request.session[:user_id] = 2 | |
280 | assert_difference 'TimeEntry.count' do |
|
280 | assert_difference 'TimeEntry.count' do | |
281 | post :create, :issue_id => 1, |
|
281 | post :create, :issue_id => 1, | |
282 | :time_entry => {:activity_id => '11', |
|
282 | :time_entry => {:activity_id => '11', | |
283 | :issue_id => '1', |
|
283 | :issue_id => '1', | |
284 | :spent_on => '2008-03-14', |
|
284 | :spent_on => '2008-03-14', | |
285 | :hours => '7.3'}, |
|
285 | :hours => '7.3'}, | |
286 | :continue => '1' |
|
286 | :continue => '1' | |
287 | assert_redirected_to '/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' |
|
287 | assert_redirected_to '/issues/1/time_entries/new?time_entry%5Bactivity_id%5D=11&time_entry%5Bissue_id%5D=1&time_entry%5Bproject_id%5D=' | |
288 | end |
|
288 | end | |
289 | end |
|
289 | end | |
290 |
|
290 | |||
291 | def test_create_without_log_time_permission_should_be_denied |
|
291 | def test_create_without_log_time_permission_should_be_denied | |
292 | @request.session[:user_id] = 2 |
|
292 | @request.session[:user_id] = 2 | |
293 | Role.find_by_name('Manager').remove_permission! :log_time |
|
293 | Role.find_by_name('Manager').remove_permission! :log_time | |
294 | post :create, :project_id => 1, |
|
294 | post :create, :project_id => 1, | |
295 | :time_entry => {:activity_id => '11', |
|
295 | :time_entry => {:activity_id => '11', | |
296 | :issue_id => '', |
|
296 | :issue_id => '', | |
297 | :spent_on => '2008-03-14', |
|
297 | :spent_on => '2008-03-14', | |
298 | :hours => '7.3'} |
|
298 | :hours => '7.3'} | |
299 |
|
299 | |||
300 | assert_response 403 |
|
300 | assert_response 403 | |
301 | end |
|
301 | end | |
302 |
|
302 | |||
303 | def test_create_without_project_and_issue_should_fail |
|
303 | def test_create_without_project_and_issue_should_fail | |
304 | @request.session[:user_id] = 2 |
|
304 | @request.session[:user_id] = 2 | |
305 | post :create, :time_entry => {:issue_id => ''} |
|
305 | post :create, :time_entry => {:issue_id => ''} | |
306 |
|
306 | |||
307 | assert_response :success |
|
307 | assert_response :success | |
308 | assert_template 'new' |
|
308 | assert_template 'new' | |
309 | end |
|
309 | end | |
310 |
|
310 | |||
311 | def test_create_with_failure |
|
311 | def test_create_with_failure | |
312 | @request.session[:user_id] = 2 |
|
312 | @request.session[:user_id] = 2 | |
313 | post :create, :project_id => 1, |
|
313 | post :create, :project_id => 1, | |
314 | :time_entry => {:activity_id => '', |
|
314 | :time_entry => {:activity_id => '', | |
315 | :issue_id => '', |
|
315 | :issue_id => '', | |
316 | :spent_on => '2008-03-14', |
|
316 | :spent_on => '2008-03-14', | |
317 | :hours => '7.3'} |
|
317 | :hours => '7.3'} | |
318 |
|
318 | |||
319 | assert_response :success |
|
319 | assert_response :success | |
320 | assert_template 'new' |
|
320 | assert_template 'new' | |
321 | end |
|
321 | end | |
322 |
|
322 | |||
323 | def test_create_without_project |
|
323 | def test_create_without_project | |
324 | @request.session[:user_id] = 2 |
|
324 | @request.session[:user_id] = 2 | |
325 | assert_difference 'TimeEntry.count' do |
|
325 | assert_difference 'TimeEntry.count' do | |
326 | post :create, :time_entry => {:project_id => '1', |
|
326 | post :create, :time_entry => {:project_id => '1', | |
327 | :activity_id => '11', |
|
327 | :activity_id => '11', | |
328 | :issue_id => '', |
|
328 | :issue_id => '', | |
329 | :spent_on => '2008-03-14', |
|
329 | :spent_on => '2008-03-14', | |
330 | :hours => '7.3'} |
|
330 | :hours => '7.3'} | |
331 | end |
|
331 | end | |
332 |
|
332 | |||
333 | assert_redirected_to '/projects/ecookbook/time_entries' |
|
333 | assert_redirected_to '/projects/ecookbook/time_entries' | |
334 | time_entry = TimeEntry.order('id DESC').first |
|
334 | time_entry = TimeEntry.order('id DESC').first | |
335 | assert_equal 1, time_entry.project_id |
|
335 | assert_equal 1, time_entry.project_id | |
336 | end |
|
336 | end | |
337 |
|
337 | |||
338 | def test_create_without_project_should_fail_with_issue_not_inside_project |
|
338 | def test_create_without_project_should_fail_with_issue_not_inside_project | |
339 | @request.session[:user_id] = 2 |
|
339 | @request.session[:user_id] = 2 | |
340 | assert_no_difference 'TimeEntry.count' do |
|
340 | assert_no_difference 'TimeEntry.count' do | |
341 | post :create, :time_entry => {:project_id => '1', |
|
341 | post :create, :time_entry => {:project_id => '1', | |
342 | :activity_id => '11', |
|
342 | :activity_id => '11', | |
343 | :issue_id => '5', |
|
343 | :issue_id => '5', | |
344 | :spent_on => '2008-03-14', |
|
344 | :spent_on => '2008-03-14', | |
345 | :hours => '7.3'} |
|
345 | :hours => '7.3'} | |
346 | end |
|
346 | end | |
347 |
|
347 | |||
348 | assert_response :success |
|
348 | assert_response :success | |
349 | assert assigns(:time_entry).errors[:issue_id].present? |
|
349 | assert assigns(:time_entry).errors[:issue_id].present? | |
350 | end |
|
350 | end | |
351 |
|
351 | |||
352 | def test_create_without_project_should_deny_without_permission |
|
352 | def test_create_without_project_should_deny_without_permission | |
353 | @request.session[:user_id] = 2 |
|
353 | @request.session[:user_id] = 2 | |
354 | Project.find(3).disable_module!(:time_tracking) |
|
354 | Project.find(3).disable_module!(:time_tracking) | |
355 |
|
355 | |||
356 | assert_no_difference 'TimeEntry.count' do |
|
356 | assert_no_difference 'TimeEntry.count' do | |
357 | post :create, :time_entry => {:project_id => '3', |
|
357 | post :create, :time_entry => {:project_id => '3', | |
358 | :activity_id => '11', |
|
358 | :activity_id => '11', | |
359 | :issue_id => '', |
|
359 | :issue_id => '', | |
360 | :spent_on => '2008-03-14', |
|
360 | :spent_on => '2008-03-14', | |
361 | :hours => '7.3'} |
|
361 | :hours => '7.3'} | |
362 | end |
|
362 | end | |
363 |
|
363 | |||
364 | assert_response 403 |
|
364 | assert_response 403 | |
365 | end |
|
365 | end | |
366 |
|
366 | |||
367 | def test_create_without_project_with_failure |
|
367 | def test_create_without_project_with_failure | |
368 | @request.session[:user_id] = 2 |
|
368 | @request.session[:user_id] = 2 | |
369 | assert_no_difference 'TimeEntry.count' do |
|
369 | assert_no_difference 'TimeEntry.count' do | |
370 | post :create, :time_entry => {:project_id => '1', |
|
370 | post :create, :time_entry => {:project_id => '1', | |
371 | :activity_id => '11', |
|
371 | :activity_id => '11', | |
372 | :issue_id => '', |
|
372 | :issue_id => '', | |
373 | :spent_on => '2008-03-14', |
|
373 | :spent_on => '2008-03-14', | |
374 | :hours => ''} |
|
374 | :hours => ''} | |
375 | end |
|
375 | end | |
376 |
|
376 | |||
377 | assert_response :success |
|
377 | assert_response :success | |
378 | assert_select 'select[name=?]', 'time_entry[project_id]' do |
|
378 | assert_select 'select[name=?]', 'time_entry[project_id]' do | |
379 | assert_select 'option[value="1"][selected=selected]' |
|
379 | assert_select 'option[value="1"][selected=selected]' | |
380 | end |
|
380 | end | |
381 | end |
|
381 | end | |
382 |
|
382 | |||
383 | def test_update |
|
383 | def test_update | |
384 | entry = TimeEntry.find(1) |
|
384 | entry = TimeEntry.find(1) | |
385 | assert_equal 1, entry.issue_id |
|
385 | assert_equal 1, entry.issue_id | |
386 | assert_equal 2, entry.user_id |
|
386 | assert_equal 2, entry.user_id | |
387 |
|
387 | |||
388 | @request.session[:user_id] = 1 |
|
388 | @request.session[:user_id] = 1 | |
389 | put :update, :id => 1, |
|
389 | put :update, :id => 1, | |
390 | :time_entry => {:issue_id => '2', |
|
390 | :time_entry => {:issue_id => '2', | |
391 | :hours => '8'} |
|
391 | :hours => '8'} | |
392 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
392 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
393 | entry.reload |
|
393 | entry.reload | |
394 |
|
394 | |||
395 | assert_equal 8, entry.hours |
|
395 | assert_equal 8, entry.hours | |
396 | assert_equal 2, entry.issue_id |
|
396 | assert_equal 2, entry.issue_id | |
397 | assert_equal 2, entry.user_id |
|
397 | assert_equal 2, entry.user_id | |
398 | end |
|
398 | end | |
399 |
|
399 | |||
400 | def test_update_should_allow_to_change_issue_to_another_project |
|
400 | def test_update_should_allow_to_change_issue_to_another_project | |
401 | entry = TimeEntry.generate!(:issue_id => 1) |
|
401 | entry = TimeEntry.generate!(:issue_id => 1) | |
402 |
|
402 | |||
403 | @request.session[:user_id] = 1 |
|
403 | @request.session[:user_id] = 1 | |
404 | put :update, :id => entry.id, :time_entry => {:issue_id => '5'} |
|
404 | put :update, :id => entry.id, :time_entry => {:issue_id => '5'} | |
405 | assert_response 302 |
|
405 | assert_response 302 | |
406 | entry.reload |
|
406 | entry.reload | |
407 |
|
407 | |||
408 | assert_equal 5, entry.issue_id |
|
408 | assert_equal 5, entry.issue_id | |
409 | assert_equal 3, entry.project_id |
|
409 | assert_equal 3, entry.project_id | |
410 | end |
|
410 | end | |
411 |
|
411 | |||
412 | def test_update_should_not_allow_to_change_issue_to_an_invalid_project |
|
412 | def test_update_should_not_allow_to_change_issue_to_an_invalid_project | |
413 | entry = TimeEntry.generate!(:issue_id => 1) |
|
413 | entry = TimeEntry.generate!(:issue_id => 1) | |
414 | Project.find(3).disable_module!(:time_tracking) |
|
414 | Project.find(3).disable_module!(:time_tracking) | |
415 |
|
415 | |||
416 | @request.session[:user_id] = 1 |
|
416 | @request.session[:user_id] = 1 | |
417 | put :update, :id => entry.id, :time_entry => {:issue_id => '5'} |
|
417 | put :update, :id => entry.id, :time_entry => {:issue_id => '5'} | |
418 | assert_response 200 |
|
418 | assert_response 200 | |
419 | assert_include "Issue is invalid", assigns(:time_entry).errors.full_messages |
|
419 | assert_include "Issue is invalid", assigns(:time_entry).errors.full_messages | |
420 | end |
|
420 | end | |
421 |
|
421 | |||
422 | def test_get_bulk_edit |
|
422 | def test_get_bulk_edit | |
423 | @request.session[:user_id] = 2 |
|
423 | @request.session[:user_id] = 2 | |
424 | get :bulk_edit, :ids => [1, 2] |
|
424 | get :bulk_edit, :ids => [1, 2] | |
425 | assert_response :success |
|
425 | assert_response :success | |
426 | assert_template 'bulk_edit' |
|
426 | assert_template 'bulk_edit' | |
427 |
|
427 | |||
428 | assert_select 'ul#bulk-selection' do |
|
428 | assert_select 'ul#bulk-selection' do | |
429 | assert_select 'li', 2 |
|
429 | assert_select 'li', 2 | |
430 | assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours' |
|
430 | assert_select 'li a', :text => '03/23/2007 - eCookbook: 4.25 hours' | |
431 | end |
|
431 | end | |
432 |
|
432 | |||
433 | assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do |
|
433 | assert_select 'form#bulk_edit_form[action=?]', '/time_entries/bulk_update' do | |
434 | # System wide custom field |
|
434 | # System wide custom field | |
435 | assert_select 'select[name=?]', 'time_entry[custom_field_values][10]' |
|
435 | assert_select 'select[name=?]', 'time_entry[custom_field_values][10]' | |
436 |
|
436 | |||
437 | # Activities |
|
437 | # Activities | |
438 | assert_select 'select[name=?]', 'time_entry[activity_id]' do |
|
438 | assert_select 'select[name=?]', 'time_entry[activity_id]' do | |
439 | assert_select 'option[value=""]', :text => '(No change)' |
|
439 | assert_select 'option[value=""]', :text => '(No change)' | |
440 | assert_select 'option[value="9"]', :text => 'Design' |
|
440 | assert_select 'option[value="9"]', :text => 'Design' | |
441 | end |
|
441 | end | |
442 | end |
|
442 | end | |
443 | end |
|
443 | end | |
444 |
|
444 | |||
445 | def test_get_bulk_edit_on_different_projects |
|
445 | def test_get_bulk_edit_on_different_projects | |
446 | @request.session[:user_id] = 2 |
|
446 | @request.session[:user_id] = 2 | |
447 | get :bulk_edit, :ids => [1, 2, 6] |
|
447 | get :bulk_edit, :ids => [1, 2, 6] | |
448 | assert_response :success |
|
448 | assert_response :success | |
449 | assert_template 'bulk_edit' |
|
449 | assert_template 'bulk_edit' | |
450 | end |
|
450 | end | |
451 |
|
451 | |||
452 | def test_bulk_edit_with_edit_own_time_entries_permission |
|
452 | def test_bulk_edit_with_edit_own_time_entries_permission | |
453 | @request.session[:user_id] = 2 |
|
453 | @request.session[:user_id] = 2 | |
454 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
454 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
455 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries |
|
455 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries | |
456 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} |
|
456 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} | |
457 |
|
457 | |||
458 | get :bulk_edit, :ids => ids |
|
458 | get :bulk_edit, :ids => ids | |
459 | assert_response :success |
|
459 | assert_response :success | |
460 | end |
|
460 | end | |
461 |
|
461 | |||
462 | def test_bulk_update |
|
462 | def test_bulk_update | |
463 | @request.session[:user_id] = 2 |
|
463 | @request.session[:user_id] = 2 | |
464 | # update time entry activity |
|
464 | # update time entry activity | |
465 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} |
|
465 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} | |
466 |
|
466 | |||
467 | assert_response 302 |
|
467 | assert_response 302 | |
468 | # check that the issues were updated |
|
468 | # check that the issues were updated | |
469 | assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id} |
|
469 | assert_equal [9, 9], TimeEntry.where(:id => [1, 2]).collect {|i| i.activity_id} | |
470 | end |
|
470 | end | |
471 |
|
471 | |||
472 | def test_bulk_update_with_failure |
|
472 | def test_bulk_update_with_failure | |
473 | @request.session[:user_id] = 2 |
|
473 | @request.session[:user_id] = 2 | |
474 | post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'} |
|
474 | post :bulk_update, :ids => [1, 2], :time_entry => { :hours => 'A'} | |
475 |
|
475 | |||
476 | assert_response 302 |
|
476 | assert_response 302 | |
477 | assert_match /Failed to save 2 time entrie/, flash[:error] |
|
477 | assert_match /Failed to save 2 time entrie/, flash[:error] | |
478 | end |
|
478 | end | |
479 |
|
479 | |||
480 | def test_bulk_update_on_different_projects |
|
480 | def test_bulk_update_on_different_projects | |
481 | @request.session[:user_id] = 2 |
|
481 | @request.session[:user_id] = 2 | |
482 | # makes user a manager on the other project |
|
482 | # makes user a manager on the other project | |
483 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) |
|
483 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) | |
484 |
|
484 | |||
485 | # update time entry activity |
|
485 | # update time entry activity | |
486 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } |
|
486 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } | |
487 |
|
487 | |||
488 | assert_response 302 |
|
488 | assert_response 302 | |
489 | # check that the issues were updated |
|
489 | # check that the issues were updated | |
490 | assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id} |
|
490 | assert_equal [9, 9, 9], TimeEntry.where(:id => [1, 2, 4]).collect {|i| i.activity_id} | |
491 | end |
|
491 | end | |
492 |
|
492 | |||
493 | def test_bulk_update_on_different_projects_without_rights |
|
493 | def test_bulk_update_on_different_projects_without_rights | |
494 | @request.session[:user_id] = 3 |
|
494 | @request.session[:user_id] = 3 | |
495 | user = User.find(3) |
|
495 | user = User.find(3) | |
496 | action = { :controller => "timelog", :action => "bulk_update" } |
|
496 | action = { :controller => "timelog", :action => "bulk_update" } | |
497 | assert user.allowed_to?(action, TimeEntry.find(1).project) |
|
497 | assert user.allowed_to?(action, TimeEntry.find(1).project) | |
498 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) |
|
498 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) | |
499 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } |
|
499 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } | |
500 | assert_response 403 |
|
500 | assert_response 403 | |
501 | end |
|
501 | end | |
502 |
|
502 | |||
503 | def test_bulk_update_with_edit_own_time_entries_permission |
|
503 | def test_bulk_update_with_edit_own_time_entries_permission | |
504 | @request.session[:user_id] = 2 |
|
504 | @request.session[:user_id] = 2 | |
505 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
505 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
506 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries |
|
506 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries | |
507 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} |
|
507 | ids = (0..1).map {TimeEntry.generate!(:user => User.find(2)).id} | |
508 |
|
508 | |||
509 | post :bulk_update, :ids => ids, :time_entry => { :activity_id => 9 } |
|
509 | post :bulk_update, :ids => ids, :time_entry => { :activity_id => 9 } | |
510 | assert_response 302 |
|
510 | assert_response 302 | |
511 | end |
|
511 | end | |
512 |
|
512 | |||
513 | def test_bulk_update_with_edit_own_time_entries_permissions_should_be_denied_for_time_entries_of_other_user |
|
513 | def test_bulk_update_with_edit_own_time_entries_permissions_should_be_denied_for_time_entries_of_other_user | |
514 | @request.session[:user_id] = 2 |
|
514 | @request.session[:user_id] = 2 | |
515 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
515 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
516 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries |
|
516 | Role.find_by_name('Manager').add_permission! :edit_own_time_entries | |
517 |
|
517 | |||
518 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9 } |
|
518 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9 } | |
519 | assert_response 403 |
|
519 | assert_response 403 | |
520 | end |
|
520 | end | |
521 |
|
521 | |||
522 | def test_bulk_update_custom_field |
|
522 | def test_bulk_update_custom_field | |
523 | @request.session[:user_id] = 2 |
|
523 | @request.session[:user_id] = 2 | |
524 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } |
|
524 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } | |
525 |
|
525 | |||
526 | assert_response 302 |
|
526 | assert_response 302 | |
527 | assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value} |
|
527 | assert_equal ["0", "0"], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(10).value} | |
528 | end |
|
528 | end | |
529 |
|
529 | |||
|
530 | def test_bulk_update_clear_custom_field | |||
|
531 | field = TimeEntryCustomField.generate!(:field_format => 'string') | |||
|
532 | @request.session[:user_id] = 2 | |||
|
533 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {field.id.to_s => '__none__'} } | |||
|
534 | ||||
|
535 | assert_response 302 | |||
|
536 | assert_equal ["", ""], TimeEntry.where(:id => [1, 2]).collect {|i| i.custom_value_for(field).value} | |||
|
537 | end | |||
|
538 | ||||
530 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
539 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
531 | @request.session[:user_id] = 2 |
|
540 | @request.session[:user_id] = 2 | |
532 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' |
|
541 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' | |
533 |
|
542 | |||
534 | assert_response :redirect |
|
543 | assert_response :redirect | |
535 | assert_redirected_to '/time_entries' |
|
544 | assert_redirected_to '/time_entries' | |
536 | end |
|
545 | end | |
537 |
|
546 | |||
538 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
547 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
539 | @request.session[:user_id] = 2 |
|
548 | @request.session[:user_id] = 2 | |
540 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
549 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | |
541 |
|
550 | |||
542 | assert_response :redirect |
|
551 | assert_response :redirect | |
543 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier |
|
552 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier | |
544 | end |
|
553 | end | |
545 |
|
554 | |||
546 | def test_post_bulk_update_without_edit_permission_should_be_denied |
|
555 | def test_post_bulk_update_without_edit_permission_should_be_denied | |
547 | @request.session[:user_id] = 2 |
|
556 | @request.session[:user_id] = 2 | |
548 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
557 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
549 | post :bulk_update, :ids => [1,2] |
|
558 | post :bulk_update, :ids => [1,2] | |
550 |
|
559 | |||
551 | assert_response 403 |
|
560 | assert_response 403 | |
552 | end |
|
561 | end | |
553 |
|
562 | |||
554 | def test_destroy |
|
563 | def test_destroy | |
555 | @request.session[:user_id] = 2 |
|
564 | @request.session[:user_id] = 2 | |
556 | delete :destroy, :id => 1 |
|
565 | delete :destroy, :id => 1 | |
557 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
566 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
558 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] |
|
567 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] | |
559 | assert_nil TimeEntry.find_by_id(1) |
|
568 | assert_nil TimeEntry.find_by_id(1) | |
560 | end |
|
569 | end | |
561 |
|
570 | |||
562 | def test_destroy_should_fail |
|
571 | def test_destroy_should_fail | |
563 | # simulate that this fails (e.g. due to a plugin), see #5700 |
|
572 | # simulate that this fails (e.g. due to a plugin), see #5700 | |
564 | TimeEntry.any_instance.expects(:destroy).returns(false) |
|
573 | TimeEntry.any_instance.expects(:destroy).returns(false) | |
565 |
|
574 | |||
566 | @request.session[:user_id] = 2 |
|
575 | @request.session[:user_id] = 2 | |
567 | delete :destroy, :id => 1 |
|
576 | delete :destroy, :id => 1 | |
568 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
577 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
569 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] |
|
578 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] | |
570 | assert_not_nil TimeEntry.find_by_id(1) |
|
579 | assert_not_nil TimeEntry.find_by_id(1) | |
571 | end |
|
580 | end | |
572 |
|
581 | |||
573 | def test_index_all_projects |
|
582 | def test_index_all_projects | |
574 | get :index |
|
583 | get :index | |
575 | assert_response :success |
|
584 | assert_response :success | |
576 | assert_template 'index' |
|
585 | assert_template 'index' | |
577 | assert_not_nil assigns(:total_hours) |
|
586 | assert_not_nil assigns(:total_hours) | |
578 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
587 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
579 | assert_select 'form#query_form[action=?]', '/time_entries' |
|
588 | assert_select 'form#query_form[action=?]', '/time_entries' | |
580 | end |
|
589 | end | |
581 |
|
590 | |||
582 | def test_index_all_projects_should_show_log_time_link |
|
591 | def test_index_all_projects_should_show_log_time_link | |
583 | @request.session[:user_id] = 2 |
|
592 | @request.session[:user_id] = 2 | |
584 | get :index |
|
593 | get :index | |
585 | assert_response :success |
|
594 | assert_response :success | |
586 | assert_template 'index' |
|
595 | assert_template 'index' | |
587 | assert_select 'a[href=?]', '/time_entries/new', :text => /Log time/ |
|
596 | assert_select 'a[href=?]', '/time_entries/new', :text => /Log time/ | |
588 | end |
|
597 | end | |
589 |
|
598 | |||
590 | def test_index_my_spent_time |
|
599 | def test_index_my_spent_time | |
591 | @request.session[:user_id] = 2 |
|
600 | @request.session[:user_id] = 2 | |
592 | get :index, :user_id => 'me' |
|
601 | get :index, :user_id => 'me' | |
593 | assert_response :success |
|
602 | assert_response :success | |
594 | assert_template 'index' |
|
603 | assert_template 'index' | |
595 | assert assigns(:entries).all? {|entry| entry.user_id == 2} |
|
604 | assert assigns(:entries).all? {|entry| entry.user_id == 2} | |
596 | end |
|
605 | end | |
597 |
|
606 | |||
598 | def test_index_at_project_level |
|
607 | def test_index_at_project_level | |
599 | get :index, :project_id => 'ecookbook' |
|
608 | get :index, :project_id => 'ecookbook' | |
600 | assert_response :success |
|
609 | assert_response :success | |
601 | assert_template 'index' |
|
610 | assert_template 'index' | |
602 | assert_not_nil assigns(:entries) |
|
611 | assert_not_nil assigns(:entries) | |
603 | assert_equal 4, assigns(:entries).size |
|
612 | assert_equal 4, assigns(:entries).size | |
604 | # project and subproject |
|
613 | # project and subproject | |
605 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
614 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort | |
606 | assert_not_nil assigns(:total_hours) |
|
615 | assert_not_nil assigns(:total_hours) | |
607 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
616 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
608 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
617 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
609 | end |
|
618 | end | |
610 |
|
619 | |||
611 | def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries |
|
620 | def test_index_with_display_subprojects_issues_to_false_should_not_include_subproject_entries | |
612 | entry = TimeEntry.generate!(:project => Project.find(3)) |
|
621 | entry = TimeEntry.generate!(:project => Project.find(3)) | |
613 |
|
622 | |||
614 | with_settings :display_subprojects_issues => '0' do |
|
623 | with_settings :display_subprojects_issues => '0' do | |
615 | get :index, :project_id => 'ecookbook' |
|
624 | get :index, :project_id => 'ecookbook' | |
616 | assert_response :success |
|
625 | assert_response :success | |
617 | assert_template 'index' |
|
626 | assert_template 'index' | |
618 | assert_not_include entry, assigns(:entries) |
|
627 | assert_not_include entry, assigns(:entries) | |
619 | end |
|
628 | end | |
620 | end |
|
629 | end | |
621 |
|
630 | |||
622 | def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries |
|
631 | def test_index_with_display_subprojects_issues_to_false_and_subproject_filter_should_include_subproject_entries | |
623 | entry = TimeEntry.generate!(:project => Project.find(3)) |
|
632 | entry = TimeEntry.generate!(:project => Project.find(3)) | |
624 |
|
633 | |||
625 | with_settings :display_subprojects_issues => '0' do |
|
634 | with_settings :display_subprojects_issues => '0' do | |
626 | get :index, :project_id => 'ecookbook', :subproject_id => 3 |
|
635 | get :index, :project_id => 'ecookbook', :subproject_id => 3 | |
627 | assert_response :success |
|
636 | assert_response :success | |
628 | assert_template 'index' |
|
637 | assert_template 'index' | |
629 | assert_include entry, assigns(:entries) |
|
638 | assert_include entry, assigns(:entries) | |
630 | end |
|
639 | end | |
631 | end |
|
640 | end | |
632 |
|
641 | |||
633 | def test_index_at_project_level_with_date_range |
|
642 | def test_index_at_project_level_with_date_range | |
634 | get :index, :project_id => 'ecookbook', |
|
643 | get :index, :project_id => 'ecookbook', | |
635 | :f => ['spent_on'], |
|
644 | :f => ['spent_on'], | |
636 | :op => {'spent_on' => '><'}, |
|
645 | :op => {'spent_on' => '><'}, | |
637 | :v => {'spent_on' => ['2007-03-20', '2007-04-30']} |
|
646 | :v => {'spent_on' => ['2007-03-20', '2007-04-30']} | |
638 | assert_response :success |
|
647 | assert_response :success | |
639 | assert_template 'index' |
|
648 | assert_template 'index' | |
640 | assert_not_nil assigns(:entries) |
|
649 | assert_not_nil assigns(:entries) | |
641 | assert_equal 3, assigns(:entries).size |
|
650 | assert_equal 3, assigns(:entries).size | |
642 | assert_not_nil assigns(:total_hours) |
|
651 | assert_not_nil assigns(:total_hours) | |
643 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
652 | assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
644 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
653 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
645 | end |
|
654 | end | |
646 |
|
655 | |||
647 | def test_index_at_project_level_with_date_range_using_from_and_to_params |
|
656 | def test_index_at_project_level_with_date_range_using_from_and_to_params | |
648 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' |
|
657 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' | |
649 | assert_response :success |
|
658 | assert_response :success | |
650 | assert_template 'index' |
|
659 | assert_template 'index' | |
651 | assert_not_nil assigns(:entries) |
|
660 | assert_not_nil assigns(:entries) | |
652 | assert_equal 3, assigns(:entries).size |
|
661 | assert_equal 3, assigns(:entries).size | |
653 | assert_not_nil assigns(:total_hours) |
|
662 | assert_not_nil assigns(:total_hours) | |
654 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
663 | assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
655 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
664 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
656 | end |
|
665 | end | |
657 |
|
666 | |||
658 | def test_index_at_project_level_with_period |
|
667 | def test_index_at_project_level_with_period | |
659 | get :index, :project_id => 'ecookbook', |
|
668 | get :index, :project_id => 'ecookbook', | |
660 | :f => ['spent_on'], |
|
669 | :f => ['spent_on'], | |
661 | :op => {'spent_on' => '>t-'}, |
|
670 | :op => {'spent_on' => '>t-'}, | |
662 | :v => {'spent_on' => ['7']} |
|
671 | :v => {'spent_on' => ['7']} | |
663 | assert_response :success |
|
672 | assert_response :success | |
664 | assert_template 'index' |
|
673 | assert_template 'index' | |
665 | assert_not_nil assigns(:entries) |
|
674 | assert_not_nil assigns(:entries) | |
666 | assert_not_nil assigns(:total_hours) |
|
675 | assert_not_nil assigns(:total_hours) | |
667 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' |
|
676 | assert_select 'form#query_form[action=?]', '/projects/ecookbook/time_entries' | |
668 | end |
|
677 | end | |
669 |
|
678 | |||
670 | def test_index_at_issue_level |
|
679 | def test_index_at_issue_level | |
671 | get :index, :issue_id => 1 |
|
680 | get :index, :issue_id => 1 | |
672 | assert_response :success |
|
681 | assert_response :success | |
673 | assert_template 'index' |
|
682 | assert_template 'index' | |
674 | assert_not_nil assigns(:entries) |
|
683 | assert_not_nil assigns(:entries) | |
675 | assert_equal 2, assigns(:entries).size |
|
684 | assert_equal 2, assigns(:entries).size | |
676 | assert_not_nil assigns(:total_hours) |
|
685 | assert_not_nil assigns(:total_hours) | |
677 | assert_equal 154.25, assigns(:total_hours) |
|
686 | assert_equal 154.25, assigns(:total_hours) | |
678 | # display all time |
|
687 | # display all time | |
679 | assert_nil assigns(:from) |
|
688 | assert_nil assigns(:from) | |
680 | assert_nil assigns(:to) |
|
689 | assert_nil assigns(:to) | |
681 | assert_select 'form#query_form[action=?]', '/issues/1/time_entries' |
|
690 | assert_select 'form#query_form[action=?]', '/issues/1/time_entries' | |
682 | end |
|
691 | end | |
683 |
|
692 | |||
684 | def test_index_should_sort_by_spent_on_and_created_on |
|
693 | def test_index_should_sort_by_spent_on_and_created_on | |
685 | 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) |
|
694 | 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) | |
686 | 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) |
|
695 | 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) | |
687 | 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) |
|
696 | 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) | |
688 |
|
697 | |||
689 | get :index, :project_id => 1, |
|
698 | get :index, :project_id => 1, | |
690 | :f => ['spent_on'], |
|
699 | :f => ['spent_on'], | |
691 | :op => {'spent_on' => '><'}, |
|
700 | :op => {'spent_on' => '><'}, | |
692 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']} |
|
701 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']} | |
693 | assert_response :success |
|
702 | assert_response :success | |
694 | assert_equal [t2, t1, t3], assigns(:entries) |
|
703 | assert_equal [t2, t1, t3], assigns(:entries) | |
695 |
|
704 | |||
696 | get :index, :project_id => 1, |
|
705 | get :index, :project_id => 1, | |
697 | :f => ['spent_on'], |
|
706 | :f => ['spent_on'], | |
698 | :op => {'spent_on' => '><'}, |
|
707 | :op => {'spent_on' => '><'}, | |
699 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, |
|
708 | :v => {'spent_on' => ['2012-06-15', '2012-06-16']}, | |
700 | :sort => 'spent_on' |
|
709 | :sort => 'spent_on' | |
701 | assert_response :success |
|
710 | assert_response :success | |
702 | assert_equal [t3, t1, t2], assigns(:entries) |
|
711 | assert_equal [t3, t1, t2], assigns(:entries) | |
703 | end |
|
712 | end | |
704 |
|
713 | |||
705 | def test_index_with_filter_on_issue_custom_field |
|
714 | def test_index_with_filter_on_issue_custom_field | |
706 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) |
|
715 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
707 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) |
|
716 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
708 |
|
717 | |||
709 | get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} |
|
718 | get :index, :f => ['issue.cf_2'], :op => {'issue.cf_2' => '='}, :v => {'issue.cf_2' => ['filter_on_issue_custom_field']} | |
710 | assert_response :success |
|
719 | assert_response :success | |
711 | assert_equal [entry], assigns(:entries) |
|
720 | assert_equal [entry], assigns(:entries) | |
712 | end |
|
721 | end | |
713 |
|
722 | |||
714 | def test_index_with_issue_custom_field_column |
|
723 | def test_index_with_issue_custom_field_column | |
715 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) |
|
724 | issue = Issue.generate!(:project_id => 1, :tracker_id => 1, :custom_field_values => {2 => 'filter_on_issue_custom_field'}) | |
716 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) |
|
725 | entry = TimeEntry.generate!(:issue => issue, :hours => 2.5) | |
717 |
|
726 | |||
718 | get :index, :c => %w(project spent_on issue comments hours issue.cf_2) |
|
727 | get :index, :c => %w(project spent_on issue comments hours issue.cf_2) | |
719 | assert_response :success |
|
728 | assert_response :success | |
720 | assert_include :'issue.cf_2', assigns(:query).column_names |
|
729 | assert_include :'issue.cf_2', assigns(:query).column_names | |
721 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' |
|
730 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' | |
722 | end |
|
731 | end | |
723 |
|
732 | |||
724 | def test_index_with_time_entry_custom_field_column |
|
733 | def test_index_with_time_entry_custom_field_column | |
725 | field = TimeEntryCustomField.generate!(:field_format => 'string') |
|
734 | field = TimeEntryCustomField.generate!(:field_format => 'string') | |
726 | entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'}) |
|
735 | entry = TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value'}) | |
727 | field_name = "cf_#{field.id}" |
|
736 | field_name = "cf_#{field.id}" | |
728 |
|
737 | |||
729 | get :index, :c => ["hours", field_name] |
|
738 | get :index, :c => ["hours", field_name] | |
730 | assert_response :success |
|
739 | assert_response :success | |
731 | assert_include field_name.to_sym, assigns(:query).column_names |
|
740 | assert_include field_name.to_sym, assigns(:query).column_names | |
732 | assert_select "td.#{field_name}", :text => 'CF Value' |
|
741 | assert_select "td.#{field_name}", :text => 'CF Value' | |
733 | end |
|
742 | end | |
734 |
|
743 | |||
735 | def test_index_with_time_entry_custom_field_sorting |
|
744 | def test_index_with_time_entry_custom_field_sorting | |
736 | field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field') |
|
745 | field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field') | |
737 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'}) |
|
746 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'}) | |
738 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'}) |
|
747 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'}) | |
739 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'}) |
|
748 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'}) | |
740 | field_name = "cf_#{field.id}" |
|
749 | field_name = "cf_#{field.id}" | |
741 |
|
750 | |||
742 | get :index, :c => ["hours", field_name], :sort => field_name |
|
751 | get :index, :c => ["hours", field_name], :sort => field_name | |
743 | assert_response :success |
|
752 | assert_response :success | |
744 | assert_include field_name.to_sym, assigns(:query).column_names |
|
753 | assert_include field_name.to_sym, assigns(:query).column_names | |
745 | assert_select "th a.sort", :text => 'String Field' |
|
754 | assert_select "th a.sort", :text => 'String Field' | |
746 |
|
755 | |||
747 | # Make sure that values are properly sorted |
|
756 | # Make sure that values are properly sorted | |
748 | values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact |
|
757 | values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact | |
749 | assert_equal 3, values.size |
|
758 | assert_equal 3, values.size | |
750 | assert_equal values.sort, values |
|
759 | assert_equal values.sort, values | |
751 | end |
|
760 | end | |
752 |
|
761 | |||
753 | def test_index_atom_feed |
|
762 | def test_index_atom_feed | |
754 | get :index, :project_id => 1, :format => 'atom' |
|
763 | get :index, :project_id => 1, :format => 'atom' | |
755 | assert_response :success |
|
764 | assert_response :success | |
756 | assert_equal 'application/atom+xml', @response.content_type |
|
765 | assert_equal 'application/atom+xml', @response.content_type | |
757 | assert_not_nil assigns(:items) |
|
766 | assert_not_nil assigns(:items) | |
758 | assert assigns(:items).first.is_a?(TimeEntry) |
|
767 | assert assigns(:items).first.is_a?(TimeEntry) | |
759 | end |
|
768 | end | |
760 |
|
769 | |||
761 | def test_index_at_project_level_should_include_csv_export_dialog |
|
770 | def test_index_at_project_level_should_include_csv_export_dialog | |
762 | get :index, :project_id => 'ecookbook', |
|
771 | get :index, :project_id => 'ecookbook', | |
763 | :f => ['spent_on'], |
|
772 | :f => ['spent_on'], | |
764 | :op => {'spent_on' => '>='}, |
|
773 | :op => {'spent_on' => '>='}, | |
765 | :v => {'spent_on' => ['2007-04-01']}, |
|
774 | :v => {'spent_on' => ['2007-04-01']}, | |
766 | :c => ['spent_on', 'user'] |
|
775 | :c => ['spent_on', 'user'] | |
767 | assert_response :success |
|
776 | assert_response :success | |
768 |
|
777 | |||
769 | assert_select '#csv-export-options' do |
|
778 | assert_select '#csv-export-options' do | |
770 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do |
|
779 | assert_select 'form[action=?][method=get]', '/projects/ecookbook/time_entries.csv' do | |
771 | # filter |
|
780 | # filter | |
772 | assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' |
|
781 | assert_select 'input[name=?][value=?]', 'f[]', 'spent_on' | |
773 | assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' |
|
782 | assert_select 'input[name=?][value=?]', 'op[spent_on]', '>=' | |
774 | assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' |
|
783 | assert_select 'input[name=?][value=?]', 'v[spent_on][]', '2007-04-01' | |
775 | # columns |
|
784 | # columns | |
776 | assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' |
|
785 | assert_select 'input[name=?][value=?]', 'c[]', 'spent_on' | |
777 | assert_select 'input[name=?][value=?]', 'c[]', 'user' |
|
786 | assert_select 'input[name=?][value=?]', 'c[]', 'user' | |
778 | assert_select 'input[name=?]', 'c[]', 2 |
|
787 | assert_select 'input[name=?]', 'c[]', 2 | |
779 | end |
|
788 | end | |
780 | end |
|
789 | end | |
781 | end |
|
790 | end | |
782 |
|
791 | |||
783 | def test_index_cross_project_should_include_csv_export_dialog |
|
792 | def test_index_cross_project_should_include_csv_export_dialog | |
784 | get :index |
|
793 | get :index | |
785 | assert_response :success |
|
794 | assert_response :success | |
786 |
|
795 | |||
787 | assert_select '#csv-export-options' do |
|
796 | assert_select '#csv-export-options' do | |
788 | assert_select 'form[action=?][method=get]', '/time_entries.csv' |
|
797 | assert_select 'form[action=?][method=get]', '/time_entries.csv' | |
789 | end |
|
798 | end | |
790 | end |
|
799 | end | |
791 |
|
800 | |||
792 | def test_index_at_issue_level_should_include_csv_export_dialog |
|
801 | def test_index_at_issue_level_should_include_csv_export_dialog | |
793 | get :index, :issue_id => 3 |
|
802 | get :index, :issue_id => 3 | |
794 | assert_response :success |
|
803 | assert_response :success | |
795 |
|
804 | |||
796 | assert_select '#csv-export-options' do |
|
805 | assert_select '#csv-export-options' do | |
797 | assert_select 'form[action=?][method=get]', '/issues/3/time_entries.csv' |
|
806 | assert_select 'form[action=?][method=get]', '/issues/3/time_entries.csv' | |
798 | end |
|
807 | end | |
799 | end |
|
808 | end | |
800 |
|
809 | |||
801 | def test_index_csv_all_projects |
|
810 | def test_index_csv_all_projects | |
802 | with_settings :date_format => '%m/%d/%Y' do |
|
811 | with_settings :date_format => '%m/%d/%Y' do | |
803 | get :index, :format => 'csv' |
|
812 | get :index, :format => 'csv' | |
804 | assert_response :success |
|
813 | assert_response :success | |
805 | assert_equal 'text/csv; header=present', response.content_type |
|
814 | assert_equal 'text/csv; header=present', response.content_type | |
806 | end |
|
815 | end | |
807 | end |
|
816 | end | |
808 |
|
817 | |||
809 | def test_index_csv |
|
818 | def test_index_csv | |
810 | with_settings :date_format => '%m/%d/%Y' do |
|
819 | with_settings :date_format => '%m/%d/%Y' do | |
811 | get :index, :project_id => 1, :format => 'csv' |
|
820 | get :index, :project_id => 1, :format => 'csv' | |
812 | assert_response :success |
|
821 | assert_response :success | |
813 | assert_equal 'text/csv; header=present', response.content_type |
|
822 | assert_equal 'text/csv; header=present', response.content_type | |
814 | end |
|
823 | end | |
815 | end |
|
824 | end | |
816 |
|
825 | |||
817 | def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject |
|
826 | def test_index_csv_should_fill_issue_column_with_tracker_id_and_subject | |
818 | issue = Issue.find(1) |
|
827 | issue = Issue.find(1) | |
819 | entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test") |
|
828 | entry = TimeEntry.generate!(:issue => issue, :comments => "Issue column content test") | |
820 |
|
829 | |||
821 | get :index, :format => 'csv' |
|
830 | get :index, :format => 'csv' | |
822 | line = response.body.split("\n").detect {|l| l.include?(entry.comments)} |
|
831 | line = response.body.split("\n").detect {|l| l.include?(entry.comments)} | |
823 | assert_not_nil line |
|
832 | assert_not_nil line | |
824 | assert_include "#{issue.tracker} #1: #{issue.subject}", line |
|
833 | assert_include "#{issue.tracker} #1: #{issue.subject}", line | |
825 | end |
|
834 | end | |
826 | end |
|
835 | end |
General Comments 0
You need to be logged in to leave comments.
Login now