Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Moved style solidification to the post_process method, this also fixe…
Browse files Browse the repository at this point in the history
…s the reprocess! method
  • Loading branch information
rob-at-thewebfellas authored and Jon Yurek committed Feb 22, 2009
1 parent 723618a commit ec09660
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/paperclip/attachment.rb
Expand Up @@ -92,7 +92,6 @@ def assign uploaded_file

@dirty = true

solidify_style_definitions
post_process if valid?

# Reset the file size if the original file was reprocessed.
Expand Down Expand Up @@ -314,9 +313,8 @@ def normalize_style_definition #:nodoc:

def solidify_style_definitions #:nodoc:
@styles.each do |name, args|
if @styles[name][:geometry].respond_to?(:call)
@styles[name][:geometry] = @styles[name][:geometry].call(instance)
end
@styles[name][:geometry] = @styles[name][:geometry].call(instance) if @styles[name][:geometry].respond_to?(:call)
@styles[name][:processors] = @styles[name][:processors].call(instance) if @styles[name][:processors].respond_to?(:call)
end
end

Expand All @@ -336,6 +334,7 @@ def extra_options_for(style) #:nodoc:

def post_process #:nodoc:
return if @queued_for_write[:original].nil?
solidify_style_definitions
return if fire_events(:before)
post_process_styles
return if fire_events(:after)
Expand Down
23 changes: 22 additions & 1 deletion test/attachment_test.rb
Expand Up @@ -265,7 +265,28 @@ def thumb; "-thumb"; end
end
end
end


context "An attachment with :processors that is a proc" do
setup do
rebuild_model :styles => { :normal => '' }, :processors => lambda { |a| [ :test ] }
@attachment = Dummy.new.avatar
end

should "not run the proc immediately" do
assert_kind_of Proc, @attachment.styles[:normal][:processors]
end

context "when assigned" do
setup do
@attachment.assign(StringIO.new("."))
end

should "have the correct processors" do
assert_equal [ :test ], @attachment.styles[:normal][:processors]
end
end
end

context "An attachment with erroring processor" do
setup do
rebuild_model :processor => [:thumbnail], :styles => { :small => '' }, :whiny_thumbnails => true
Expand Down
2 changes: 2 additions & 0 deletions test/integration_test.rb
Expand Up @@ -39,6 +39,7 @@ class IntegrationTest < Test::Unit::TestCase
setup do
Dummy.class_eval do
has_attached_file :avatar, :styles => { :thumb => "150x25#" }
has_attached_file :avatar, :styles => { :thumb => "150x25#", :dynamic => lambda { |a| '50x50#' } }
end
@d2 = Dummy.find(@dummy.id)
@d2.avatar.reprocess!
Expand All @@ -47,6 +48,7 @@ class IntegrationTest < Test::Unit::TestCase

should "create its thumbnails properly" do
assert_match /\b150x25\b/, `identify "#{@dummy.avatar.path(:thumb)}"`
assert_match /\b50x50\b/, `identify "#{@dummy.avatar.path(:dynamic)}"`
end
end
end
Expand Down

0 comments on commit ec09660

Please sign in to comment.