Permalink
Browse files

Datastream.content= should allow Rack::Test::Uploaded file. It behave…

…s like an IO, but it doesn't decend from IO
  • Loading branch information...
1 parent f1e8d16 commit 963fdbe39156188609961796c5fe09304febe9b4 @jcoyne jcoyne committed Dec 20, 2012
Showing with 13 additions and 6 deletions.
  1. +8 −2 lib/rubydora/datastream.rb
  2. +5 −4 spec/lib/datastream_spec.rb
@@ -129,7 +129,7 @@ def content
@content ||= datastream_content
- if @content.kind_of? IO
+ if behaves_like_io?(@content)
begin
@content.rewind
@content.read
@@ -205,7 +205,7 @@ def has_content?
# return true if instance_variable_defined? :@content
- @content.is_a?(IO) || !content.blank?
+ behaves_like_io?(@content) || !content.blank?
end
# Retrieve the datastream profile as a hash (and cache it)
@@ -367,6 +367,12 @@ def validate_dsLocation! val
end
private
+
+ # Rack::Test::UploadedFile is often set via content=, however it's not an IO, though it wraps an io object.
+ def behaves_like_io?(obj)
+ obj.is_a?(IO) || (defined?(Rack) && obj.is_a?(Rack::Test::UploadedFile))
+ end
+
def attribute_will_change! *args
check_if_read_only
super
@@ -1,4 +1,5 @@
require 'spec_helper'
+require 'stringio'
describe Rubydora::Datastream do
before do
@@ -187,26 +188,26 @@
@datastream.content
@datastream.content_changed?.should == false
end
- it "should be changed in the new content is different than the old content" do
+ it "should be changed when the new content is different than the old content" do
@mock_repository.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('asdf')
@datastream.content = "test"
@datastream.content_changed?.should == true
end
- it "should not be changed in the new content is the same as the existing content (when eager-loading is enabled)" do
+ it "should not be changed when the new content is the same as the existing content (when eager-loading is enabled)" do
@mock_repository.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('test')
@datastream.eager_load_datastream_content = true
@datastream.content = "test"
@datastream.content_changed?.should == false
end
- it "should be changed in the new content is the same as the existing content (without eager loading, the default)" do
+ it "should be changed when the new content is the same as the existing content (without eager loading, the default)" do
@mock_repository.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('test')
@datastream.content = "test"
@datastream.content_changed?.should == true
end
- it "should not be changed in the new content is the same as the existing content (and we have accessed #content previously)" do
+ it "should not be changed when the new content is the same as the existing content (and we have accessed #content previously)" do
@mock_repository.stub(:datastream_dissemination).with(hash_including(:pid => 'pid', :dsid => 'dsid')).and_return('test')
@datastream.content
@datastream.content = "test"

0 comments on commit 963fdbe

Please sign in to comment.