Commit 34c9b747 by Ahmad Sherif Committed by Jon Yurek

Add handling for S3 path option being a proc

parent 3398282e
......@@ -158,7 +158,7 @@ module Paperclip
end
unless @options[:url].to_s.match(/\A:s3.*url\Z/) || @options[:url] == ":asset_host"
@options[:path] = @options[:path].gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system/, '')
@options[:path] = path_option.gsub(/:url/, @options[:url]).gsub(/\A:rails_root\/public\/system/, '')
@options[:url] = ":s3_path_url"
end
@options[:url] = @options[:url].inspect if @options[:url].is_a?(Symbol)
......
......@@ -1474,6 +1474,26 @@ describe Paperclip::Storage::S3 do
end
end
context "path is a proc" do
before do
rebuild_model storage: :s3,
path: ->(attachment) { attachment.instance.attachment_path }
@dummy = Dummy.new
@dummy.class_eval do
def attachment_path
'/some/dynamic/path'
end
end
@dummy.avatar = stringy_file
end
it "returns a correct path" do
assert_match '/some/dynamic/path', @dummy.avatar.path
end
end
private
def rails_env(env)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment