Skip to content

Commit 0ab6d68

Browse files
authored
Merge pull request #106 from projecthydra/patch-add-mod-ds
Patches Rubydora::RestApiClient to not read file-like object
2 parents cf81f19 + 890aba2 commit 0ab6d68

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ gemspec
44

55
gem 'jruby-openssl', :platform => :jruby
66
gem 'activesupport', '< 5' if RUBY_VERSION < '2.2.2'
7+
gem 'rake', '< 12'

lib/rubydora/rest_api_client.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,8 @@ def add_datastream(options = {})
336336
file = query_options.delete(:content)
337337
content_type = query_options.delete(:content_type) || query_options[:mimeType] || file_content_type(file)
338338
run_hook :before_add_datastream, :pid => pid, :dsid => dsid, :file => file, :options => options
339-
str = file.respond_to?(:read) ? file.read : file
340339
file.rewind if file.respond_to?(:rewind)
341-
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].post(str, :content_type => content_type.to_s, :multipart => true))
340+
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].post(file, :content_type => content_type.to_s, :multipart => true))
342341
rescue Exception => exception
343342
rescue_with_handler(exception) || raise
344343
end
@@ -361,9 +360,8 @@ def modify_datastream(options = {})
361360
end
362361

363362
run_hook :before_modify_datastream, :pid => pid, :dsid => dsid, :file => file, :content_type => content_type, :options => options
364-
str = file.respond_to?(:read) ? file.read : file
365363
file.rewind if file.respond_to?(:rewind)
366-
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].put(str, rest_client_options))
364+
ProfileParser.parse_datastream_profile(client[datastream_url(pid, dsid, query_options)].put(file, rest_client_options))
367365

368366
rescue Exception => exception
369367
rescue_with_handler(exception) || raise

spec/lib/rest_api_client_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ class MockRepository
240240
@mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa'
241241
end
242242
describe "when a file is passed" do
243-
let!(:file) { StringIO.new('test', 'r') } # StringIO is a good stand it for a real File (it has read, rewind and close)
244-
it "should rewind the file" do
243+
let!(:file) { StringIO.new('test', 'r') } # StringIO is a good stand in for a real File (it has read, rewind and close)
244+
it "closes the file" do
245245
RestClient::Request.any_instance.should_receive(:transmit) #stub transmit so that Request.execute can close the file we pass
246246
@mock_repository.add_datastream :pid => 'mypid', :dsid => 'aaa', :content=>file
247-
lambda {file.read}.should_not raise_error
247+
file.should be_closed
248248
end
249249
describe "and mimeType is not provided" do
250250
describe "and file responds to :content_type" do
@@ -282,10 +282,10 @@ class MockRepository
282282
end
283283
describe "when a file is passed" do
284284
let!(:file) { StringIO.new('test', 'r') } # StringIO is a good stand it for a real File (it has read, rewind and close)
285-
it "should rewind the file" do
285+
it "closes the file" do
286286
RestClient::Request.any_instance.should_receive(:transmit) #stub transmit so that Request.execute can close the file we pass
287287
@mock_repository.modify_datastream :pid => 'mypid', :dsid => 'aaa', :content=>file
288-
lambda {file.read}.should_not raise_error
288+
file.should be_closed
289289
end
290290
describe "and mimeType is not provided" do
291291
describe "and file responds to :content_type" do

0 commit comments

Comments
 (0)