From cff91ce31c87c001c8cbbd171fc84c28585ec4ec Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Wed, 21 Mar 2012 08:44:46 -0400 Subject: [PATCH] first pass to fix issue #13 -- pass through IO-type objects that can't be IO#read properly (because they are too large?) --- lib/rubydora/datastream.rb | 5 ++++- spec/lib/datastream_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/rubydora/datastream.rb b/lib/rubydora/datastream.rb index 30ebf26..aa8030f 100644 --- a/lib/rubydora/datastream.rb +++ b/lib/rubydora/datastream.rb @@ -118,7 +118,10 @@ def content rescue RestClient::ResourceNotFound end - content = @content.read and @content.rewind if @content.kind_of? IO + if @content.kind_of? IO + content = @content.read and @content.rewind rescue nil + end + content ||= @content end alias_method :read, :content diff --git a/spec/lib/datastream_spec.rb b/spec/lib/datastream_spec.rb index b5f977f..4265658 100644 --- a/spec/lib/datastream_spec.rb +++ b/spec/lib/datastream_spec.rb @@ -152,6 +152,16 @@ end + it "should pass-through IO-type content if reading the content fails" do + @mock_io = File.open('rubydora.gemspec') + @mock_io.should_receive(:read).and_raise('Rubydora #13-style read-error.') + + @datastream.content = @mock_io + + @datastream.content.should == @mock_io + + end + end