Skip to content

Commit

Permalink
Merge pull request #2185 from zog/master
Browse files Browse the repository at this point in the history
Fix issue encountered when trying to reopen a file stored  remotely
  • Loading branch information
mshibuya authored Jul 12, 2017
2 parents 2be9b11 + 09d3d51 commit f43c068
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/carrierwave/processing/rmagick.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def dimension_from(value)
end

def rmagick_image
::Magick::Image.read(current_path).first
::Magick::Image.from_blob(self.read).first
end

end # RMagick
Expand Down
32 changes: 32 additions & 0 deletions spec/processing/rmagick_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,38 @@
end
end

describe "#rmagick_image" do
it "returns a ::Magick::Image" do
expect{instance.send(:rmagick_image)}.to_not raise_exception
expect(instance.send(:rmagick_image).class).to eq(::Magick::Image)
end

context "with a remotely stored file" do
class RemoteFile < CarrierWave::SanitizedFile
def initialize local_path
@local_path = local_path
end

def current_path
"foo/bar.jpg"
end

def read
File.read @local_path
end
end

before do
allow(instance).to receive(:file).and_return(RemoteFile.new(landscape_file_copy_path))
end

it "returns a ::Magick::Image" do
expect{instance.send(:rmagick_image)}.to_not raise_exception
expect(instance.send(:rmagick_image).class).to eq(::Magick::Image)
end
end
end

describe "test errors" do
context "invalid image file" do
before do
Expand Down

0 comments on commit f43c068

Please sign in to comment.