thoughtbot/paperclip — pull request #1325 by mguymon (2013-08-28 04:18:07+00:00)
Title: correctly set original_filename if File defines original_filename

If a File is passed in with the `original_filename` method, Paperclip tosses an error:

NoMethodError: undefined method `gsub' for nil:NilClass

I stumbled upon this while migrating a database and passing in data to Paperclip along the lines of:

data = open('http://blahblah')
data.class.class_eval { attr_accessor :original_filename }
data.original_filename = "exciting_name"

instance.attachment = data

The `open` call from open-uri wrecks the filename, so I patched in the `original_filename` accessor to override. This worked fine on StringIO but failed with the `NoMethodError` for TempFile.

Paperclip::StringIOAdapter was functioning correctly, but Paperclip::FileAdapter was not. I retooled Paperclip::FileAdapter#cache_current_values to correctly handle original_filename and tweaked Paperclip::StringIOAdapter to avoid changing the `@original_filename` directly, instead relying on the `original_filename=` setter.