Skip to content

Commit

Permalink
Merge pull request #1418 from samvera/patch-12.2
Browse files Browse the repository at this point in the history
Always rewind IO content even when the file is new.
  • Loading branch information
jeremyf committed Jan 24, 2020
2 parents 4fb5c8e + 73777f5 commit 877e1a8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/active_fedora/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ def uploaded_file?(payload)
end

def local_or_remote_content(ensure_fetch = true)
return @content if new_record?

@content ||= ensure_fetch ? remote_content : @ds_content
@content ||= ensure_fetch ? remote_content : @ds_content unless new_record?
@content.rewind if behaves_like_io?(@content)
@content
end
Expand Down
17 changes: 17 additions & 0 deletions spec/unit/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@
end
end

context 'when file is new and content behaves like io' do
let(:file_content) { "hello world" }

before do
af_file.uri = "http://localhost:8983/fedora/rest/test/1234/abcd"
af_file.content = StringIO.new(file_content)
allow(af_file).to receive(:new_record?).and_return(true)
end

describe "#content" do
it 'can be re-read' do
expect(af_file.content.read).to eq file_content
expect(af_file.content.read).to eq file_content
end
end
end

describe "#mime_type" do
let(:parent) { ActiveFedora::Base.create }
before do
Expand Down

0 comments on commit 877e1a8

Please sign in to comment.