Skip to content

Commit acdf2cd

Browse files
committed
Inputs only need to have a #path method.
1 parent b10c828 commit acdf2cd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/mini_magick.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class << self
6363
def read(stream, ext = nil)
6464
if stream.is_a?(String)
6565
stream = StringIO.new(stream)
66-
elsif stream.is_a?(File)
66+
elsif stream.respond_to? :path
6767
if File.respond_to?(:binread)
6868
stream = StringIO.new File.binread(stream.path.to_s)
6969
else

test/image_test.rb

+13
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ def test_image_from_blob
1414
end
1515
end
1616

17+
def test_image_from_tempfile
18+
tempfile = Tempfile.new('magick')
19+
20+
File.open(SIMPLE_IMAGE_PATH, 'rb') do |f|
21+
tempfile.write(f.read)
22+
tempfile.rewind
23+
end
24+
25+
image = Image.read(tempfile)
26+
assert image.valid?
27+
image.destroy!
28+
end
29+
1730
def test_image_open
1831
image = Image.open(SIMPLE_IMAGE_PATH)
1932
assert image.valid?

0 commit comments

Comments
 (0)