##// END OF EJS Templates
file upload test now uses ActionController::TestUploadedFile...
Jean-Philippe Lang -
r248:5a241fd12e96
parent child
Show More
@@ -0,0 +1,1
1 this is a text file for upload tests No newline at end of file
@@ -37,36 +37,16 class IssuesTest < ActionController::IntegrationTest
37 # add then remove 2 attachments to an issue
37 # add then remove 2 attachments to an issue
38 def test_issue_attachements
38 def test_issue_attachements
39 log_user('jsmith', 'jsmith')
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 = [
41 post "issues/add_attachment/1", { 'attachments[]' => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain') }
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"
42 assert_redirected_to "issues/show/1"
63
43
64 # make sure attachment was saved
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 assert_kind_of Attachment, attachment
46 assert_kind_of Attachment, attachment
67 assert_equal Issue.find(1), attachment.container
47 assert_equal Issue.find(1), attachment.container
68 # verify the size of the attachment stored in db
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 # verify that the attachment was written to disk
50 # verify that the attachment was written to disk
71 assert File.exist?(attachment.diskfile)
51 assert File.exist?(attachment.diskfile)
72
52
@@ -53,3 +53,20 class Test::Unit::TestCase
53 assert_equal login, User.find(session[:user_id]).login
53 assert_equal login, User.find(session[:user_id]).login
54 end
54 end
55 end
55 end
56
57
58 # ActionController::TestUploadedFile bug
59 # see http://dev.rubyonrails.org/ticket/4635
60 class String
61 def original_filename
62 "testfile.txt"
63 end
64
65 def content_type
66 "text/plain"
67 end
68
69 def read
70 self.to_s
71 end
72 end No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now