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