multipart-post 2.0.0 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,115 +0,0 @@
1
- #--
2
- # Copyright (c) 2007-2013 Nick Sieger.
3
- # See the file README.txt included with the distribution for
4
- # software license details.
5
- #++
6
-
7
- require 'composite_io'
8
- require 'stringio'
9
- require 'test/unit'
10
- require 'timeout'
11
-
12
- class CompositeReadIOTest < Test::Unit::TestCase
13
- def setup
14
- @io = CompositeReadIO.new(CompositeReadIO.new(StringIO.new('the '), StringIO.new('quick ')),
15
- StringIO.new('brown '), StringIO.new('fox'))
16
- end
17
-
18
- def test_full_read_from_several_ios
19
- assert_equal 'the quick brown fox', @io.read
20
- end
21
-
22
- unless RUBY_VERSION < '1.9'
23
- def test_read_from_multibyte
24
- utf8 = File.open(File.dirname(__FILE__)+'/multibyte.txt')
25
- binary = StringIO.new("\x86")
26
- @io = CompositeReadIO.new(binary,utf8)
27
-
28
- expect = "\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n"
29
- expect.force_encoding('BINARY') if expect.respond_to?(:force_encoding)
30
- assert_equal expect, @io.read
31
- end
32
- end
33
-
34
- def test_partial_read
35
- assert_equal 'the quick', @io.read(9)
36
- end
37
-
38
- def test_partial_read_to_boundary
39
- assert_equal 'the quick ', @io.read(10)
40
- end
41
-
42
- def test_read_with_size_larger_than_available
43
- assert_equal 'the quick brown fox', @io.read(32)
44
- end
45
-
46
- def test_read_into_buffer
47
- buf = ''
48
- @io.read(nil, buf)
49
- assert_equal 'the quick brown fox', buf
50
- end
51
-
52
- def test_multiple_reads
53
- assert_equal 'the ', @io.read(4)
54
- assert_equal 'quic', @io.read(4)
55
- assert_equal 'k br', @io.read(4)
56
- assert_equal 'own ', @io.read(4)
57
- assert_equal 'fox', @io.read(4)
58
- end
59
-
60
- def test_read_after_end
61
- @io.read
62
- assert_equal "", @io.read
63
- end
64
-
65
- def test_read_after_end_with_amount
66
- @io.read(32)
67
- assert_equal nil, @io.read(32)
68
- end
69
-
70
- def test_second_full_read_after_rewinding
71
- @io.read
72
- @io.rewind
73
- assert_equal 'the quick brown fox', @io.read
74
- end
75
-
76
- def test_convert_error
77
- assert_raises(ArgumentError) {
78
- UploadIO.convert!('tmp.txt', 'text/plain', 'tmp.txt', 'tmp.txt')
79
- }
80
- end
81
-
82
- ## FIXME excluding on JRuby due to
83
- ## http://jira.codehaus.org/browse/JRUBY-7109
84
- if IO.respond_to?(:copy_stream) && !defined?(JRUBY_VERSION)
85
- def test_compatible_with_copy_stream
86
- target_io = StringIO.new
87
- Timeout.timeout(1) do
88
- IO.copy_stream(@io, target_io)
89
- end
90
- assert_equal "the quick brown fox", target_io.string
91
- end
92
- end
93
-
94
- def test_empty
95
- io = CompositeReadIO.new
96
- assert_equal "", io.read
97
- end
98
-
99
- def test_empty_limited
100
- io = CompositeReadIO.new
101
- assert_nil io.read(1)
102
- end
103
-
104
- def test_empty_parts
105
- io = CompositeReadIO.new(StringIO.new, StringIO.new('the '), StringIO.new, StringIO.new('quick'))
106
- assert_equal "the", io.read(3)
107
- assert_equal " qu", io.read(3)
108
- assert_equal "ick", io.read(4)
109
- end
110
-
111
- def test_all_empty_parts
112
- io = CompositeReadIO.new(StringIO.new, StringIO.new)
113
- assert_nil io.read(1)
114
- end
115
- end
data/test/test_parts.rb DELETED
@@ -1,86 +0,0 @@
1
- #--
2
- # Copyright (c) 2007-2012 Nick Sieger.
3
- # See the file README.txt included with the distribution for
4
- # software license details.
5
- #++
6
-
7
- require 'test/unit'
8
-
9
- require 'parts'
10
- require 'stringio'
11
- require 'composite_io'
12
- require 'tempfile'
13
-
14
-
15
- MULTIBYTE = File.dirname(__FILE__)+'/multibyte.txt'
16
- TEMP_FILE = "temp.txt"
17
-
18
- module AssertPartLength
19
- def assert_part_length(part)
20
- bytes = part.to_io.read
21
- bytesize = bytes.respond_to?(:bytesize) ? bytes.bytesize : bytes.length
22
- assert_equal bytesize, part.length
23
- end
24
- end
25
-
26
- class PartTest < Test::Unit::TestCase
27
- def setup
28
- @string_with_content_type = Class.new(String) do
29
- def content_type; 'application/data'; end
30
- end
31
- end
32
-
33
- def test_file_with_upload_io
34
- assert Parts::Part.file?(UploadIO.new(__FILE__, "text/plain"))
35
- end
36
-
37
- def test_file_with_modified_string
38
- assert !Parts::Part.file?(@string_with_content_type.new("Hello"))
39
- end
40
-
41
- def test_new_with_modified_string
42
- assert_kind_of Parts::ParamPart,
43
- Parts::Part.new("boundary", "multibyte", @string_with_content_type.new("Hello"))
44
- end
45
- end
46
-
47
- class FilePartTest < Test::Unit::TestCase
48
- include AssertPartLength
49
-
50
- def setup
51
- File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
52
- io = UploadIO.new(TEMP_FILE, "text/plain")
53
- @part = Parts::FilePart.new("boundary", "afile", io)
54
- end
55
-
56
- def teardown
57
- File.delete(TEMP_FILE) rescue nil
58
- end
59
-
60
- def test_correct_length
61
- assert_part_length @part
62
- end
63
-
64
- def test_multibyte_file_length
65
- assert_part_length Parts::FilePart.new("boundary", "multibyte", UploadIO.new(MULTIBYTE, "text/plain"))
66
- end
67
-
68
- def test_multibyte_filename
69
- name = File.read(MULTIBYTE, 300)
70
- file = Tempfile.new(name.respond_to?(:force_encoding) ? name.force_encoding("UTF-8") : name)
71
- assert_part_length Parts::FilePart.new("boundary", "multibyte", UploadIO.new(file, "text/plain"))
72
- file.close
73
- end
74
- end
75
-
76
- class ParamPartTest < Test::Unit::TestCase
77
- include AssertPartLength
78
-
79
- def setup
80
- @part = Parts::ParamPart.new("boundary", "multibyte", File.read(MULTIBYTE))
81
- end
82
-
83
- def test_correct_length
84
- assert_part_length @part
85
- end
86
- end