diff --git a/lib/shrine/uploaded_file.rb b/lib/shrine/uploaded_file.rb index b1547117..60a6cc2e 100644 --- a/lib/shrine/uploaded_file.rb +++ b/lib/shrine/uploaded_file.rb @@ -170,6 +170,7 @@ def rewind # opened IO object. def close io.close if opened? + @io = nil end # Returns whether the file has already been opened. diff --git a/test/plugin/rack_response_test.rb b/test/plugin/rack_response_test.rb index a0cdb449..b3a5386c 100644 --- a/test/plugin/rack_response_test.rb +++ b/test/plugin/rack_response_test.rb @@ -106,8 +106,11 @@ uploaded_file = @uploader.upload(fakeio) uploaded_file.open response = uploaded_file.to_rack_response + + existing_io = uploaded_file.to_io + response[2].close - assert uploaded_file.to_io.closed? + assert existing_io.closed? end it "returns ranged responses when :range is given" do diff --git a/test/uploaded_file_test.rb b/test/uploaded_file_test.rb index da52e992..eb8ad4ff 100644 --- a/test/uploaded_file_test.rb +++ b/test/uploaded_file_test.rb @@ -241,6 +241,14 @@ def uploaded_file(data = {}) uploaded_file.storage.expects(:open).never uploaded_file.close end + + it "leaves the UploadedFile no longer #opened?" do + uploaded_file = @uploader.upload(fakeio) + uploaded_file.open + uploaded_file.close + + refute uploaded_file.opened? + end end describe "#url" do