Skip to content

Commit 571e0c5

Browse files
author
Matt Kelly
committed
WIP: Verify no boundary desired between 'pairs'
1 parent 246a2ca commit 571e0c5

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

lib/http/form_data/multipart.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def tail
5454
end
5555

5656
def parts(data)
57-
return Param.coerce FormData.ensure_hash data if @params.is_a?(Hash)
58-
Param.coerce_array_of_pairs data
57+
return Param.coerce_array_of_pairs data if data.is_a?(Array)
58+
Param.coerce FormData.ensure_hash data
5959
end
6060
end
6161
end

lib/http/form_data/multipart/param.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ class Param
3131
# @param [FormData::File, FormData::Part, #to_s] value
3232
def initialize(name, value)
3333
@name = name.to_s
34-
3534
@part =
3635
if value.is_a?(FormData::Part)
3736
value
3837
else
3938
FormData::Part.new(value)
4039
end
41-
4240
@io = CompositeIO.new [header, @part, footer]
4341
end
4442

@@ -52,12 +50,10 @@ def self.coerce(data)
5250
params = []
5351

5452
data.each do |name, values|
55-
binding.pry
5653
Array(values).each do |value|
5754
params << new(name, value)
5855
end
5956
end
60-
6157
params
6258
end
6359

@@ -70,11 +66,11 @@ def self.coerce(data)
7066
def self.coerce_array_of_pairs(data)
7167
params = []
7268

73-
data.each_slice(2) do |first, second|
74-
binding.pry
75-
params << new(first[0], first[1])
76-
params << new(second[0], second[1])
77-
binding.pry
69+
data.each do |pair|
70+
name, values = pair
71+
Array(values).each do |value|
72+
params << new(name, value)
73+
end
7874
end
7975

8076
params

spec/lib/http/form_data/multipart_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ def disposition(params)
1717

1818
it "properly generates multipart data" do
1919
boundary_value = form_data.boundary
20-
2120
expect(form_data.to_s).to eq([
2221
"--#{boundary_value}#{crlf}",
2322
"#{disposition 'name' => 'foo'}#{crlf}",
@@ -99,7 +98,7 @@ def disposition(params)
9998
]
10099
end
101100

102-
it "allows duplicate param names and preservesd given order" do
101+
it "allows duplicate param names and preserves given order" do
103102
expect(form_data.to_s).to eq([
104103
%(--#{form_data.boundary}#{crlf}),
105104
%(Content-Disposition: form-data; name="metadata"#{crlf}),
@@ -108,6 +107,7 @@ def disposition(params)
108107
%(Content-Disposition: form-data; name="file"; filename="abc"#{crlf}),
109108
%(Content-Type: plain/text#{crlf}),
110109
%(#{crlf}uno#{crlf}),
110+
# TODO: Veryify that no form_data.boundry line is desired between 'pairs'
111111
%(Content-Disposition: form-data; name="metadata"#{crlf}#{crlf}),
112112
%(filename=second.txt#{crlf}),
113113
%(--#{form_data.boundary}#{crlf}),

spec/spec_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# ...rather than:
1818
# # => "be bigger than 2"
1919
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
20+
# This option will remove the default 200 character limit for RSpec diffs
21+
expectations.max_formatted_output_length = nil
2022
end
2123

2224
config.mock_with :rspec do |mocks|

0 commit comments

Comments
 (0)