diff --git a/lib/paperclip/attachment.rb b/lib/paperclip/attachment.rb index 6fabb67de..c85fb9b52 100644 --- a/lib/paperclip/attachment.rb +++ b/lib/paperclip/attachment.rb @@ -95,7 +95,7 @@ def assign uploaded_file uploaded_file = uploaded_file.to_file(:original) close_uploaded_file = uploaded_file.respond_to?(:close) else - instance_write(:uploaded_file, uploaded_file) + instance_write(:uploaded_file, uploaded_file) if uploaded_file end return nil unless valid_assignment?(uploaded_file) @@ -209,7 +209,7 @@ def uploaded_file def original_filename instance_read(:file_name) end - + # Returns the size of the file as originally assigned, and lives in the # _file_size attribute of the model. def size diff --git a/test/attachment_test.rb b/test/attachment_test.rb index a5235b6ad..91ef6a380 100644 --- a/test/attachment_test.rb +++ b/test/attachment_test.rb @@ -855,6 +855,10 @@ def do_after_all; end assert @attachment.dirty? end + should "set uploaded_file for access beyond the paperclip lifecycle" do + assert_equal @file, @attachment.uploaded_file + end + context "and saved" do setup do @attachment.save diff --git a/test/helper.rb b/test/helper.rb index 91f39488e..ad86b0421 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,5 +1,6 @@ require 'rubygems' require 'tempfile' +require 'pathname' require 'test/unit' require 'shoulda'