Skip to content

Commit

Permalink
Moved the geometry proc running to assignment instead of initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Yurek committed Jan 23, 2009
1 parent f07487f commit 9e71b21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/paperclip/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions test/attachment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9e71b21

Please sign in to comment.