| Class | Merb::Test::MultipartRequestHelper::Post |
| In: |
merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb
|
| Parent: | Object |
| BOUNDARY | = | '----------0xKhTmLbOuNdArY' |
| CONTENT_TYPE | = | "multipart/form-data, boundary=" + BOUNDARY |
Saves the params in an array of multipart params as Param and FileParam objects.
| params<Hash>: | The params to add to the multipart params. |
| prefix<~to_s>: | An optional prefix for the request string keys. |
# File merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb, line 62
62: def push_params(params, prefix = nil)
63: params.sort_by {|k| k.to_s}.each do |key, value|
64: param_key = prefix.nil? ? key : "#{prefix}[#{key}]"
65: if value.respond_to?(:read)
66: @multipart_params << FileParam.new(param_key, value.path, value.read)
67: else
68: if value.is_a?(Hash) || value.is_a?(Mash)
69: value.keys.each do |k|
70: push_params(value, param_key)
71: end
72: else
73: @multipart_params << Param.new(param_key, value)
74: end
75: end
76: end
77: end
| Array[String, String]: | The query and the content type. |
# File merb-core/lib/merb-core/test/helpers/multipart_request_helper.rb, line 81
81: def to_multipart
82: query = @multipart_params.collect { |param| "--" + BOUNDARY + "\r\n" + param.to_multipart }.join("") + "--" + BOUNDARY + "--"
83: return query, CONTENT_TYPE
84: end