Commit a1adaf31 by Brian Tatnall

Added :rails_env as a path/url interpolation variable. Useful for networked storage.

parent 8164a6fe
......@@ -161,6 +161,7 @@ module Paperclip
def self.interpolations
@interpolations ||= {
:rails_root => lambda{|attachment,style| RAILS_ROOT },
:rails_env => lambda{|attachment,style| RAILS_ENV },
:class => lambda do |attachment,style|
attachment.instance.class.name.underscore.pluralize
end,
......
......@@ -86,6 +86,26 @@ class AttachmentTest < Test::Unit::TestCase
end
end
context "An attachment with a :rails_env interpolation" do
setup do
@rails_env = "blah"
@id = 1024
rebuild_model :path => ":rails_env/:id.png"
@dummy = Dummy.new
@dummy.stubs(:id).returns(@id)
@file = File.new(File.join(File.dirname(__FILE__),
"fixtures",
"5k.png"))
@dummy.avatar = @file
end
should "return the proper path" do
temporary_rails_env(@rails_env) {
assert_equal "#{@rails_env}/#{@id}.png", @dummy.avatar.path
}
end
end
context "Assigning an attachment" do
setup do
rebuild_model
......
......@@ -5,6 +5,7 @@ require 'mocha'
require 'tempfile'
require 'active_record'
require 'active_support'
begin
require 'ruby-debug'
rescue LoadError
......@@ -43,3 +44,14 @@ def rebuild_model options = {}
has_attached_file :avatar, options
end
end
def temporary_rails_env(new_env)
old_env = defined?(RAILS_ENV) ? RAILS_ENV : nil
silence_warnings do
Object.const_set("RAILS_ENV", new_env)
end
yield
silence_warnings do
Object.const_set("RAILS_ENV", old_env)
end
end
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