Skip to content
This repository has been archived by the owner on Sep 9, 2019. It is now read-only.

Commit

Permalink
Multiple processors can be specified, and styles can take hashes inst…
Browse files Browse the repository at this point in the history
…ead of strings/arrays
  • Loading branch information
Jon Yurek committed Dec 24, 2008
1 parent f1118c6 commit 1d02330
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/paperclip/attachment.rb
Expand Up @@ -267,6 +267,12 @@ def normalize_style_definition
:whiny => @whiny,
:convert_options => extra_options_for(name)
}
else
@styles[name] = {
:processors => @processors,
:whiny => @whiny,
:convert_options => extra_options_for(name)
}.merge(@styles[name])
end
end
end
Expand Down
40 changes: 40 additions & 0 deletions test/attachment_test.rb
Expand Up @@ -134,6 +134,46 @@ class AttachmentTest < Test::Unit::TestCase
end
end

context "An attachment with both 'normal' and hash-style styles" do
setup do
rebuild_model :styles => {
:normal => ["50x50#", :png],
:hash => { :geometry => "50x50#", :format => :png }
}
@dummy = Dummy.new
@attachment = @dummy.avatar
end

[:processors, :whiny, :convert_options, :geometry, :format].each do |field|
should "have the same #{field} field" do
assert_equal @attachment.styles[:normal][field], @attachment.styles[:hash][field]
end
end
end

context "An attachment with multiple processors" do
setup do
class Paperclip::Test < Paperclip::Processor; end
@style_params = { :once => {:one => 1, :two => 2} }
rebuild_model :processors => [:thumbnail, :test], :styles => @style_params
@dummy = Dummy.new
@file = StringIO.new("...")
@file.stubs(:to_tempfile).returns(@file)
Paperclip::Test.stubs(:make).returns(@file)
Paperclip::Thumbnail.stubs(:make).returns(@file)
end

context "when assigned" do
setup { @dummy.avatar = @file }

before_should "call #make on all specified processors" do
expected_params = @style_params[:once].merge({:processors => [:thumbnail, :test], :whiny => nil, :convert_options => ""})
Paperclip::Thumbnail.expects(:make).with(@file, expected_params).returns(@file)
Paperclip::Test.expects(:make).with(@file, expected_params).returns(@file)
end
end
end

context "Assigning an attachment with post_process hooks" do
setup do
rebuild_model :styles => { :something => "100x100#" }
Expand Down

0 comments on commit 1d02330

Please sign in to comment.