| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  | require "#{File.dirname(__FILE__)}/../test_helper" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class IssuesTest < ActionController::IntegrationTest | 
					
						
							| 
									
										
										
										
											2008-01-20 21:29:51 +00:00
										 |  |  |   fixtures :projects,  | 
					
						
							|  |  |  |            :users, | 
					
						
							|  |  |  |            :trackers, | 
					
						
							|  |  |  |            :projects_trackers, | 
					
						
							|  |  |  |            :issue_statuses, | 
					
						
							|  |  |  |            :issues, | 
					
						
							|  |  |  |            :enumerations, | 
					
						
							|  |  |  |            :custom_fields, | 
					
						
							|  |  |  |            :custom_values, | 
					
						
							|  |  |  |            :custom_fields_trackers | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # create an issue | 
					
						
							|  |  |  |   def test_add_issue | 
					
						
							|  |  |  |     log_user('jsmith', 'jsmith') | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |     get 'projects/1/issues/new', :tracker_id => '1' | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |     assert_response :success | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |     assert_template 'issues/new' | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |      | 
					
						
							| 
									
										
										
										
											2008-01-20 11:30:57 +00:00
										 |  |  |     post 'projects/1/issues/new', :tracker_id => "1", | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |                                  :issue => { :start_date => "2006-12-26",  | 
					
						
							|  |  |  |                                              :priority_id => "3",  | 
					
						
							|  |  |  |                                              :subject => "new test issue",  | 
					
						
							|  |  |  |                                              :category_id => "",  | 
					
						
							|  |  |  |                                              :description => "new issue",  | 
					
						
							|  |  |  |                                              :done_ratio => "0", | 
					
						
							|  |  |  |                                              :due_date => "", | 
					
						
							| 
									
										
										
										
											2008-01-20 21:29:51 +00:00
										 |  |  |                                              :assigned_to_id => "" }, | 
					
						
							|  |  |  |                                  :custom_fields => {'2' => 'Value for field 2'} | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |     # find created issue | 
					
						
							|  |  |  |     issue = Issue.find_by_subject("new test issue") | 
					
						
							|  |  |  |     assert_kind_of Issue, issue | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # check redirection | 
					
						
							| 
									
										
										
										
											2008-03-15 11:27:46 +00:00
										 |  |  |     assert_redirected_to "issues/show" | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |     follow_redirect! | 
					
						
							| 
									
										
										
										
											2008-03-15 11:27:46 +00:00
										 |  |  |     assert_equal issue, assigns(:issue) | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # check issue attributes     | 
					
						
							|  |  |  |     assert_equal 'jsmith', issue.author.login | 
					
						
							|  |  |  |     assert_equal 1, issue.project.id | 
					
						
							|  |  |  |     assert_equal 1, issue.status.id | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # add then remove 2 attachments to an issue | 
					
						
							|  |  |  |   def test_issue_attachements | 
					
						
							|  |  |  |     log_user('jsmith', 'jsmith') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-09 16:11:18 +00:00
										 |  |  |     post 'issues/edit/1', | 
					
						
							| 
									
										
										
										
											2008-01-06 17:06:14 +00:00
										 |  |  |          :notes => 'Some notes', | 
					
						
							| 
									
										
										
										
											2008-02-29 19:46:58 +00:00
										 |  |  |          :attachments => {'1' => {'file' => test_uploaded_file('testfile.txt', 'text/plain'), 'description' => 'This is an attachment'}} | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |     assert_redirected_to "issues/show/1" | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     # make sure attachment was saved | 
					
						
							| 
									
										
										
										
											2007-02-18 11:41:39 +00:00
										 |  |  |     attachment = Issue.find(1).attachments.find_by_filename("testfile.txt") | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |     assert_kind_of Attachment, attachment | 
					
						
							|  |  |  |     assert_equal Issue.find(1), attachment.container | 
					
						
							| 
									
										
										
										
											2008-02-29 19:46:58 +00:00
										 |  |  |     assert_equal 'This is an attachment', attachment.description | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |     # verify the size of the attachment stored in db | 
					
						
							| 
									
										
										
										
											2007-02-18 11:41:39 +00:00
										 |  |  |     #assert_equal file_data_1.length, attachment.filesize | 
					
						
							| 
									
										
										
										
											2006-12-26 20:14:03 +00:00
										 |  |  |     # verify that the attachment was written to disk | 
					
						
							|  |  |  |     assert File.exist?(attachment.diskfile) | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     # remove the attachments | 
					
						
							|  |  |  |     Issue.find(1).attachments.each(&:destroy) | 
					
						
							|  |  |  |     assert_equal 0, Issue.find(1).attachments.length | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | end |