@@ -227,20 +227,24 @@ def test_encoding_length
227227
228228 def test_file_encode
229229 file = Pathname ( __FILE__ )
230+ fileinput = Scrapegraphai ::Internal ::Type ::Converter . dump ( Scrapegraphai ::Internal ::Type ::FileInput , "abc" )
230231 headers = { "content-type" => "multipart/form-data" }
231232 cases = {
232- "abc" => " abc",
233- StringIO . new ( "abc" ) => " abc",
234- Scrapegraphai :: FilePart . new ( "abc" ) => " abc" ,
235- Scrapegraphai ::FilePart . new ( StringIO . new ( "abc" ) ) => " abc",
236- file => /^class Scrapegraphai/ ,
237- Scrapegraphai ::FilePart . new ( file ) => /^class Scrapegraphai/
233+ "abc" => [ "" , " abc"] ,
234+ StringIO . new ( "abc" ) => [ "" , " abc"] ,
235+ fileinput => %w[ upload abc ] ,
236+ Scrapegraphai ::FilePart . new ( StringIO . new ( "abc" ) ) => [ "" , " abc"] ,
237+ file => [ file . basename . to_path , /^class Scrapegraphai/ ] ,
238+ Scrapegraphai ::FilePart . new ( file , filename : "d o g" ) => [ "d%20o%20g" , /^class Scrapegraphai/ ]
238239 }
239- cases . each do |body , val |
240+ cases . each do |body , testcase |
241+ filename , val = testcase
240242 encoded = Scrapegraphai ::Internal ::Util . encode_content ( headers , body )
241243 cgi = FakeCGI . new ( *encoded )
244+ io = cgi [ "" ]
242245 assert_pattern do
243- cgi [ "" ] . read => ^val
246+ io . original_filename => ^filename
247+ io . read => ^val
244248 end
245249 end
246250 end
@@ -261,7 +265,14 @@ def test_hash_encode
261265 cgi = FakeCGI . new ( *encoded )
262266 testcase . each do |key , val |
263267 assert_pattern do
264- cgi [ key ] => ^val
268+ parsed =
269+ case ( p = cgi [ key ] )
270+ in StringIO
271+ p . read
272+ else
273+ p
274+ end
275+ parsed => ^val
265276 end
266277 end
267278 end
0 commit comments