Sha256: f451df9a77c055f04e51435304d3979425be66e4dd5fc6340cd7357126d7c12a

Contents?: true

Size: 1.75 KB

Versions: 21

Compression:

Stored size: 1.75 KB

Contents

module Merb::Test::MultipartRequestHelper
  
  def multipart_request(path, params = {}, env = {})
    multipart = Merb::Test::MultipartRequestHelper::Post.new(params)
    body, head = multipart.to_multipart
    env["CONTENT_TYPE"] = head
    env["CONTENT_LENGTH"] = body.size
    env[:input] = StringIO.new(body)
    request(path, env)
  end

  # An HTTP POST request that operates through the router and uses multipart
  # parameters.
  #
  # ==== Parameters
  # path<String>:: The path that should go to the router as the request uri.
  # params<Hash>::
  #   An optional hash that will end up as params in the controller instance.
  # env<Hash>::
  #   An optional hash that is passed to the fake request. Any request options
  #   should go here (see +fake_request+).
  # block<Proc>:: The block is executed in the context of the controller.
  #
  # ==== Notes
  # To include an uploaded file, put a file object as a value in params.
  def multipart_post(path, params = {}, env = {})
    env[:method] = "POST"
    multipart_request(path, params, env)
  end

  # An HTTP PUT request that operates through the router and uses multipart
  # parameters.
  #
  # ==== Parameters
  # path<String>:: The path that should go to the router as the request uri.
  # params<Hash>::
  #   An optional hash that will end up as params in the controller instance.
  # env<Hash>::
  #   An optional hash that is passed to the fake request. Any request options
  #   should go here (see +fake_request+).
  # block<Proc>:: The block is executed in the context of the controller.
  #
  # ==== Notes
  # To include an uplaoded file, put a file object as a value in params.
  def multipart_put(path, params = {}, env = {}, &block)
    env[:method] = "PUT"
    multipart_request(path, params, env)
  end
  
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
merb-core-1.1.3 lib/merb-core/two-oh.rb
merb-core-1.1.2 lib/merb-core/two-oh.rb
merb-core-1.1.1 lib/merb-core/two-oh.rb
merb-core-1.1.0 lib/merb-core/two-oh.rb
merb-core-1.1.0.rc1 lib/merb-core/two-oh.rb
merb-core-1.1.0.pre lib/merb-core/two-oh.rb
merb-core-1.0.15 lib/merb-core/two-oh.rb
merb-core-1.0.14 lib/merb-core/two-oh.rb
merb-core-1.0.13 lib/merb-core/two-oh.rb
merb-core-1.0.12 lib/merb-core/two-oh.rb
merb-core-1.0.10 lib/merb-core/two-oh.rb
merb-core-1.0.11 lib/merb-core/two-oh.rb
merb-core-1.0.6.1 lib/merb-core/two-oh.rb
merb-core-1.0.5 lib/merb-core/two-oh.rb
merb-core-1.0.4 lib/merb-core/two-oh.rb
merb-core-1.0.8.1 lib/merb-core/two-oh.rb
merb-core-1.0.7 lib/merb-core/two-oh.rb
merb-core-1.0.7.1 lib/merb-core/two-oh.rb
merb-core-1.0.6 lib/merb-core/two-oh.rb
merb-core-1.0.9 lib/merb-core/two-oh.rb