multipart-post 1.1.5 → 2.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rspec +5 -0
- data/.travis.yml +19 -6
- data/.yardopts +6 -0
- data/Gemfile +1 -9
- data/History.txt +22 -1
- data/LICENSE +21 -0
- data/README.md +127 -0
- data/Rakefile +3 -6
- data/lib/composite_io.rb +38 -37
- data/lib/multipart_post.rb +2 -2
- data/lib/multipartable.rb +41 -13
- data/lib/net/http/post/multipart.rb +4 -3
- data/lib/parts.rb +60 -18
- data/multipart-post.gemspec +18 -15
- data/spec/composite_io_spec.rb +138 -0
- data/{test → spec}/multibyte.txt +0 -0
- data/spec/net/http/post/multipart_spec.rb +123 -0
- data/spec/parts_spec.rb +102 -0
- data/spec/spec_helper.rb +29 -0
- metadata +77 -25
- data/Gemfile.lock +0 -39
- data/README.txt +0 -62
- data/test/net/http/post/test_multipart.rb +0 -56
- data/test/test_composite_io.rb +0 -77
- data/test/test_parts.rb +0 -57
data/spec/parts_spec.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Copyright, 2012, by Nick Sieger.
|
2
|
+
# Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'parts'
|
23
|
+
require 'stringio'
|
24
|
+
require 'composite_io'
|
25
|
+
require 'tempfile'
|
26
|
+
|
27
|
+
MULTIBYTE = File.dirname(__FILE__)+'/multibyte.txt'
|
28
|
+
TEMP_FILE = "temp.txt"
|
29
|
+
|
30
|
+
module AssertPartLength
|
31
|
+
def assert_part_length(part)
|
32
|
+
bytes = part.to_io.read
|
33
|
+
bytesize = bytes.respond_to?(:bytesize) ? bytes.bytesize : bytes.length
|
34
|
+
expect(bytesize).to be == part.length
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec.describe Parts do
|
39
|
+
let(:string_with_content_type) do
|
40
|
+
Class.new(String) do
|
41
|
+
def content_type; 'application/data'; end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "test_file_with_upload_io" do
|
46
|
+
expect(Parts::Part.file?(UploadIO.new(__FILE__, "text/plain"))).to be true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "test_file_with_modified_string" do
|
50
|
+
expect(Parts::Part.file?(string_with_content_type.new("Hello"))).to be false
|
51
|
+
end
|
52
|
+
|
53
|
+
it "test_new_with_modified_string" do
|
54
|
+
expect(Parts::Part.new("boundary", "multibyte", string_with_content_type.new("Hello"))).to be_kind_of(Parts::ParamPart)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
RSpec.describe Parts::FilePart do
|
59
|
+
include AssertPartLength
|
60
|
+
|
61
|
+
before(:each) do
|
62
|
+
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
63
|
+
io = UploadIO.new(TEMP_FILE, "text/plain")
|
64
|
+
@part = Parts::FilePart.new("boundary", "afile", io)
|
65
|
+
end
|
66
|
+
|
67
|
+
after(:each) do
|
68
|
+
File.delete(TEMP_FILE) rescue nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "test_correct_length" do
|
72
|
+
assert_part_length @part
|
73
|
+
end
|
74
|
+
|
75
|
+
it "test_multibyte_file_length" do
|
76
|
+
assert_part_length Parts::FilePart.new("boundary", "multibyte", UploadIO.new(MULTIBYTE, "text/plain"))
|
77
|
+
end
|
78
|
+
|
79
|
+
it "test_multibyte_filename" do
|
80
|
+
name = File.read(MULTIBYTE, 300)
|
81
|
+
file = Tempfile.new(name.respond_to?(:force_encoding) ? name.force_encoding("UTF-8") : name)
|
82
|
+
assert_part_length Parts::FilePart.new("boundary", "multibyte", UploadIO.new(file, "text/plain"))
|
83
|
+
file.close
|
84
|
+
end
|
85
|
+
|
86
|
+
it "test_force_content_type_header" do
|
87
|
+
part = Parts::FilePart.new("boundary", "afile", UploadIO.new(TEMP_FILE, "text/plain"), { "Content-Type" => "application/pdf" })
|
88
|
+
expect(part.to_io.read).to match(/Content-Type: application\/pdf/)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
RSpec.describe Parts::ParamPart do
|
93
|
+
include AssertPartLength
|
94
|
+
|
95
|
+
before(:each) do
|
96
|
+
@part = Parts::ParamPart.new("boundary", "multibyte", File.read(MULTIBYTE))
|
97
|
+
end
|
98
|
+
|
99
|
+
it "test_correct_length" do
|
100
|
+
assert_part_length @part
|
101
|
+
end
|
102
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
if ENV['COVERAGE']
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "/spec/"
|
8
|
+
end
|
9
|
+
|
10
|
+
if ENV['TRAVIS']
|
11
|
+
require 'coveralls'
|
12
|
+
Coveralls.wear!
|
13
|
+
end
|
14
|
+
rescue LoadError
|
15
|
+
warn "Could not load simplecov: #{$!}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require "bundler/setup"
|
20
|
+
require "multipart_post"
|
21
|
+
|
22
|
+
RSpec.configure do |config|
|
23
|
+
# Enable flags like --only-failures and --next-failure
|
24
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
25
|
+
|
26
|
+
config.expect_with :rspec do |c|
|
27
|
+
c.syntax = :expect
|
28
|
+
end
|
29
|
+
end
|
metadata
CHANGED
@@ -1,31 +1,82 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multipart-post
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
5
|
-
prerelease:
|
4
|
+
version: 2.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Nick Sieger
|
8
|
+
- Samuel Williams
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
|
12
|
+
date: 2019-05-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.3'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '3'
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.3'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: rspec
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
41
|
+
type: :development
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: 'Use with Net::HTTP to do multipart form postspec. IO values that have
|
15
63
|
#content_type, #original_filename, and #local_path will be posted as a binary file.'
|
16
64
|
email:
|
17
65
|
- nick@nicksieger.com
|
66
|
+
- samuel.williams@oriontransfer.co.nz
|
18
67
|
executables: []
|
19
68
|
extensions: []
|
20
69
|
extra_rdoc_files: []
|
21
70
|
files:
|
22
|
-
- .gitignore
|
23
|
-
- .
|
71
|
+
- ".gitignore"
|
72
|
+
- ".rspec"
|
73
|
+
- ".travis.yml"
|
74
|
+
- ".yardopts"
|
24
75
|
- Gemfile
|
25
|
-
- Gemfile.lock
|
26
76
|
- History.txt
|
77
|
+
- LICENSE
|
27
78
|
- Manifest.txt
|
28
|
-
- README.
|
79
|
+
- README.md
|
29
80
|
- Rakefile
|
30
81
|
- lib/composite_io.rb
|
31
82
|
- lib/multipart_post.rb
|
@@ -33,36 +84,37 @@ files:
|
|
33
84
|
- lib/net/http/post/multipart.rb
|
34
85
|
- lib/parts.rb
|
35
86
|
- multipart-post.gemspec
|
36
|
-
-
|
37
|
-
-
|
38
|
-
-
|
39
|
-
-
|
87
|
+
- spec/composite_io_spec.rb
|
88
|
+
- spec/multibyte.txt
|
89
|
+
- spec/net/http/post/multipart_spec.rb
|
90
|
+
- spec/parts_spec.rb
|
91
|
+
- spec/spec_helper.rb
|
40
92
|
homepage: https://github.com/nicksieger/multipart-post
|
41
|
-
licenses:
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
42
96
|
post_install_message:
|
43
97
|
rdoc_options: []
|
44
98
|
require_paths:
|
45
99
|
- lib
|
46
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
-
none: false
|
48
101
|
requirements:
|
49
|
-
- -
|
102
|
+
- - ">="
|
50
103
|
- !ruby/object:Gem::Version
|
51
104
|
version: '0'
|
52
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
-
none: false
|
54
106
|
requirements:
|
55
|
-
- -
|
107
|
+
- - ">="
|
56
108
|
- !ruby/object:Gem::Version
|
57
109
|
version: '0'
|
58
110
|
requirements: []
|
59
|
-
|
60
|
-
rubygems_version: 1.8.6
|
111
|
+
rubygems_version: 3.0.3
|
61
112
|
signing_key:
|
62
|
-
specification_version:
|
113
|
+
specification_version: 4
|
63
114
|
summary: A multipart form post accessory for Net::HTTP.
|
64
115
|
test_files:
|
65
|
-
-
|
66
|
-
-
|
67
|
-
-
|
68
|
-
-
|
116
|
+
- spec/composite_io_spec.rb
|
117
|
+
- spec/multibyte.txt
|
118
|
+
- spec/net/http/post/multipart_spec.rb
|
119
|
+
- spec/parts_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
data/Gemfile.lock
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
multipart-post (1.1.4)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
archive-tar-minitar (0.5.2)
|
10
|
-
columnize (0.3.6)
|
11
|
-
linecache (0.43)
|
12
|
-
linecache19 (0.5.12)
|
13
|
-
ruby_core_source (>= 0.1.4)
|
14
|
-
rake (0.9.2.2)
|
15
|
-
ruby-debug (0.10.3)
|
16
|
-
columnize (>= 0.1)
|
17
|
-
ruby-debug-base (~> 0.10.3.0)
|
18
|
-
ruby-debug-base (0.10.3)
|
19
|
-
linecache (>= 0.3)
|
20
|
-
ruby-debug-base19 (0.11.25)
|
21
|
-
columnize (>= 0.3.1)
|
22
|
-
linecache19 (>= 0.5.11)
|
23
|
-
ruby_core_source (>= 0.1.4)
|
24
|
-
ruby-debug19 (0.11.6)
|
25
|
-
columnize (>= 0.3.1)
|
26
|
-
linecache19 (>= 0.5.11)
|
27
|
-
ruby-debug-base19 (>= 0.11.19)
|
28
|
-
ruby_core_source (0.1.5)
|
29
|
-
archive-tar-minitar (>= 0.5.2)
|
30
|
-
|
31
|
-
PLATFORMS
|
32
|
-
java
|
33
|
-
ruby
|
34
|
-
|
35
|
-
DEPENDENCIES
|
36
|
-
multipart-post!
|
37
|
-
rake
|
38
|
-
ruby-debug
|
39
|
-
ruby-debug19
|
data/README.txt
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
= multipart-post
|
2
|
-
|
3
|
-
* http://github.com/nicksieger/multipart-post
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
Adds a streamy multipart form post capability to Net::HTTP. Also
|
8
|
-
supports other methods besides POST.
|
9
|
-
|
10
|
-
== FEATURES/PROBLEMS:
|
11
|
-
|
12
|
-
* Appears to actually work. A good feature to have.
|
13
|
-
* Encapsulates posting of file/binary parts and name/value parameter parts, similar to
|
14
|
-
most browsers' file upload forms.
|
15
|
-
* Provides an UploadIO helper class to prepare IO objects for inclusion in the params
|
16
|
-
hash of the multipart post object.
|
17
|
-
|
18
|
-
== SYNOPSIS:
|
19
|
-
|
20
|
-
require 'net/http/post/multipart'
|
21
|
-
|
22
|
-
url = URI.parse('http://www.example.com/upload')
|
23
|
-
File.open("./image.jpg") do |jpg|
|
24
|
-
req = Net::HTTP::Post::Multipart.new url.path,
|
25
|
-
"file" => UploadIO.new(jpg, "image/jpeg", "image.jpg")
|
26
|
-
res = Net::HTTP.start(url.host, url.port) do |http|
|
27
|
-
http.request(req)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
== REQUIREMENTS:
|
32
|
-
|
33
|
-
None
|
34
|
-
|
35
|
-
== INSTALL:
|
36
|
-
|
37
|
-
gem install multipart-post
|
38
|
-
|
39
|
-
== LICENSE:
|
40
|
-
|
41
|
-
(The MIT License)
|
42
|
-
|
43
|
-
Copyright (c) 2007-2012 Nick Sieger <nick@nicksieger.com>
|
44
|
-
|
45
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
-
a copy of this software and associated documentation files (the
|
47
|
-
'Software'), to deal in the Software without restriction, including
|
48
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
-
permit persons to whom the Software is furnished to do so, subject to
|
51
|
-
the following conditions:
|
52
|
-
|
53
|
-
The above copyright notice and this permission notice shall be
|
54
|
-
included in all copies or substantial portions of the Software.
|
55
|
-
|
56
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,56 +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 'net/http/post/multipart'
|
8
|
-
require 'test/unit'
|
9
|
-
|
10
|
-
class Net::HTTP::Post::MultiPartTest < Test::Unit::TestCase
|
11
|
-
TEMP_FILE = "temp.txt"
|
12
|
-
|
13
|
-
HTTPPost = Struct.new("HTTPPost", :content_length, :body_stream, :content_type)
|
14
|
-
HTTPPost.module_eval do
|
15
|
-
def set_content_type(type, params = {})
|
16
|
-
self.content_type = type + params.map{|k,v|"; #{k}=#{v}"}.join('')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def teardown
|
21
|
-
File.delete(TEMP_FILE) rescue nil
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_form_multipart_body
|
25
|
-
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
26
|
-
@io = File.open(TEMP_FILE)
|
27
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
28
|
-
assert_results Net::HTTP::Post::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
29
|
-
end
|
30
|
-
def test_form_multipart_body_put
|
31
|
-
File.open(TEMP_FILE, "w") {|f| f << "1234567890"}
|
32
|
-
@io = File.open(TEMP_FILE)
|
33
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
34
|
-
assert_results Net::HTTP::Put::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_form_multipart_body_with_stringio
|
38
|
-
@io = StringIO.new("1234567890")
|
39
|
-
@io = UploadIO.new @io, "text/plain", TEMP_FILE
|
40
|
-
assert_results Net::HTTP::Post::Multipart.new("/foo/bar", :foo => 'bar', :file => @io)
|
41
|
-
end
|
42
|
-
|
43
|
-
def assert_results(post)
|
44
|
-
assert post.content_length && post.content_length > 0
|
45
|
-
assert post.body_stream
|
46
|
-
assert_equal "multipart/form-data; boundary=#{Multipartable::DEFAULT_BOUNDARY}", post['content-type']
|
47
|
-
body = post.body_stream.read
|
48
|
-
boundary_regex = Regexp.quote Multipartable::DEFAULT_BOUNDARY
|
49
|
-
assert body =~ /1234567890/
|
50
|
-
# ensure there is at least one boundary
|
51
|
-
assert body =~ /^--#{boundary_regex}\r\n/
|
52
|
-
# ensure there is an epilogue
|
53
|
-
assert body =~ /^--#{boundary_regex}--\r\n/
|
54
|
-
assert body =~ /text\/plain/
|
55
|
-
end
|
56
|
-
end
|
data/test/test_composite_io.rb
DELETED
@@ -1,77 +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 'composite_io'
|
8
|
-
require 'stringio'
|
9
|
-
require 'test/unit'
|
10
|
-
|
11
|
-
class CompositeReadIOTest < Test::Unit::TestCase
|
12
|
-
def setup
|
13
|
-
@io = CompositeReadIO.new(CompositeReadIO.new(StringIO.new('the '), StringIO.new('quick ')),
|
14
|
-
StringIO.new('brown '), StringIO.new('fox'))
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_full_read_from_several_ios
|
18
|
-
assert_equal 'the quick brown fox', @io.read
|
19
|
-
end
|
20
|
-
|
21
|
-
unless RUBY_VERSION < '1.9'
|
22
|
-
def test_read_from_multibyte
|
23
|
-
utf8 = File.open(File.dirname(__FILE__)+'/multibyte.txt')
|
24
|
-
binary = StringIO.new("\x86")
|
25
|
-
@io = CompositeReadIO.new(binary,utf8)
|
26
|
-
assert_equal "\x86\xE3\x83\x95\xE3\x82\xA1\xE3\x82\xA4\xE3\x83\xAB\n", @io.read
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_partial_read
|
31
|
-
assert_equal 'the quick', @io.read(9)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_partial_read_to_boundary
|
35
|
-
assert_equal 'the quick ', @io.read(10)
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_read_with_size_larger_than_available
|
39
|
-
assert_equal 'the quick brown fox', @io.read(32)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_read_into_buffer
|
43
|
-
buf = ''
|
44
|
-
@io.read(nil, buf)
|
45
|
-
assert_equal 'the quick brown fox', buf
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_multiple_reads
|
49
|
-
assert_equal 'the ', @io.read(4)
|
50
|
-
assert_equal 'quic', @io.read(4)
|
51
|
-
assert_equal 'k br', @io.read(4)
|
52
|
-
assert_equal 'own ', @io.read(4)
|
53
|
-
assert_equal 'fox', @io.read(4)
|
54
|
-
end
|
55
|
-
|
56
|
-
def test_read_after_end
|
57
|
-
@io.read
|
58
|
-
assert_equal "", @io.read
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_read_after_end_with_amount
|
62
|
-
@io.read(32)
|
63
|
-
assert_equal nil, @io.read(32)
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_second_full_read_after_rewinding
|
67
|
-
@io.read
|
68
|
-
@io.rewind
|
69
|
-
assert_equal 'the quick brown fox', @io.read
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_convert_error
|
73
|
-
assert_raises(ArgumentError) {
|
74
|
-
UploadIO.convert!('tmp.txt', 'text/plain', 'tmp.txt', 'tmp.txt')
|
75
|
-
}
|
76
|
-
end
|
77
|
-
end
|