Commit ab9a0f7e by Janko Marohnić Committed by Jon Yurek

Add #blank? to Attachment

parent eb466fac
...@@ -320,6 +320,10 @@ module Paperclip ...@@ -320,6 +320,10 @@ module Paperclip
alias :present? :file? alias :present? :file?
def blank?
not present?
end
# Determines whether the instance responds to this attribute. Used to prevent # Determines whether the instance responds to this attribute. Used to prevent
# calculations on fields we won't even store. # calculations on fields we won't even store.
def instance_respond_to?(attr) def instance_respond_to?(attr)
......
...@@ -6,6 +6,29 @@ class Dummy; end ...@@ -6,6 +6,29 @@ class Dummy; end
class AttachmentTest < Test::Unit::TestCase class AttachmentTest < Test::Unit::TestCase
context "presence" do
setup do
rebuild_class
@dummy = Dummy.new
end
context "when file not set" do
should "not be present" do
assert @dummy.avatar.blank?
refute @dummy.avatar.present?
end
end
context "when file set" do
setup { @dummy.avatar = File.new(fixture_file("50x50.png"), "rb") }
should "be present" do
refute @dummy.avatar.blank?
assert @dummy.avatar.present?
end
end
end
should "process :original style first" do should "process :original style first" do
file = File.new(fixture_file("50x50.png"), 'rb') file = File.new(fixture_file("50x50.png"), 'rb')
rebuild_class :styles => { :small => '100x>', :original => '42x42#' } rebuild_class :styles => { :small => '100x>', :original => '42x42#' }
......
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