From 6deeaf76e7235eebf1158d9ff9b2c7ad4021b4c7 Mon Sep 17 00:00:00 2001 From: Barry Hess Date: Thu, 7 Aug 2008 14:43:45 -0500 Subject: [PATCH] Add tests for convert_options thumbnail setting. --- test/integration_test.rb | 32 ++++++++++++++++++++++++++++++++ test/thumbnail_test.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/test/integration_test.rb b/test/integration_test.rb index aaf1a25d9..61ef52dc6 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -91,6 +91,38 @@ class IntegrationTest < Test::Unit::TestCase end end + context "A model with no thumbnail_convert_options setting" do + setup do + rebuild_model :styles => { :large => "300x300>", + :medium => "100x100", + :thumb => ["32x32#", :gif] }, + :default_style => :medium, + :url => "/:attachment/:class/:style/:id/:basename.:extension", + :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension" + @dummy = Dummy.new + end + + should "have its definition return nil when asked about convert_options" do + assert ! Dummy.attachment_definitions[:avatar][:thumbnail_convert_options] + end + + context "redefined to have convert_options setting" do + setup do + rebuild_model :styles => { :large => "300x300>", + :medium => "100x100", + :thumb => ["32x32#", :gif] }, + :thumbnail_convert_options => "-strip -depth 8", + :default_style => :medium, + :url => "/:attachment/:class/:style/:id/:basename.:extension", + :path => ":rails_root/tmp/:attachment/:class/:style/:id/:basename.:extension" + end + + should "have its definition return convert_options value when asked about convert_options" do + assert_equal "-strip -depth 8", Dummy.attachment_definitions[:avatar][:thumbnail_convert_options] + end + end + end + context "A model with a filesystem attachment" do setup do rebuild_model :styles => { :large => "300x300>", diff --git a/test/thumbnail_test.rb b/test/thumbnail_test.rb index 14f8c29aa..0f96137a5 100644 --- a/test/thumbnail_test.rb +++ b/test/thumbnail_test.rb @@ -90,6 +90,10 @@ class ThumbnailTest < Test::Unit::TestCase should "have whiny_thumbnails turned on by default" do assert @thumb.whiny_thumbnails end + + should "have convert_options set to nil by default" do + assert_equal nil, @thumb.convert_options + end should "send the right command to convert when sent #make" do @thumb.expects(:system).with do |arg| @@ -103,5 +107,27 @@ class ThumbnailTest < Test::Unit::TestCase assert_match /100x50/, `identify #{dst.path}` end end + + context "being thumbnailed with convert options set" do + setup do + @thumb = Paperclip::Thumbnail.new(@file, "100x50#", format=nil, whiny_thumbnails=true, convert_options="-strip -depth 8") + end + + should "have convert_options value set" do + assert_equal "-strip -depth 8", @thumb.convert_options + end + + should "send the right command to convert when sent #make" do + @thumb.expects(:system).with do |arg| + arg.match %r{convert\s+"#{File.expand_path(@thumb.file.path)}"\s+-scale\s+\"x50\"\s+-crop\s+\"100x50\+114\+0\"\s+\+repage\s+-strip\s+-depth\s+8\s+".*?"} + end + @thumb.make + end + + should "create the thumbnail when sent #make" do + dst = @thumb.make + assert_match /100x50/, `identify #{dst.path}` + end + end end end