file upload test now uses ActionController::TestUploadedFile
git-svn-id: http://redmine.rubyforge.org/svn/trunk@251 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
840fcf2fa9
commit
5a241fd12e
|
@ -0,0 +1 @@
|
||||||
|
this is a text file for upload tests
|
|
@ -37,36 +37,16 @@ class IssuesTest < ActionController::IntegrationTest
|
||||||
# add then remove 2 attachments to an issue
|
# add then remove 2 attachments to an issue
|
||||||
def test_issue_attachements
|
def test_issue_attachements
|
||||||
log_user('jsmith', 'jsmith')
|
log_user('jsmith', 'jsmith')
|
||||||
|
|
||||||
file_data_1 = "some text...."
|
|
||||||
file_name_1 = "sometext.txt"
|
|
||||||
file_data_2 = "more text..."
|
|
||||||
file_name_2 = "moretext.txt"
|
|
||||||
|
|
||||||
boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
|
|
||||||
headers = { "Content-Type" => "multipart/form-data; boundary=#{boundary}" }
|
|
||||||
|
|
||||||
data = [
|
post "issues/add_attachment/1", { 'attachments[]' => ActionController::TestUploadedFile.new(Test::Unit::TestCase.fixture_path + '/files/testfile.txt', 'text/plain') }
|
||||||
"--" + boundary,
|
|
||||||
"Content-Disposition: form-data; name=\"attachments[]\"; filename=\"#{file_name_1}\"",
|
|
||||||
"Content-Type: text/plain",
|
|
||||||
"", file_data_1,
|
|
||||||
"--" + boundary,
|
|
||||||
"Content-Disposition: form-data; name=\"attachments[]\"; filename=\"#{file_name_2}\"",
|
|
||||||
"Content-Type: text/plain",
|
|
||||||
"", file_data_2,
|
|
||||||
"--" + boundary, ""
|
|
||||||
].join("\x0D\x0A")
|
|
||||||
|
|
||||||
post "issues/add_attachment/1", data, headers
|
|
||||||
assert_redirected_to "issues/show/1"
|
assert_redirected_to "issues/show/1"
|
||||||
|
|
||||||
# make sure attachment was saved
|
# make sure attachment was saved
|
||||||
attachment = Issue.find(1).attachments.find_by_filename(file_name_1)
|
attachment = Issue.find(1).attachments.find_by_filename("testfile.txt")
|
||||||
assert_kind_of Attachment, attachment
|
assert_kind_of Attachment, attachment
|
||||||
assert_equal Issue.find(1), attachment.container
|
assert_equal Issue.find(1), attachment.container
|
||||||
# verify the size of the attachment stored in db
|
# verify the size of the attachment stored in db
|
||||||
assert_equal file_data_1.length, attachment.filesize
|
#assert_equal file_data_1.length, attachment.filesize
|
||||||
# verify that the attachment was written to disk
|
# verify that the attachment was written to disk
|
||||||
assert File.exist?(attachment.diskfile)
|
assert File.exist?(attachment.diskfile)
|
||||||
|
|
||||||
|
|
|
@ -53,3 +53,20 @@ class Test::Unit::TestCase
|
||||||
assert_equal login, User.find(session[:user_id]).login
|
assert_equal login, User.find(session[:user_id]).login
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# ActionController::TestUploadedFile bug
|
||||||
|
# see http://dev.rubyonrails.org/ticket/4635
|
||||||
|
class String
|
||||||
|
def original_filename
|
||||||
|
"testfile.txt"
|
||||||
|
end
|
||||||
|
|
||||||
|
def content_type
|
||||||
|
"text/plain"
|
||||||
|
end
|
||||||
|
|
||||||
|
def read
|
||||||
|
self.to_s
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue