Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Moved the geometry proc running to assignment instead of initialization

  • Loading branch information...
commit 9e71b211c762786f5cd09142efee33c2442049bc 1 parent f07487f
@jyurek jyurek authored
Showing with 19 additions and 2 deletions.
  1. +6 −0 lib/paperclip/attachment.rb
  2. +13 −2 test/attachment_test.rb
View
6 lib/paperclip/attachment.rb
@@ -90,6 +90,7 @@ def assign uploaded_file
@dirty = true
+ solidify_style_definitions
post_process if valid?
# Reset the file size if the original file was reprocessed.
@@ -303,6 +304,11 @@ def normalize_style_definition #:nodoc:
:convert_options => extra_options_for(name)
}.merge(@styles[name])
end
+ end
+ end
+
+ 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
View
15 test/attachment_test.rb
@@ -182,8 +182,19 @@ def thumb; "-thumb"; end
@attachment = Dummy.new.avatar
end
- should "have the correct geometry" do
- assert_equal "50x50#", @attachment.styles[:normal][:geometry]
+ should "not run the procs immediately" do
+ assert_kind_of Proc, @attachment.styles[:normal][:geometry]
+ end
+
+ context "when assigned" do
+ setup do
+ @file = StringIO.new(".")
+ @attachment.assign(@file)
+ end
+
+ should "have the correct geometry" do
+ assert_equal "50x50#", @attachment.styles[:normal][:geometry]
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.