test/paperclip_test.rb in paperclip-2.3.11 vs test/paperclip_test.rb in paperclip-2.3.12
- old
+ new
@@ -1,48 +1,13 @@
require './test/helper'
class PaperclipTest < Test::Unit::TestCase
context "Calling Paperclip.run" do
- setup do
- Paperclip.options[:image_magick_path] = nil
- Paperclip.options[:command_path] = nil
- Paperclip::CommandLine.stubs(:'`')
+ should "run the command with Cocaine" do
+ Cocaine::CommandLine.expects(:new).with("convert", "stuff").returns(stub(:run))
+ Paperclip.run("convert", "stuff")
end
-
- should "execute the right command with :image_magick_path" do
- Paperclip.options[:image_magick_path] = "/usr/bin"
- Paperclip.expects(:log).with(includes('[DEPRECATION]'))
- Paperclip.expects(:log).with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
- Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
- Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
- end
-
- should "execute the right command with :command_path" do
- Paperclip.options[:command_path] = "/usr/bin"
- Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{/usr/bin/convert ['"]one.jpg['"] ['"]two.jpg['"]}))
- Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
- end
-
- should "execute the right command with no path" do
- Paperclip::CommandLine.expects(:"`").with(regexp_matches(%r{convert ['"]one.jpg['"] ['"]two.jpg['"]}))
- Paperclip.run("convert", ":one :two", :one => "one.jpg", :two => "two.jpg")
- end
-
- should "tell you the command isn't there if the shell returns 127" do
- with_exitstatus_returning(127) do
- assert_raises(Paperclip::CommandNotFoundError) do
- Paperclip.run("command")
- end
- end
- end
-
- should "tell you the command isn't there if an ENOENT is raised" do
- assert_raises(Paperclip::CommandNotFoundError) do
- Paperclip::CommandLine.stubs(:"`").raises(Errno::ENOENT)
- Paperclip.run("command")
- end
- end
end
context "Paperclip.each_instance_with_attachment" do
setup do
@file = File.new(File.join(FIXTURES_DIR, "5k.png"), 'rb')
@@ -70,10 +35,23 @@
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 "get a class from a namespaced class name" do
+ class ::One; class Two; end; end
+ assert_equal ::One::Two, Paperclip.class_for("One::Two")
+ end
+
+ should "raise when class doesn't exist in specified namespace" do
+ class ::Three; end
+ class ::Four; end
+ assert_raise NameError do
+ Paperclip.class_for("Three::Four")
+ end
+ end
+
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
@@ -221,19 +199,19 @@
setup do
@dummy.avatar = valid_file
@dummy.valid?
end
should "not have an error when assigned a valid file" do
- assert_equal 0, @dummy.errors.length, @dummy.errors.full_messages.join(", ")
+ assert_equal 0, @dummy.errors.size, @dummy.errors.full_messages.join(", ")
end
end
context "and assigned an invalid file" do
setup do
@dummy.avatar = invalid_file
@dummy.valid?
end
should "have an error when assigned a valid file" do
- assert @dummy.errors.length > 0
+ assert @dummy.errors.size > 0
end
end
end
end