@@ -1,440 +1,510 | |||||
1 | # -*- coding: utf-8 -*- |
|
1 | # -*- coding: utf-8 -*- | |
2 | # Redmine - project management software |
|
2 | # Redmine - project management software | |
3 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | # Copyright (C) 2006-2011 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 | |||
|
32 | ||||
31 | def setup |
|
33 | def setup | |
32 | @controller = TimelogController.new |
|
34 | @controller = TimelogController.new | |
33 | @request = ActionController::TestRequest.new |
|
35 | @request = ActionController::TestRequest.new | |
34 | @response = ActionController::TestResponse.new |
|
36 | @response = ActionController::TestResponse.new | |
35 | end |
|
37 | end | |
36 |
|
38 | |||
37 | def test_get_new |
|
39 | def test_get_new | |
38 | @request.session[:user_id] = 3 |
|
40 | @request.session[:user_id] = 3 | |
39 | get :new, :project_id => 1 |
|
41 | get :new, :project_id => 1 | |
40 | assert_response :success |
|
42 | assert_response :success | |
41 | assert_template 'edit' |
|
43 | assert_template 'edit' | |
42 | # Default activity selected |
|
44 | # Default activity selected | |
43 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, |
|
45 | assert_tag :tag => 'option', :attributes => { :selected => 'selected' }, | |
44 | :content => 'Development' |
|
46 | :content => 'Development' | |
45 | end |
|
47 | end | |
46 |
|
48 | |||
47 | def test_get_new_should_only_show_active_time_entry_activities |
|
49 | def test_get_new_should_only_show_active_time_entry_activities | |
48 | @request.session[:user_id] = 3 |
|
50 | @request.session[:user_id] = 3 | |
49 | get :new, :project_id => 1 |
|
51 | get :new, :project_id => 1 | |
50 | assert_response :success |
|
52 | assert_response :success | |
51 | assert_template 'edit' |
|
53 | assert_template 'edit' | |
52 | assert_no_tag :tag => 'option', :content => 'Inactive Activity' |
|
54 | assert_no_tag :tag => 'option', :content => 'Inactive Activity' | |
53 | end |
|
55 | end | |
54 |
|
56 | |||
55 | def test_get_edit_existing_time |
|
57 | def test_get_edit_existing_time | |
56 | @request.session[:user_id] = 2 |
|
58 | @request.session[:user_id] = 2 | |
57 | get :edit, :id => 2, :project_id => nil |
|
59 | get :edit, :id => 2, :project_id => nil | |
58 | assert_response :success |
|
60 | assert_response :success | |
59 | assert_template 'edit' |
|
61 | assert_template 'edit' | |
60 | # Default activity selected |
|
62 | # Default activity selected | |
61 | assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' } |
|
63 | assert_tag :tag => 'form', :attributes => { :action => '/projects/ecookbook/time_entries/2' } | |
62 | end |
|
64 | end | |
63 |
|
65 | |||
64 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity |
|
66 | def test_get_edit_with_an_existing_time_entry_with_inactive_activity | |
65 | te = TimeEntry.find(1) |
|
67 | te = TimeEntry.find(1) | |
66 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") |
|
68 | te.activity = TimeEntryActivity.find_by_name("Inactive Activity") | |
67 | te.save! |
|
69 | te.save! | |
68 |
|
70 | |||
69 | @request.session[:user_id] = 1 |
|
71 | @request.session[:user_id] = 1 | |
70 | get :edit, :project_id => 1, :id => 1 |
|
72 | get :edit, :project_id => 1, :id => 1 | |
71 | assert_response :success |
|
73 | assert_response :success | |
72 | assert_template 'edit' |
|
74 | assert_template 'edit' | |
73 | # Blank option since nothing is pre-selected |
|
75 | # Blank option since nothing is pre-selected | |
74 | assert_tag :tag => 'option', :content => '--- Please select ---' |
|
76 | assert_tag :tag => 'option', :content => '--- Please select ---' | |
75 | end |
|
77 | end | |
76 |
|
78 | |||
77 | def test_post_create |
|
79 | def test_post_create | |
78 | # TODO: should POST to issuesβ time log instead of project. change form |
|
80 | # TODO: should POST to issuesβ time log instead of project. change form | |
79 | # and routing |
|
81 | # and routing | |
80 | @request.session[:user_id] = 3 |
|
82 | @request.session[:user_id] = 3 | |
81 | post :create, :project_id => 1, |
|
83 | post :create, :project_id => 1, | |
82 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
84 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
83 | # Not the default activity |
|
85 | # Not the default activity | |
84 | :activity_id => '11', |
|
86 | :activity_id => '11', | |
85 | :spent_on => '2008-03-14', |
|
87 | :spent_on => '2008-03-14', | |
86 | :issue_id => '1', |
|
88 | :issue_id => '1', | |
87 | :hours => '7.3'} |
|
89 | :hours => '7.3'} | |
88 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
90 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
89 |
|
91 | |||
90 | i = Issue.find(1) |
|
92 | i = Issue.find(1) | |
91 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
93 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') | |
92 | assert_not_nil t |
|
94 | assert_not_nil t | |
93 | assert_equal 11, t.activity_id |
|
95 | assert_equal 11, t.activity_id | |
94 | assert_equal 7.3, t.hours |
|
96 | assert_equal 7.3, t.hours | |
95 | assert_equal 3, t.user_id |
|
97 | assert_equal 3, t.user_id | |
96 | assert_equal i, t.issue |
|
98 | assert_equal i, t.issue | |
97 | assert_equal i.project, t.project |
|
99 | assert_equal i.project, t.project | |
98 | end |
|
100 | end | |
99 |
|
101 | |||
100 | def test_post_create_with_blank_issue |
|
102 | def test_post_create_with_blank_issue | |
101 | # TODO: should POST to issuesβ time log instead of project. change form |
|
103 | # TODO: should POST to issuesβ time log instead of project. change form | |
102 | # and routing |
|
104 | # and routing | |
103 | @request.session[:user_id] = 3 |
|
105 | @request.session[:user_id] = 3 | |
104 | post :create, :project_id => 1, |
|
106 | post :create, :project_id => 1, | |
105 | :time_entry => {:comments => 'Some work on TimelogControllerTest', |
|
107 | :time_entry => {:comments => 'Some work on TimelogControllerTest', | |
106 | # Not the default activity |
|
108 | # Not the default activity | |
107 | :activity_id => '11', |
|
109 | :activity_id => '11', | |
108 | :issue_id => '', |
|
110 | :issue_id => '', | |
109 | :spent_on => '2008-03-14', |
|
111 | :spent_on => '2008-03-14', | |
110 | :hours => '7.3'} |
|
112 | :hours => '7.3'} | |
111 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
113 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
112 |
|
114 | |||
113 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') |
|
115 | t = TimeEntry.find_by_comments('Some work on TimelogControllerTest') | |
114 | assert_not_nil t |
|
116 | assert_not_nil t | |
115 | assert_equal 11, t.activity_id |
|
117 | assert_equal 11, t.activity_id | |
116 | assert_equal 7.3, t.hours |
|
118 | assert_equal 7.3, t.hours | |
117 | assert_equal 3, t.user_id |
|
119 | assert_equal 3, t.user_id | |
118 | end |
|
120 | end | |
119 |
|
121 | |||
120 | def test_create_without_log_time_permission_should_be_denied |
|
122 | def test_create_without_log_time_permission_should_be_denied | |
121 | @request.session[:user_id] = 2 |
|
123 | @request.session[:user_id] = 2 | |
122 | Role.find_by_name('Manager').remove_permission! :log_time |
|
124 | Role.find_by_name('Manager').remove_permission! :log_time | |
123 | post :create, :project_id => 1, |
|
125 | post :create, :project_id => 1, | |
124 | :time_entry => {:activity_id => '11', |
|
126 | :time_entry => {:activity_id => '11', | |
125 | :issue_id => '', |
|
127 | :issue_id => '', | |
126 | :spent_on => '2008-03-14', |
|
128 | :spent_on => '2008-03-14', | |
127 | :hours => '7.3'} |
|
129 | :hours => '7.3'} | |
128 |
|
130 | |||
129 | assert_response 403 |
|
131 | assert_response 403 | |
130 | end |
|
132 | end | |
131 |
|
133 | |||
132 | def test_update |
|
134 | def test_update | |
133 | entry = TimeEntry.find(1) |
|
135 | entry = TimeEntry.find(1) | |
134 | assert_equal 1, entry.issue_id |
|
136 | assert_equal 1, entry.issue_id | |
135 | assert_equal 2, entry.user_id |
|
137 | assert_equal 2, entry.user_id | |
136 |
|
138 | |||
137 | @request.session[:user_id] = 1 |
|
139 | @request.session[:user_id] = 1 | |
138 | put :update, :id => 1, |
|
140 | put :update, :id => 1, | |
139 | :time_entry => {:issue_id => '2', |
|
141 | :time_entry => {:issue_id => '2', | |
140 | :hours => '8'} |
|
142 | :hours => '8'} | |
141 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
143 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
142 | entry.reload |
|
144 | entry.reload | |
143 |
|
145 | |||
144 | assert_equal 8, entry.hours |
|
146 | assert_equal 8, entry.hours | |
145 | assert_equal 2, entry.issue_id |
|
147 | assert_equal 2, entry.issue_id | |
146 | assert_equal 2, entry.user_id |
|
148 | assert_equal 2, entry.user_id | |
147 | end |
|
149 | end | |
148 |
|
150 | |||
149 | def test_get_bulk_edit |
|
151 | def test_get_bulk_edit | |
150 | @request.session[:user_id] = 2 |
|
152 | @request.session[:user_id] = 2 | |
151 | get :bulk_edit, :ids => [1, 2] |
|
153 | get :bulk_edit, :ids => [1, 2] | |
152 | assert_response :success |
|
154 | assert_response :success | |
153 | assert_template 'bulk_edit' |
|
155 | assert_template 'bulk_edit' | |
154 |
|
156 | |||
155 | # System wide custom field |
|
157 | # System wide custom field | |
156 | assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'} |
|
158 | assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'} | |
157 | end |
|
159 | end | |
158 |
|
160 | |||
159 | def test_get_bulk_edit_on_different_projects |
|
161 | def test_get_bulk_edit_on_different_projects | |
160 | @request.session[:user_id] = 2 |
|
162 | @request.session[:user_id] = 2 | |
161 | get :bulk_edit, :ids => [1, 2, 6] |
|
163 | get :bulk_edit, :ids => [1, 2, 6] | |
162 | assert_response :success |
|
164 | assert_response :success | |
163 | assert_template 'bulk_edit' |
|
165 | assert_template 'bulk_edit' | |
164 | end |
|
166 | end | |
165 |
|
167 | |||
166 | def test_bulk_update |
|
168 | def test_bulk_update | |
167 | @request.session[:user_id] = 2 |
|
169 | @request.session[:user_id] = 2 | |
168 | # update time entry activity |
|
170 | # update time entry activity | |
169 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} |
|
171 | post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9} | |
170 |
|
172 | |||
171 | assert_response 302 |
|
173 | assert_response 302 | |
172 | # check that the issues were updated |
|
174 | # check that the issues were updated | |
173 | assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id} |
|
175 | assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id} | |
174 | end |
|
176 | end | |
175 |
|
177 | |||
176 | def test_bulk_update_on_different_projects |
|
178 | def test_bulk_update_on_different_projects | |
177 | @request.session[:user_id] = 2 |
|
179 | @request.session[:user_id] = 2 | |
178 | # makes user a manager on the other project |
|
180 | # makes user a manager on the other project | |
179 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) |
|
181 | Member.create!(:user_id => 2, :project_id => 3, :role_ids => [1]) | |
180 |
|
182 | |||
181 | # update time entry activity |
|
183 | # update time entry activity | |
182 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } |
|
184 | post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 } | |
183 |
|
185 | |||
184 | assert_response 302 |
|
186 | assert_response 302 | |
185 | # check that the issues were updated |
|
187 | # check that the issues were updated | |
186 | assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id} |
|
188 | assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id} | |
187 | end |
|
189 | end | |
188 |
|
190 | |||
189 | def test_bulk_update_on_different_projects_without_rights |
|
191 | def test_bulk_update_on_different_projects_without_rights | |
190 | @request.session[:user_id] = 3 |
|
192 | @request.session[:user_id] = 3 | |
191 | user = User.find(3) |
|
193 | user = User.find(3) | |
192 | action = { :controller => "timelog", :action => "bulk_update" } |
|
194 | action = { :controller => "timelog", :action => "bulk_update" } | |
193 | assert user.allowed_to?(action, TimeEntry.find(1).project) |
|
195 | assert user.allowed_to?(action, TimeEntry.find(1).project) | |
194 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) |
|
196 | assert ! user.allowed_to?(action, TimeEntry.find(5).project) | |
195 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } |
|
197 | post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 } | |
196 | assert_response 403 |
|
198 | assert_response 403 | |
197 | end |
|
199 | end | |
198 |
|
200 | |||
199 | def test_bulk_update_custom_field |
|
201 | def test_bulk_update_custom_field | |
200 | @request.session[:user_id] = 2 |
|
202 | @request.session[:user_id] = 2 | |
201 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } |
|
203 | post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} } | |
202 |
|
204 | |||
203 | assert_response 302 |
|
205 | assert_response 302 | |
204 | assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value} |
|
206 | assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value} | |
205 | end |
|
207 | end | |
206 |
|
208 | |||
207 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter |
|
209 | def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter | |
208 | @request.session[:user_id] = 2 |
|
210 | @request.session[:user_id] = 2 | |
209 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' |
|
211 | post :bulk_update, :ids => [1,2], :back_url => '/time_entries' | |
210 |
|
212 | |||
211 | assert_response :redirect |
|
213 | assert_response :redirect | |
212 | assert_redirected_to '/time_entries' |
|
214 | assert_redirected_to '/time_entries' | |
213 | end |
|
215 | end | |
214 |
|
216 | |||
215 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host |
|
217 | def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host | |
216 | @request.session[:user_id] = 2 |
|
218 | @request.session[:user_id] = 2 | |
217 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' |
|
219 | post :bulk_update, :ids => [1,2], :back_url => 'http://google.com' | |
218 |
|
220 | |||
219 | assert_response :redirect |
|
221 | assert_response :redirect | |
220 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier |
|
222 | assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier | |
221 | end |
|
223 | end | |
222 |
|
224 | |||
223 | def test_post_bulk_update_without_edit_permission_should_be_denied |
|
225 | def test_post_bulk_update_without_edit_permission_should_be_denied | |
224 | @request.session[:user_id] = 2 |
|
226 | @request.session[:user_id] = 2 | |
225 | Role.find_by_name('Manager').remove_permission! :edit_time_entries |
|
227 | Role.find_by_name('Manager').remove_permission! :edit_time_entries | |
226 | post :bulk_update, :ids => [1,2] |
|
228 | post :bulk_update, :ids => [1,2] | |
227 |
|
229 | |||
228 | assert_response 403 |
|
230 | assert_response 403 | |
229 | end |
|
231 | end | |
230 |
|
232 | |||
231 | def test_destroy |
|
233 | def test_destroy | |
232 | @request.session[:user_id] = 2 |
|
234 | @request.session[:user_id] = 2 | |
233 | delete :destroy, :id => 1 |
|
235 | delete :destroy, :id => 1 | |
234 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
236 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
235 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] |
|
237 | assert_equal I18n.t(:notice_successful_delete), flash[:notice] | |
236 | assert_nil TimeEntry.find_by_id(1) |
|
238 | assert_nil TimeEntry.find_by_id(1) | |
237 | end |
|
239 | end | |
238 |
|
240 | |||
239 | def test_destroy_should_fail |
|
241 | def test_destroy_should_fail | |
240 | # simulate that this fails (e.g. due to a plugin), see #5700 |
|
242 | # simulate that this fails (e.g. due to a plugin), see #5700 | |
241 | TimeEntry.any_instance.expects(:destroy).returns(false) |
|
243 | TimeEntry.any_instance.expects(:destroy).returns(false) | |
242 |
|
244 | |||
243 | @request.session[:user_id] = 2 |
|
245 | @request.session[:user_id] = 2 | |
244 | delete :destroy, :id => 1 |
|
246 | delete :destroy, :id => 1 | |
245 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
247 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
246 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] |
|
248 | assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] | |
247 | assert_not_nil TimeEntry.find_by_id(1) |
|
249 | assert_not_nil TimeEntry.find_by_id(1) | |
248 | end |
|
250 | end | |
249 |
|
251 | |||
250 | def test_index_all_projects |
|
252 | def test_index_all_projects | |
251 | get :index |
|
253 | get :index | |
252 | assert_response :success |
|
254 | assert_response :success | |
253 | assert_template 'index' |
|
255 | assert_template 'index' | |
254 | assert_not_nil assigns(:total_hours) |
|
256 | assert_not_nil assigns(:total_hours) | |
255 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
257 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
256 | assert_tag :form, |
|
258 | assert_tag :form, | |
257 | :attributes => {:action => "/time_entries", :id => 'query_form'} |
|
259 | :attributes => {:action => "/time_entries", :id => 'query_form'} | |
258 | end |
|
260 | end | |
259 |
|
261 | |||
260 | def test_index_at_project_level |
|
262 | def test_index_at_project_level | |
261 | get :index, :project_id => 'ecookbook' |
|
263 | get :index, :project_id => 'ecookbook' | |
262 | assert_response :success |
|
264 | assert_response :success | |
263 | assert_template 'index' |
|
265 | assert_template 'index' | |
264 | assert_not_nil assigns(:entries) |
|
266 | assert_not_nil assigns(:entries) | |
265 | assert_equal 4, assigns(:entries).size |
|
267 | assert_equal 4, assigns(:entries).size | |
266 | # project and subproject |
|
268 | # project and subproject | |
267 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort |
|
269 | assert_equal [1, 3], assigns(:entries).collect(&:project_id).uniq.sort | |
268 | assert_not_nil assigns(:total_hours) |
|
270 | assert_not_nil assigns(:total_hours) | |
269 | assert_equal "162.90", "%.2f" % assigns(:total_hours) |
|
271 | assert_equal "162.90", "%.2f" % assigns(:total_hours) | |
270 | # display all time by default |
|
272 | # display all time by default | |
271 | assert_equal '2007-03-12'.to_date, assigns(:from) |
|
273 | assert_equal '2007-03-12'.to_date, assigns(:from) | |
272 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
274 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
273 | assert_tag :form, |
|
275 | assert_tag :form, | |
274 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
276 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
275 | end |
|
277 | end | |
276 |
|
278 | |||
277 | def test_index_at_project_level_with_date_range |
|
279 | def test_index_at_project_level_with_date_range | |
278 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' |
|
280 | get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30' | |
279 | assert_response :success |
|
281 | assert_response :success | |
280 | assert_template 'index' |
|
282 | assert_template 'index' | |
281 | assert_not_nil assigns(:entries) |
|
283 | assert_not_nil assigns(:entries) | |
282 | assert_equal 3, assigns(:entries).size |
|
284 | assert_equal 3, assigns(:entries).size | |
283 | assert_not_nil assigns(:total_hours) |
|
285 | assert_not_nil assigns(:total_hours) | |
284 | assert_equal "12.90", "%.2f" % assigns(:total_hours) |
|
286 | assert_equal "12.90", "%.2f" % assigns(:total_hours) | |
285 | assert_equal '2007-03-20'.to_date, assigns(:from) |
|
287 | assert_equal '2007-03-20'.to_date, assigns(:from) | |
286 | assert_equal '2007-04-30'.to_date, assigns(:to) |
|
288 | assert_equal '2007-04-30'.to_date, assigns(:to) | |
287 | assert_tag :form, |
|
289 | assert_tag :form, | |
288 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
290 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
289 | end |
|
291 | end | |
290 |
|
292 | |||
291 | def test_index_at_project_level_with_period |
|
293 | def test_index_at_project_level_with_period | |
292 | get :index, :project_id => 'ecookbook', :period => '7_days' |
|
294 | get :index, :project_id => 'ecookbook', :period => '7_days' | |
293 | assert_response :success |
|
295 | assert_response :success | |
294 | assert_template 'index' |
|
296 | assert_template 'index' | |
295 | assert_not_nil assigns(:entries) |
|
297 | assert_not_nil assigns(:entries) | |
296 | assert_not_nil assigns(:total_hours) |
|
298 | assert_not_nil assigns(:total_hours) | |
297 | assert_equal Date.today - 7, assigns(:from) |
|
299 | assert_equal Date.today - 7, assigns(:from) | |
298 | assert_equal Date.today, assigns(:to) |
|
300 | assert_equal Date.today, assigns(:to) | |
299 | assert_tag :form, |
|
301 | assert_tag :form, | |
300 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
302 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
301 | end |
|
303 | end | |
302 |
|
304 | |||
303 | def test_index_one_day |
|
305 | def test_index_one_day | |
304 | get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23" |
|
306 | get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23" | |
305 | assert_response :success |
|
307 | assert_response :success | |
306 | assert_template 'index' |
|
308 | assert_template 'index' | |
307 | assert_not_nil assigns(:total_hours) |
|
309 | assert_not_nil assigns(:total_hours) | |
308 | assert_equal "4.25", "%.2f" % assigns(:total_hours) |
|
310 | assert_equal "4.25", "%.2f" % assigns(:total_hours) | |
309 | assert_tag :form, |
|
311 | assert_tag :form, | |
310 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} |
|
312 | :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'} | |
311 | end |
|
313 | end | |
312 |
|
314 | |||
313 | def test_index_at_issue_level |
|
315 | def test_index_at_issue_level | |
314 | get :index, :issue_id => 1 |
|
316 | get :index, :issue_id => 1 | |
315 | assert_response :success |
|
317 | assert_response :success | |
316 | assert_template 'index' |
|
318 | assert_template 'index' | |
317 | assert_not_nil assigns(:entries) |
|
319 | assert_not_nil assigns(:entries) | |
318 | assert_equal 2, assigns(:entries).size |
|
320 | assert_equal 2, assigns(:entries).size | |
319 | assert_not_nil assigns(:total_hours) |
|
321 | assert_not_nil assigns(:total_hours) | |
320 | assert_equal 154.25, assigns(:total_hours) |
|
322 | assert_equal 154.25, assigns(:total_hours) | |
321 | # display all time based on what's been logged |
|
323 | # display all time based on what's been logged | |
322 | assert_equal '2007-03-12'.to_date, assigns(:from) |
|
324 | assert_equal '2007-03-12'.to_date, assigns(:from) | |
323 | assert_equal '2007-04-22'.to_date, assigns(:to) |
|
325 | assert_equal '2007-04-22'.to_date, assigns(:to) | |
324 | # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes |
|
326 | # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes | |
325 | # to use /issues/:issue_id/time_entries |
|
327 | # to use /issues/:issue_id/time_entries | |
326 | assert_tag :form, |
|
328 | assert_tag :form, | |
327 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} |
|
329 | :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'} | |
328 | end |
|
330 | end | |
329 |
|
331 | |||
330 | def test_index_atom_feed |
|
332 | def test_index_atom_feed | |
331 | get :index, :project_id => 1, :format => 'atom' |
|
333 | get :index, :project_id => 1, :format => 'atom' | |
332 | assert_response :success |
|
334 | assert_response :success | |
333 | assert_equal 'application/atom+xml', @response.content_type |
|
335 | assert_equal 'application/atom+xml', @response.content_type | |
334 | assert_not_nil assigns(:items) |
|
336 | assert_not_nil assigns(:items) | |
335 | assert assigns(:items).first.is_a?(TimeEntry) |
|
337 | assert assigns(:items).first.is_a?(TimeEntry) | |
336 | end |
|
338 | end | |
337 |
|
339 | |||
338 | def test_index_all_projects_csv_export |
|
340 | def test_index_all_projects_csv_export | |
339 | Setting.date_format = '%m/%d/%Y' |
|
341 | Setting.date_format = '%m/%d/%Y' | |
340 | get :index, :format => 'csv' |
|
342 | get :index, :format => 'csv' | |
341 | assert_response :success |
|
343 | assert_response :success | |
342 | assert_equal 'text/csv', @response.content_type |
|
344 | assert_equal 'text/csv', @response.content_type | |
343 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") |
|
345 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") | |
344 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") |
|
346 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") | |
345 | end |
|
347 | end | |
346 |
|
348 | |||
347 | def test_index_csv_export |
|
349 | def test_index_csv_export | |
348 | Setting.date_format = '%m/%d/%Y' |
|
350 | Setting.date_format = '%m/%d/%Y' | |
349 | get :index, :project_id => 1, :format => 'csv' |
|
351 | get :index, :project_id => 1, :format => 'csv' | |
350 | assert_response :success |
|
352 | assert_response :success | |
351 | assert_equal 'text/csv', @response.content_type |
|
353 | assert_equal 'text/csv', @response.content_type | |
352 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") |
|
354 | assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n") | |
353 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") |
|
355 | assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n") | |
354 | end |
|
356 | end | |
355 |
|
357 | |||
356 | def test_csv_big_5 |
|
358 | def test_csv_big_5 | |
357 | user = User.find_by_id(3) |
|
359 | user = User.find_by_id(3) | |
358 | user.language = "zh-TW" |
|
360 | user.language = "zh-TW" | |
359 | assert user.save |
|
361 | assert user.save | |
360 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" |
|
362 | str_utf8 = "\xe4\xb8\x80\xe6\x9c\x88" | |
361 | str_big5 = "\xa4@\xa4\xeb" |
|
363 | str_big5 = "\xa4@\xa4\xeb" | |
362 | if str_utf8.respond_to?(:force_encoding) |
|
364 | if str_utf8.respond_to?(:force_encoding) | |
363 | str_utf8.force_encoding('UTF-8') |
|
365 | str_utf8.force_encoding('UTF-8') | |
364 | str_big5.force_encoding('Big5') |
|
366 | str_big5.force_encoding('Big5') | |
365 | end |
|
367 | end | |
366 | @request.session[:user_id] = 3 |
|
368 | @request.session[:user_id] = 3 | |
367 | post :create, :project_id => 1, |
|
369 | post :create, :project_id => 1, | |
368 | :time_entry => {:comments => str_utf8, |
|
370 | :time_entry => {:comments => str_utf8, | |
369 | # Not the default activity |
|
371 | # Not the default activity | |
370 | :activity_id => '11', |
|
372 | :activity_id => '11', | |
371 | :issue_id => '', |
|
373 | :issue_id => '', | |
372 | :spent_on => '2011-11-10', |
|
374 | :spent_on => '2011-11-10', | |
373 | :hours => '7.3'} |
|
375 | :hours => '7.3'} | |
374 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
376 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
375 |
|
377 | |||
376 | t = TimeEntry.find_by_comments(str_utf8) |
|
378 | t = TimeEntry.find_by_comments(str_utf8) | |
377 | assert_not_nil t |
|
379 | assert_not_nil t | |
378 | assert_equal 11, t.activity_id |
|
380 | assert_equal 11, t.activity_id | |
379 | assert_equal 7.3, t.hours |
|
381 | assert_equal 7.3, t.hours | |
380 | assert_equal 3, t.user_id |
|
382 | assert_equal 3, t.user_id | |
381 |
|
383 | |||
382 | get :index, :project_id => 1, :format => 'csv', |
|
384 | get :index, :project_id => 1, :format => 'csv', | |
383 | :from => '2011-11-10', :to => '2011-11-10' |
|
385 | :from => '2011-11-10', :to => '2011-11-10' | |
384 | assert_response :success |
|
386 | assert_response :success | |
385 | assert_equal 'text/csv', @response.content_type |
|
387 | assert_equal 'text/csv', @response.content_type | |
386 | ar = @response.body.chomp.split("\n") |
|
388 | ar = @response.body.chomp.split("\n") | |
387 | s1 = "\xa4\xe9\xb4\xc1" |
|
389 | s1 = "\xa4\xe9\xb4\xc1" | |
388 | if str_utf8.respond_to?(:force_encoding) |
|
390 | if str_utf8.respond_to?(:force_encoding) | |
389 | s1.force_encoding('Big5') |
|
391 | s1.force_encoding('Big5') | |
390 | end |
|
392 | end | |
391 | assert ar[0].include?(s1) |
|
393 | assert ar[0].include?(s1) | |
392 | assert ar[1].include?(str_big5) |
|
394 | assert ar[1].include?(str_big5) | |
393 | end |
|
395 | end | |
394 |
|
396 | |||
395 | def test_csv_cannot_convert_should_be_replaced_big_5 |
|
397 | def test_csv_cannot_convert_should_be_replaced_big_5 | |
396 | user = User.find_by_id(3) |
|
398 | user = User.find_by_id(3) | |
397 | user.language = "zh-TW" |
|
399 | user.language = "zh-TW" | |
398 | assert user.save |
|
400 | assert user.save | |
399 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" |
|
401 | str_utf8 = "\xe4\xbb\xa5\xe5\x86\x85" | |
400 | if str_utf8.respond_to?(:force_encoding) |
|
402 | if str_utf8.respond_to?(:force_encoding) | |
401 | str_utf8.force_encoding('UTF-8') |
|
403 | str_utf8.force_encoding('UTF-8') | |
402 | end |
|
404 | end | |
403 | @request.session[:user_id] = 3 |
|
405 | @request.session[:user_id] = 3 | |
404 | post :create, :project_id => 1, |
|
406 | post :create, :project_id => 1, | |
405 | :time_entry => {:comments => str_utf8, |
|
407 | :time_entry => {:comments => str_utf8, | |
406 | # Not the default activity |
|
408 | # Not the default activity | |
407 | :activity_id => '11', |
|
409 | :activity_id => '11', | |
408 | :issue_id => '', |
|
410 | :issue_id => '', | |
409 | :spent_on => '2011-11-10', |
|
411 | :spent_on => '2011-11-10', | |
410 | :hours => '7.3'} |
|
412 | :hours => '7.3'} | |
411 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' |
|
413 | assert_redirected_to :action => 'index', :project_id => 'ecookbook' | |
412 |
|
414 | |||
413 | t = TimeEntry.find_by_comments(str_utf8) |
|
415 | t = TimeEntry.find_by_comments(str_utf8) | |
414 | assert_not_nil t |
|
416 | assert_not_nil t | |
415 | assert_equal 11, t.activity_id |
|
417 | assert_equal 11, t.activity_id | |
416 | assert_equal 7.3, t.hours |
|
418 | assert_equal 7.3, t.hours | |
417 | assert_equal 3, t.user_id |
|
419 | assert_equal 3, t.user_id | |
418 |
|
420 | |||
419 | get :index, :project_id => 1, :format => 'csv', |
|
421 | get :index, :project_id => 1, :format => 'csv', | |
420 | :from => '2011-11-10', :to => '2011-11-10' |
|
422 | :from => '2011-11-10', :to => '2011-11-10' | |
421 | assert_response :success |
|
423 | assert_response :success | |
422 | assert_equal 'text/csv', @response.content_type |
|
424 | assert_equal 'text/csv', @response.content_type | |
423 | ar = @response.body.chomp.split("\n") |
|
425 | ar = @response.body.chomp.split("\n") | |
424 | s1 = "\xa4\xe9\xb4\xc1" |
|
426 | s1 = "\xa4\xe9\xb4\xc1" | |
425 | if str_utf8.respond_to?(:force_encoding) |
|
427 | if str_utf8.respond_to?(:force_encoding) | |
426 | s1.force_encoding('Big5') |
|
428 | s1.force_encoding('Big5') | |
427 | end |
|
429 | end | |
428 | assert ar[0].include?(s1) |
|
430 | assert ar[0].include?(s1) | |
429 | s2 = ar[1].split(",")[8] |
|
431 | s2 = ar[1].split(",")[8] | |
430 | if s2.respond_to?(:force_encoding) |
|
432 | if s2.respond_to?(:force_encoding) | |
431 | s3 = "\xa5H?" |
|
433 | s3 = "\xa5H?" | |
432 | s3.force_encoding('Big5') |
|
434 | s3.force_encoding('Big5') | |
433 | assert_equal s3, s2 |
|
435 | assert_equal s3, s2 | |
434 | elsif RUBY_PLATFORM == 'java' |
|
436 | elsif RUBY_PLATFORM == 'java' | |
435 | assert_equal "??", s2 |
|
437 | assert_equal "??", s2 | |
436 | else |
|
438 | else | |
437 | assert_equal "\xa5H???", s2 |
|
439 | assert_equal "\xa5H???", s2 | |
438 | end |
|
440 | end | |
439 | end |
|
441 | end | |
|
442 | ||||
|
443 | def test_csv_tw | |||
|
444 | with_settings :default_language => "zh-TW" do | |||
|
445 | str1 = "test_csv_tw" | |||
|
446 | user = User.find_by_id(3) | |||
|
447 | te1 = TimeEntry.create(:spent_on => '2011-11-10', | |||
|
448 | :hours => 999.9, | |||
|
449 | :project => Project.find(1), | |||
|
450 | :user => user, | |||
|
451 | :activity => TimeEntryActivity.find_by_name('Design'), | |||
|
452 | :comments => str1) | |||
|
453 | te2 = TimeEntry.find_by_comments(str1) | |||
|
454 | assert_not_nil te2 | |||
|
455 | assert_equal 999.9, te2.hours | |||
|
456 | assert_equal 3, te2.user_id | |||
|
457 | ||||
|
458 | get :index, :project_id => 1, :format => 'csv', | |||
|
459 | :from => '2011-11-10', :to => '2011-11-10' | |||
|
460 | assert_response :success | |||
|
461 | assert_equal 'text/csv', @response.content_type | |||
|
462 | ||||
|
463 | ar = @response.body.chomp.split("\n") | |||
|
464 | s2 = ar[1].split(",")[7] | |||
|
465 | assert_equal '999.9', s2 | |||
|
466 | ||||
|
467 | str_tw = "Traditional Chinese (\xe7\xb9\x81\xe9\xab\x94\xe4\xb8\xad\xe6\x96\x87)" | |||
|
468 | if str_tw.respond_to?(:force_encoding) | |||
|
469 | str_tw.force_encoding('UTF-8') | |||
|
470 | end | |||
|
471 | assert_equal str_tw, l(:general_lang_name) | |||
|
472 | assert_equal ',', l(:general_csv_separator) | |||
|
473 | assert_equal '.', l(:general_csv_decimal_separator) | |||
|
474 | end | |||
|
475 | end | |||
|
476 | ||||
|
477 | def test_csv_fr | |||
|
478 | with_settings :default_language => "fr" do | |||
|
479 | str1 = "test_csv_fr" | |||
|
480 | user = User.find_by_id(3) | |||
|
481 | te1 = TimeEntry.create(:spent_on => '2011-11-10', | |||
|
482 | :hours => 999.9, | |||
|
483 | :project => Project.find(1), | |||
|
484 | :user => user, | |||
|
485 | :activity => TimeEntryActivity.find_by_name('Design'), | |||
|
486 | :comments => str1) | |||
|
487 | te2 = TimeEntry.find_by_comments(str1) | |||
|
488 | assert_not_nil te2 | |||
|
489 | assert_equal 999.9, te2.hours | |||
|
490 | assert_equal 3, te2.user_id | |||
|
491 | ||||
|
492 | get :index, :project_id => 1, :format => 'csv', | |||
|
493 | :from => '2011-11-10', :to => '2011-11-10' | |||
|
494 | assert_response :success | |||
|
495 | assert_equal 'text/csv', @response.content_type | |||
|
496 | ||||
|
497 | ar = @response.body.chomp.split("\n") | |||
|
498 | s2 = ar[1].split(";")[7] | |||
|
499 | assert_equal '999,9', s2 | |||
|
500 | ||||
|
501 | str_fr = "Fran\xc3\xa7ais" | |||
|
502 | if str_fr.respond_to?(:force_encoding) | |||
|
503 | str_fr.force_encoding('UTF-8') | |||
|
504 | end | |||
|
505 | assert_equal str_fr, l(:general_lang_name) | |||
|
506 | assert_equal ';', l(:general_csv_separator) | |||
|
507 | assert_equal ',', l(:general_csv_decimal_separator) | |||
|
508 | end | |||
|
509 | end | |||
440 | end |
|
510 | end |
General Comments 0
You need to be logged in to leave comments.
Login now