Parent

Class/Module Index [+]

Quicksearch

Merb::Test::MultipartRequestHelper::Post

Public Class Methods

new(params = {}) click to toggle source

Parameters

params<Hash>

Optional params for the controller.

# File lib/merb-core/test/helpers/multipart_request_helper.rb, line 50
def initialize(params = {})
  @multipart_params = []
  push_params(params)
end

Public Instance Methods

push_params(params, prefix = nil) click to toggle source

Saves the params in an array of multipart params as Param and FileParam objects.

Parameters

params<Hash>

The params to add to the multipart params.

prefix<~to_s>

An optional prefix for the request string keys.

# File lib/merb-core/test/helpers/multipart_request_helper.rb, line 61
def push_params(params, prefix = nil)
  params.sort_by {|k| k.to_s}.each do |key, value|
    param_key = prefix.nil? ? key : "#{prefix}[#{key}]"
    if value.respond_to?(:read)
      @multipart_params << FileParam.new(param_key, value.path, value.read)
    else
      if value.is_a?(Hash) || value.is_a?(Mash)
        push_params(value, param_key)
      elsif value.is_a?(Array)
        value.each { |v| push_params(v, "#{param_key}[]") }
      else
        @multipart_params << Param.new(param_key, value)
      end
    end
  end
end
to_multipart() click to toggle source

Returns

Array[String, String]

The query and the content type.

# File lib/merb-core/test/helpers/multipart_request_helper.rb, line 80
def to_multipart
  query = @multipart_params.collect { |param| "--" + BOUNDARY + "\r\n" + param.to_multipart }.join("") + "--" + BOUNDARY + "--"
  return query, CONTENT_TYPE
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.