comparison test/functional/timelog_controller_test.rb @ 442:753f1380d6bc cannam

Merge from branch "redmine-1.2"
author Chris Cannam
date Mon, 06 Jun 2011 14:41:04 +0100
parents cbce1fd3b1b7
children cbb26bc654de
comparison
equal deleted inserted replaced
252:adc8466df404 442:753f1380d6bc
129 129
130 assert_equal 8, entry.hours 130 assert_equal 8, entry.hours
131 assert_equal 2, entry.issue_id 131 assert_equal 2, entry.issue_id
132 assert_equal 2, entry.user_id 132 assert_equal 2, entry.user_id
133 end 133 end
134
135 def test_get_bulk_edit
136 @request.session[:user_id] = 2
137 get :bulk_edit, :ids => [1, 2]
138 assert_response :success
139 assert_template 'bulk_edit'
140
141 # System wide custom field
142 assert_tag :select, :attributes => {:name => 'time_entry[custom_field_values][10]'}
143 end
144
145 def test_get_bulk_edit_on_different_projects
146 @request.session[:user_id] = 2
147 get :bulk_edit, :ids => [1, 2, 6]
148 assert_response :success
149 assert_template 'bulk_edit'
150 end
151
152 def test_bulk_update
153 @request.session[:user_id] = 2
154 # update time entry activity
155 post :bulk_update, :ids => [1, 2], :time_entry => { :activity_id => 9}
156
157 assert_response 302
158 # check that the issues were updated
159 assert_equal [9, 9], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.activity_id}
160 end
161
162 def test_bulk_update_on_different_projects
163 @request.session[:user_id] = 2
164 # update time entry activity
165 post :bulk_update, :ids => [1, 2, 4], :time_entry => { :activity_id => 9 }
166
167 assert_response 302
168 # check that the issues were updated
169 assert_equal [9, 9, 9], TimeEntry.find_all_by_id([1, 2, 4]).collect {|i| i.activity_id}
170 end
171
172 def test_bulk_update_on_different_projects_without_rights
173 @request.session[:user_id] = 3
174 user = User.find(3)
175 action = { :controller => "timelog", :action => "bulk_update" }
176 assert user.allowed_to?(action, TimeEntry.find(1).project)
177 assert ! user.allowed_to?(action, TimeEntry.find(5).project)
178 post :bulk_update, :ids => [1, 5], :time_entry => { :activity_id => 9 }
179 assert_response 403
180 end
181
182 def test_bulk_update_custom_field
183 @request.session[:user_id] = 2
184 post :bulk_update, :ids => [1, 2], :time_entry => { :custom_field_values => {'10' => '0'} }
185
186 assert_response 302
187 assert_equal ["0", "0"], TimeEntry.find_all_by_id([1, 2]).collect {|i| i.custom_value_for(10).value}
188 end
189
190 def test_post_bulk_update_should_redirect_back_using_the_back_url_parameter
191 @request.session[:user_id] = 2
192 post :bulk_update, :ids => [1,2], :back_url => '/time_entries'
193
194 assert_response :redirect
195 assert_redirected_to '/time_entries'
196 end
197
198 def test_post_bulk_update_should_not_redirect_back_using_the_back_url_parameter_off_the_host
199 @request.session[:user_id] = 2
200 post :bulk_update, :ids => [1,2], :back_url => 'http://google.com'
201
202 assert_response :redirect
203 assert_redirected_to :controller => 'timelog', :action => 'index', :project_id => Project.find(1).identifier
204 end
134 205
135 def test_destroy 206 def test_destroy
136 @request.session[:user_id] = 2 207 @request.session[:user_id] = 2
137 delete :destroy, :id => 1 208 delete :destroy, :id => 1
138 assert_redirected_to :action => 'index', :project_id => 'ecookbook' 209 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
140 assert_nil TimeEntry.find_by_id(1) 211 assert_nil TimeEntry.find_by_id(1)
141 end 212 end
142 213
143 def test_destroy_should_fail 214 def test_destroy_should_fail
144 # simulate that this fails (e.g. due to a plugin), see #5700 215 # simulate that this fails (e.g. due to a plugin), see #5700
145 TimeEntry.class_eval do 216 TimeEntry.any_instance.expects(:destroy).returns(false)
146 before_destroy :stop_callback_chain
147 def stop_callback_chain ; return false ; end
148 end
149 217
150 @request.session[:user_id] = 2 218 @request.session[:user_id] = 2
151 delete :destroy, :id => 1 219 delete :destroy, :id => 1
152 assert_redirected_to :action => 'index', :project_id => 'ecookbook' 220 assert_redirected_to :action => 'index', :project_id => 'ecookbook'
153 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error] 221 assert_equal I18n.t(:notice_unable_delete_time_entry), flash[:error]
154 assert_not_nil TimeEntry.find_by_id(1) 222 assert_not_nil TimeEntry.find_by_id(1)
155
156 # remove the simulation
157 TimeEntry.before_destroy.reject! {|callback| callback.method == :stop_callback_chain }
158 end 223 end
159 224
160 def test_index_all_projects 225 def test_index_all_projects
161 get :index 226 get :index
162 assert_response :success 227 assert_response :success
163 assert_template 'index' 228 assert_template 'index'
164 assert_not_nil assigns(:total_hours) 229 assert_not_nil assigns(:total_hours)
165 assert_equal "162.90", "%.2f" % assigns(:total_hours) 230 assert_equal "162.90", "%.2f" % assigns(:total_hours)
231 assert_tag :form,
232 :attributes => {:action => "/time_entries", :id => 'query_form'}
166 end 233 end
167 234
168 def test_index_at_project_level 235 def test_index_at_project_level
169 get :index, :project_id => 1 236 get :index, :project_id => 'ecookbook'
170 assert_response :success 237 assert_response :success
171 assert_template 'index' 238 assert_template 'index'
172 assert_not_nil assigns(:entries) 239 assert_not_nil assigns(:entries)
173 assert_equal 4, assigns(:entries).size 240 assert_equal 4, assigns(:entries).size
174 # project and subproject 241 # project and subproject
176 assert_not_nil assigns(:total_hours) 243 assert_not_nil assigns(:total_hours)
177 assert_equal "162.90", "%.2f" % assigns(:total_hours) 244 assert_equal "162.90", "%.2f" % assigns(:total_hours)
178 # display all time by default 245 # display all time by default
179 assert_equal '2007-03-12'.to_date, assigns(:from) 246 assert_equal '2007-03-12'.to_date, assigns(:from)
180 assert_equal '2007-04-22'.to_date, assigns(:to) 247 assert_equal '2007-04-22'.to_date, assigns(:to)
248 assert_tag :form,
249 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
181 end 250 end
182 251
183 def test_index_at_project_level_with_date_range 252 def test_index_at_project_level_with_date_range
184 get :index, :project_id => 1, :from => '2007-03-20', :to => '2007-04-30' 253 get :index, :project_id => 'ecookbook', :from => '2007-03-20', :to => '2007-04-30'
185 assert_response :success 254 assert_response :success
186 assert_template 'index' 255 assert_template 'index'
187 assert_not_nil assigns(:entries) 256 assert_not_nil assigns(:entries)
188 assert_equal 3, assigns(:entries).size 257 assert_equal 3, assigns(:entries).size
189 assert_not_nil assigns(:total_hours) 258 assert_not_nil assigns(:total_hours)
190 assert_equal "12.90", "%.2f" % assigns(:total_hours) 259 assert_equal "12.90", "%.2f" % assigns(:total_hours)
191 assert_equal '2007-03-20'.to_date, assigns(:from) 260 assert_equal '2007-03-20'.to_date, assigns(:from)
192 assert_equal '2007-04-30'.to_date, assigns(:to) 261 assert_equal '2007-04-30'.to_date, assigns(:to)
262 assert_tag :form,
263 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
193 end 264 end
194 265
195 def test_index_at_project_level_with_period 266 def test_index_at_project_level_with_period
196 get :index, :project_id => 1, :period => '7_days' 267 get :index, :project_id => 'ecookbook', :period => '7_days'
197 assert_response :success 268 assert_response :success
198 assert_template 'index' 269 assert_template 'index'
199 assert_not_nil assigns(:entries) 270 assert_not_nil assigns(:entries)
200 assert_not_nil assigns(:total_hours) 271 assert_not_nil assigns(:total_hours)
201 assert_equal Date.today - 7, assigns(:from) 272 assert_equal Date.today - 7, assigns(:from)
202 assert_equal Date.today, assigns(:to) 273 assert_equal Date.today, assigns(:to)
274 assert_tag :form,
275 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
203 end 276 end
204 277
205 def test_index_one_day 278 def test_index_one_day
206 get :index, :project_id => 1, :from => "2007-03-23", :to => "2007-03-23" 279 get :index, :project_id => 'ecookbook', :from => "2007-03-23", :to => "2007-03-23"
207 assert_response :success 280 assert_response :success
208 assert_template 'index' 281 assert_template 'index'
209 assert_not_nil assigns(:total_hours) 282 assert_not_nil assigns(:total_hours)
210 assert_equal "4.25", "%.2f" % assigns(:total_hours) 283 assert_equal "4.25", "%.2f" % assigns(:total_hours)
284 assert_tag :form,
285 :attributes => {:action => "/projects/ecookbook/time_entries", :id => 'query_form'}
211 end 286 end
212 287
213 def test_index_at_issue_level 288 def test_index_at_issue_level
214 get :index, :issue_id => 1 289 get :index, :issue_id => 1
215 assert_response :success 290 assert_response :success
219 assert_not_nil assigns(:total_hours) 294 assert_not_nil assigns(:total_hours)
220 assert_equal 154.25, assigns(:total_hours) 295 assert_equal 154.25, assigns(:total_hours)
221 # display all time based on what's been logged 296 # display all time based on what's been logged
222 assert_equal '2007-03-12'.to_date, assigns(:from) 297 assert_equal '2007-03-12'.to_date, assigns(:from)
223 assert_equal '2007-04-22'.to_date, assigns(:to) 298 assert_equal '2007-04-22'.to_date, assigns(:to)
299 # TODO: remove /projects/:project_id/issues/:issue_id/time_entries routes
300 # to use /issues/:issue_id/time_entries
301 assert_tag :form,
302 :attributes => {:action => "/projects/ecookbook/issues/1/time_entries", :id => 'query_form'}
224 end 303 end
225 304
226 def test_index_atom_feed 305 def test_index_atom_feed
227 get :index, :project_id => 1, :format => 'atom' 306 get :index, :project_id => 1, :format => 'atom'
228 assert_response :success 307 assert_response :success
234 def test_index_all_projects_csv_export 313 def test_index_all_projects_csv_export
235 Setting.date_format = '%m/%d/%Y' 314 Setting.date_format = '%m/%d/%Y'
236 get :index, :format => 'csv' 315 get :index, :format => 'csv'
237 assert_response :success 316 assert_response :success
238 assert_equal 'text/csv', @response.content_type 317 assert_equal 'text/csv', @response.content_type
239 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") 318 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
240 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") 319 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
241 end 320 end
242 321
243 def test_index_csv_export 322 def test_index_csv_export
244 Setting.date_format = '%m/%d/%Y' 323 Setting.date_format = '%m/%d/%Y'
245 get :index, :project_id => 1, :format => 'csv' 324 get :index, :project_id => 1, :format => 'csv'
246 assert_response :success 325 assert_response :success
247 assert_equal 'text/csv', @response.content_type 326 assert_equal 'text/csv', @response.content_type
248 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment\n") 327 assert @response.body.include?("Date,User,Activity,Project,Issue,Tracker,Subject,Hours,Comment,Overtime\n")
249 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\"\n") 328 assert @response.body.include?("\n04/21/2007,redMine Admin,Design,eCookbook,3,Bug,Error 281 when updating a recipe,1.0,\"\",\"\"\n")
250 end 329 end
251 end 330 end