@@ -0,0 +1,78 | |||||
|
1 | require "#{File.dirname(__FILE__)}/../test_helper" | |||
|
2 | ||||
|
3 | class IssuesTest < ActionController::IntegrationTest | |||
|
4 | fixtures :projects, :users, :trackers, :issue_statuses, :issues, :permissions, :permissions_roles, :enumerations | |||
|
5 | ||||
|
6 | # create an issue | |||
|
7 | def test_add_issue | |||
|
8 | log_user('jsmith', 'jsmith') | |||
|
9 | get "projects/add_issue/1", :tracker_id => "1" | |||
|
10 | assert_response :success | |||
|
11 | assert_template "projects/add_issue" | |||
|
12 | ||||
|
13 | post "projects/add_issue/1", :tracker_id => "1", | |||
|
14 | :issue => { :start_date => "2006-12-26", | |||
|
15 | :priority_id => "3", | |||
|
16 | :subject => "new test issue", | |||
|
17 | :category_id => "", | |||
|
18 | :description => "new issue", | |||
|
19 | :done_ratio => "0", | |||
|
20 | :due_date => "", | |||
|
21 | :assigned_to_id => "" } | |||
|
22 | # find created issue | |||
|
23 | issue = Issue.find_by_subject("new test issue") | |||
|
24 | assert_kind_of Issue, issue | |||
|
25 | ||||
|
26 | # check redirection | |||
|
27 | assert_redirected_to "projects/list_issues/1" | |||
|
28 | follow_redirect! | |||
|
29 | assert assigns(:issues).include?(issue) | |||
|
30 | ||||
|
31 | # check issue attributes | |||
|
32 | assert_equal 'jsmith', issue.author.login | |||
|
33 | assert_equal 1, issue.project.id | |||
|
34 | assert_equal 1, issue.status.id | |||
|
35 | end | |||
|
36 | ||||
|
37 | # add then remove 2 attachments to an issue | |||
|
38 | def test_issue_attachements | |||
|
39 | log_user('jsmith', 'jsmith') | |||
|
40 | ||||
|
41 | file_data_1 = "some text...." | |||
|
42 | file_name_1 = "sometext.txt" | |||
|
43 | file_data_2 = "more text..." | |||
|
44 | file_name_2 = "moretext.txt" | |||
|
45 | ||||
|
46 | boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor" | |||
|
47 | headers = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" } | |||
|
48 | ||||
|
49 | data = [ | |||
|
50 | "--" + boundary, | |||
|
51 | "Content-Disposition: form-data; name=\"attachments[]\"; filename=\"#{file_name_1}\"", | |||
|
52 | "Content-Type: text/plain", | |||
|
53 | "", file_data_1, | |||
|
54 | "--" + boundary, | |||
|
55 | "Content-Disposition: form-data; name=\"attachments[]\"; filename=\"#{file_name_2}\"", | |||
|
56 | "Content-Type: text/plain", | |||
|
57 | "", file_data_2, | |||
|
58 | "--" + boundary, "" | |||
|
59 | ].join("\x0D\x0A") | |||
|
60 | ||||
|
61 | post "issues/add_attachment/1", data, headers | |||
|
62 | assert_redirected_to "issues/show/1" | |||
|
63 | ||||
|
64 | # make sure attachment was saved | |||
|
65 | attachment = Issue.find(1).attachments.find_by_filename(file_name_1) | |||
|
66 | assert_kind_of Attachment, attachment | |||
|
67 | assert_equal Issue.find(1), attachment.container | |||
|
68 | # verify the size of the attachment stored in db | |||
|
69 | assert_equal file_data_1.length, attachment.filesize | |||
|
70 | # verify that the attachment was written to disk | |||
|
71 | assert File.exist?(attachment.diskfile) | |||
|
72 | ||||
|
73 | # remove the attachments | |||
|
74 | Issue.find(1).attachments.each(&:destroy) | |||
|
75 | assert_equal 0, Issue.find(1).attachments.length | |||
|
76 | end | |||
|
77 | ||||
|
78 | end |
General Comments 0
You need to be logged in to leave comments.
Login now