Skip to content

Commit

Permalink
Added support for :styles option being defined as a Proc.
Browse files Browse the repository at this point in the history
(cherry picked from commit 5799558cb4211bed0fba67df36510a29cfbbd94c)
  • Loading branch information
thijsc authored and Jon Yurek committed Feb 10, 2009
1 parent 3f5516c commit 4dccd53
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/paperclip/attachment.rb
Expand Up @@ -32,6 +32,7 @@ def initialize name, instance, options = {}
@path = options[:path]
@path = @path.call(self) if @path.is_a?(Proc)
@styles = options[:styles]
@styles = @styles.call(self) if @styles.is_a?(Proc)
@default_url = options[:default_url]
@validations = options[:validations]
@default_style = options[:default_style]
Expand Down
12 changes: 12 additions & 0 deletions test/attachment_test.rb
Expand Up @@ -217,6 +217,18 @@ def thumb; "-thumb"; end
end
end

context "An attachment with :styles that is a proc" do
setup do
rebuild_model :styles => lambda{ |attachment| {:thumb => "50x50#", :large => "400x400"} }

@attachment = Dummy.new.avatar
end

should "have the correct geometry" do
assert_equal "50x50#", @attachment.styles[:thumb][:geometry]
end
end

context "An attachment with :url that is a proc" do
setup do
rebuild_model :url => lambda{ |attachment| "path/#{attachment.instance.other}.:extension" }
Expand Down

0 comments on commit 4dccd53

Please sign in to comment.