test/paperclip_test.rb in paperclip-2.1.5 vs test/paperclip_test.rb in paperclip-2.2.0
- old
+ new
@@ -1,17 +1,51 @@
require 'test/helper'
class PaperclipTest < Test::Unit::TestCase
- context "Calling Paperclip.run" do
+ [:image_magick_path, :convert_path].each do |path|
+ context "Calling Paperclip.run with an #{path} specified" do
+ setup do
+ Paperclip.options[:image_magick_path] = nil
+ Paperclip.options[:convert_path] = nil
+ Paperclip.options[path] = "/usr/bin"
+ end
+
+ should "execute the right command" do
+ Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
+ Paperclip.expects(:bit_bucket).returns("/dev/null")
+ Paperclip.expects(:"`").with("/usr/bin/convert one.jpg two.jpg 2>/dev/null")
+ Paperclip.run("convert", "one.jpg two.jpg")
+ end
+ end
+ end
+
+ context "Calling Paperclip.run with no path specified" do
+ setup do
+ Paperclip.options[:image_magick_path] = nil
+ Paperclip.options[:convert_path] = nil
+ end
+
should "execute the right command" do
- Paperclip.expects(:path_for_command).with("convert").returns("/usr/bin/convert")
+ Paperclip.expects(:path_for_command).with("convert").returns("convert")
Paperclip.expects(:bit_bucket).returns("/dev/null")
- Paperclip.expects(:"`").with("/usr/bin/convert one.jpg two.jpg 2>/dev/null")
+ Paperclip.expects(:"`").with("convert one.jpg two.jpg 2>/dev/null")
Paperclip.run("convert", "one.jpg two.jpg")
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
+
+ should "raise when sent #processor and the name of a class that doesn't exist" do
+ assert_raises(NameError){ Paperclip.processor(:boogey_man) }
+ end
+
+ should "return a class when sent #processor and the name of a class under Paperclip" do
+ assert_equal ::Paperclip::Thumbnail, Paperclip.processor(:thumbnail)
+ end
+
context "Paperclip.bit_bucket" do
context "on systems without /dev/null" do
setup do
File.expects(:exists?).with("/dev/null").returns(false)
end
@@ -35,9 +69,11 @@
context "An ActiveRecord model with an 'avatar' attachment" do
setup do
rebuild_model :path => "tmp/:class/omg/:style.:extension"
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
end
+
+ teardown { @file.close }
should "not error when trying to also create a 'blah' attachment" do
assert_nothing_raised do
Dummy.class_eval do
has_attached_file :blah