Commit e54b5bdf by Jon Yurek

Assigning an empty string does nothing

parent fab4aea3
......@@ -181,6 +181,7 @@ end
# This stuff needs to be run after Paperclip is defined.
require 'paperclip/io_adapters/registry'
require 'paperclip/io_adapters/abstract_adapter'
require 'paperclip/io_adapters/empty_string_adapter'
require 'paperclip/io_adapters/identity_adapter'
require 'paperclip/io_adapters/file_adapter'
require 'paperclip/io_adapters/stringio_adapter'
......
......@@ -93,6 +93,7 @@ module Paperclip
ensure_required_accessors!
file = Paperclip.io_adapters.for(uploaded_file)
return nil if not file.assignment?
self.clear(*only_process)
return nil if file.nil?
......
......@@ -23,6 +23,14 @@ module Paperclip
@original_filename = new_filename.gsub(OS_RESTRICTED_CHARACTERS, "_")
end
def nil?
false
end
def assignment?
true
end
private
def destination
......
module Paperclip
class EmptyStringAdapter < AbstractAdapter
def initialize(target)
end
def nil?
false
end
def assignment?
false
end
end
end
Paperclip.io_adapters.register Paperclip::EmptyStringAdapter do |target|
target.is_a?(String) && target.empty?
end
......@@ -47,4 +47,12 @@ class AbstractAdapterTest < Test::Unit::TestCase
assert_equal "awesome_file_name.png", @adapter.original_filename
end
should 'be an assignment' do
assert TestAdapter.new.assignment?
end
should 'not be nil' do
assert !TestAdapter.new.nil?
end
end
require './test/helper'
class EmptyStringAdapterTest < Test::Unit::TestCase
context 'a new instance' do
setup do
@subject = Paperclip.io_adapters.for('')
end
should "return false for a call to nil?" do
assert !@subject.nil?
end
should 'return false for a call to assignment?' do
assert !@subject.assignment?
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment