Skip to content

Commit

Permalink
Add tests for convert_options thumbnail setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
bjhess committed Aug 7, 2008
1 parent c0257f8 commit 6deeaf7
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/integration_test.rb
Expand Up @@ -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>",
Expand Down
26 changes: 26 additions & 0 deletions test/thumbnail_test.rb
Expand Up @@ -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|
Expand All @@ -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

0 comments on commit 6deeaf7

Please sign in to comment.