37 |
37 |
# add then remove 2 attachments to an issue
|
38 |
38 |
def test_issue_attachements
|
39 |
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 |
40 |
|
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
|
|
41 |
post "issues/add_attachment/1", { 'attachments[]' => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain') }
|
62 |
42 |
assert_redirected_to "issues/show/1"
|
63 |
43 |
|
64 |
44 |
# make sure attachment was saved
|
65 |
|
attachment = Issue.find(1).attachments.find_by_filename(file_name_1)
|
|
45 |
attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
|
66 |
46 |
assert_kind_of Attachment, attachment
|
67 |
47 |
assert_equal Issue.find(1), attachment.container
|
68 |
48 |
# verify the size of the attachment stored in db
|
69 |
|
assert_equal file_data_1.length, attachment.filesize
|
|
49 |
#assert_equal file_data_1.length, attachment.filesize
|
70 |
50 |
# verify that the attachment was written to disk
|
71 |
51 |
assert File.exist?(attachment.diskfile)
|
72 |
52 |
|
file upload test now uses ActionController::TestUploadedFile