From 571e0c509aa66da0838c7d9c79baba5a33ca7234 Mon Sep 17 00:00:00 2001 From: Matt Kelly Date: Thu, 27 May 2021 23:53:48 -0400 Subject: [PATCH] WIP: Verify no boundary desired between 'pairs' --- lib/http/form_data/multipart.rb | 4 ++-- lib/http/form_data/multipart/param.rb | 14 +++++--------- spec/lib/http/form_data/multipart_spec.rb | 4 ++-- spec/spec_helper.rb | 2 ++ 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/http/form_data/multipart.rb b/lib/http/form_data/multipart.rb index d6f1bf7..b7c387e 100644 --- a/lib/http/form_data/multipart.rb +++ b/lib/http/form_data/multipart.rb @@ -54,8 +54,8 @@ def tail end def parts(data) - return Param.coerce FormData.ensure_hash data if @params.is_a?(Hash) - Param.coerce_array_of_pairs data + return Param.coerce_array_of_pairs data if data.is_a?(Array) + Param.coerce FormData.ensure_hash data end end end diff --git a/lib/http/form_data/multipart/param.rb b/lib/http/form_data/multipart/param.rb index beddbd0..0b19b22 100644 --- a/lib/http/form_data/multipart/param.rb +++ b/lib/http/form_data/multipart/param.rb @@ -31,14 +31,12 @@ class Param # @param [FormData::File, FormData::Part, #to_s] value def initialize(name, value) @name = name.to_s - @part = if value.is_a?(FormData::Part) value else FormData::Part.new(value) end - @io = CompositeIO.new [header, @part, footer] end @@ -52,12 +50,10 @@ def self.coerce(data) params = [] data.each do |name, values| - binding.pry Array(values).each do |value| params << new(name, value) end end - params end @@ -70,11 +66,11 @@ def self.coerce(data) def self.coerce_array_of_pairs(data) params = [] - data.each_slice(2) do |first, second| - binding.pry - params << new(first[0], first[1]) - params << new(second[0], second[1]) - binding.pry + data.each do |pair| + name, values = pair + Array(values).each do |value| + params << new(name, value) + end end params diff --git a/spec/lib/http/form_data/multipart_spec.rb b/spec/lib/http/form_data/multipart_spec.rb index 291630a..4e90606 100644 --- a/spec/lib/http/form_data/multipart_spec.rb +++ b/spec/lib/http/form_data/multipart_spec.rb @@ -17,7 +17,6 @@ def disposition(params) it "properly generates multipart data" do boundary_value = form_data.boundary - expect(form_data.to_s).to eq([ "--#{boundary_value}#{crlf}", "#{disposition 'name' => 'foo'}#{crlf}", @@ -99,7 +98,7 @@ def disposition(params) ] end - it "allows duplicate param names and preservesd given order" do + it "allows duplicate param names and preserves given order" do expect(form_data.to_s).to eq([ %(--#{form_data.boundary}#{crlf}), %(Content-Disposition: form-data; name="metadata"#{crlf}), @@ -108,6 +107,7 @@ def disposition(params) %(Content-Disposition: form-data; name="file"; filename="abc"#{crlf}), %(Content-Type: plain/text#{crlf}), %(#{crlf}uno#{crlf}), + # TODO: Veryify that no form_data.boundry line is desired between 'pairs' %(Content-Disposition: form-data; name="metadata"#{crlf}#{crlf}), %(filename=second.txt#{crlf}), %(--#{form_data.boundary}#{crlf}), diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 80d8cba..1f0ca63 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,6 +17,8 @@ # ...rather than: # # => "be bigger than 2" expectations.include_chain_clauses_in_custom_matcher_descriptions = true + # This option will remove the default 200 character limit for RSpec diffs + expectations.max_formatted_output_length = nil end config.mock_with :rspec do |mocks|