Fix bug in #remove_#{column} when filename is set explicitly #735

Merged
merged 1 commit into from May 5, 2012
@@ -296,11 +296,11 @@ def initialize(record, column, options={})
end
def write_identifier
- if remove?
- record.write_uploader(serialization_column, '')
- elsif not uploader.identifier.blank?
- record.write_uploader(serialization_column, uploader.identifier)
- end
+ return if record.frozen? || uploader.identifier.blank?
+
+ value = remove? ? '' : uploader.identifier
+
+ record.write_uploader(serialization_column, value)
end
def identifier
@@ -419,6 +419,20 @@ def download! file
describe '#destroy' do
+ it "should not raise an error with a custom filename" do
+ @uploader.class_eval do
+ def filename
+ "page.jpeg"
+ end
+ end
+
+ @event.image = stub_file('test.jpeg')
+ @event.save.should be_true
+ expect {
+ @event.destroy
+ }.to_not raise_error
+ end
+
it "should do nothing when no file has been assigned" do
@event.save.should be_true
@event.destroy