test/paperclip_test.rb in thoughtbot-paperclip-2.2.8 vs test/paperclip_test.rb in thoughtbot-paperclip-2.2.9.1
- old
+ new
@@ -28,10 +28,18 @@
Paperclip.expects(:path_for_command).with("convert").returns("convert")
Paperclip.expects(:bit_bucket).returns("/dev/null")
Paperclip.expects(:"`").with("convert one.jpg two.jpg 2>/dev/null")
Paperclip.run("convert", "one.jpg two.jpg")
end
+
+ should "log the command when :log_command is set" do
+ Paperclip.options[:log_command] = true
+ Paperclip.expects(:bit_bucket).returns("/dev/null")
+ Paperclip.expects(:log).with("this is the command 2>/dev/null")
+ Paperclip.expects(:"`").with("this is the command 2>/dev/null")
+ Paperclip.run("this","is the command")
+ end
end
should "raise when sent #processor and the name of a class that exists but isn't a subclass of Processor" do
assert_raises(Paperclip::PaperclipError){ Paperclip.processor(:attachment) }
end
@@ -42,10 +50,22 @@
should "return a class when sent #processor and the name of a class under Paperclip" do
assert_equal ::Paperclip::Thumbnail, Paperclip.processor(:thumbnail)
end
+ should "call a proc sent to check_guard" do
+ @dummy = Dummy.new
+ @dummy.expects(:one).returns(:one)
+ assert_equal :one, @dummy.avatar.send(:check_guard, lambda{|x| x.one })
+ end
+
+ should "call a method name sent to check_guard" do
+ @dummy = Dummy.new
+ @dummy.expects(:one).returns(:one)
+ assert_equal :one, @dummy.avatar.send(:check_guard, :one)
+ end
+
context "Paperclip.bit_bucket" do
context "on systems without /dev/null" do
setup do
File.expects(:exists?).with("/dev/null").returns(false)
end
@@ -162,9 +182,47 @@
@dummy2.avatar.valid?
first_errors = @dummy2.avatar.errors
@dummy2.avatar.valid?
assert_equal first_errors, @dummy2.avatar.errors
end
+ end
+ end
+
+ context "a validation with an if guard clause" do
+ setup do
+ Dummy.send(:"validates_attachment_presence", :avatar, :if => lambda{|i| i.foo })
+ @dummy = Dummy.new
+ end
+
+ should "attempt validation if the guard returns true" do
+ @dummy.expects(:foo).returns(true)
+ @dummy.avatar.expects(:validate_presence).returns(nil)
+ @dummy.valid?
+ end
+
+ should "not attempt validation if the guard returns false" do
+ @dummy.expects(:foo).returns(false)
+ @dummy.avatar.expects(:validate_presence).never
+ @dummy.valid?
+ end
+ end
+
+ context "a validation with an unless guard clause" do
+ setup do
+ Dummy.send(:"validates_attachment_presence", :avatar, :unless => lambda{|i| i.foo })
+ @dummy = Dummy.new
+ end
+
+ should "attempt validation if the guard returns true" do
+ @dummy.expects(:foo).returns(false)
+ @dummy.avatar.expects(:validate_presence).returns(nil)
+ @dummy.valid?
+ end
+
+ should "not attempt validation if the guard returns false" do
+ @dummy.expects(:foo).returns(true)
+ @dummy.avatar.expects(:validate_presence).never
+ @dummy.valid?
end
end
def self.should_validate validation, options, valid_file, invalid_file
context "with #{validation} validation and #{options.inspect} options" do