Changeset 8978
- Timestamp:
- 03/03/08 06:42:24 (3 months ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/integration.rb (modified) (4 diffs)
- trunk/actionpack/test/controller/integration_upload_test.rb (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r8976 r8978 1 1 *SVN* 2 3 * Allow file uploads in Integration Tests. Closes #11091 [RubyRedRick] 2 4 3 5 * Refactor partial rendering into a PartialTemplate class. [Pratik] trunk/actionpack/lib/action_controller/integration.rb
r8483 r8978 56 56 attr_accessor :request_count 57 57 58 class MultiPartNeededException < Exception 59 end 60 58 61 # Create and initialize a new +Session+ instance. 59 62 def initialize … … 295 298 parse_result 296 299 return status 300 rescue MultiPartNeededException 301 boundary = "----------XnJLe9ZIbbGUYtzPQJ16u1" 302 status = process(method, path, multipart_body(parameters, boundary), (headers || {}).merge({"CONTENT_TYPE" => "multipart/form-data; boundary=#{boundary}"})) 303 return status 297 304 end 298 305 … … 343 350 # be a string, +nil+, or a Hash. 344 351 def requestify(parameters, prefix=nil) 345 if Hash === parameters 352 if TestUploadedFile === parameters 353 raise MultiPartNeededException 354 elsif Hash === parameters 346 355 return nil if parameters.empty? 347 356 parameters.map { |k,v| requestify(v, name_with_prefix(prefix, k)) }.join("&") … … 353 362 "#{CGI.escape(prefix)}=#{CGI.escape(parameters.to_s)}" 354 363 end 364 end 365 366 def multipart_requestify(params, first=true) 367 returning Hash.new do |p| 368 params.each do |key, value| 369 k = first ? CGI.escape(key.to_s) : "[#{CGI.escape(key.to_s)}]" 370 if Hash === value 371 multipart_requestify(value, false).each do |subkey, subvalue| 372 p[k + subkey] = subvalue 373 end 374 else 375 p[k] = value 376 end 377 end 378 end 379 end 380 381 def multipart_body(params, boundary) 382 multipart_requestify(params).map do |key, value| 383 if value.respond_to?(:original_filename) 384 File.open(value.path) do |f| 385 <<-EOF 386 --#{boundary}\r 387 Content-Disposition: form-data; name="#{key}"; filename="#{CGI.escape(value.original_filename)}"\r 388 Content-Type: #{value.content_type}\r 389 Content-Length: #{File.stat(value.path).size}\r 390 \r 391 #{f.read}\r 392 EOF 393 end 394 else 395 <<-EOF 396 --#{boundary}\r 397 Content-Disposition: form-data; name="#{key}"\r 398 \r 399 #{value}\r 400 EOF 401 end 402 end.join("")+"--#{boundary}--\r" 355 403 end 356 404 end