Commit 1d756110 by Jon Yurek

Added :filename interpolation

parent 634864d7
...@@ -22,6 +22,10 @@ module Paperclip ...@@ -22,6 +22,10 @@ module Paperclip
end end
end end
def filename attachment, style
"#{basename(attachment, style)}.#{extension(attachment, style)}"
end
def url attachment, style def url attachment, style
raise InfiniteInterpolationError if attachment.options[:url].include?(":url") raise InfiniteInterpolationError if attachment.options[:url].include?(":url")
attachment.url(style) attachment.url(style)
......
...@@ -83,12 +83,26 @@ class InterpolationsTest < Test::Unit::TestCase ...@@ -83,12 +83,26 @@ class InterpolationsTest < Test::Unit::TestCase
assert_equal "1234", Paperclip::Interpolations.url(attachment, :style) assert_equal "1234", Paperclip::Interpolations.url(attachment, :style)
end end
should "raise if infinite loop detcted reinterpolatin :url" do should "raise if infinite loop detcted reinterpolating :url" do
attachment = mock attachment = mock
attachment.expects(:options).returns({:url => ":url"}) attachment.expects(:options).returns({:url => ":url"})
assert_raises(Paperclip::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) } assert_raises(Paperclip::InfiniteInterpolationError){ Paperclip::Interpolations.url(attachment, :style) }
end end
should "return the filename as basename.extension" do
attachment = mock
attachment.expects(:styles).returns({})
attachment.expects(:original_filename).returns("one.jpg").times(3)
assert_equal "one.jpg", Paperclip::Interpolations.filename(attachment, :style)
end
should "return the filename as basename.extension when format supplied" do
attachment = mock
attachment.expects(:styles).returns({:style => {:format => :png}})
attachment.expects(:original_filename).returns("one.jpg").times(2)
assert_equal "one.png", Paperclip::Interpolations.filename(attachment, :style)
end
should "return the timestamp" do should "return the timestamp" do
now = Time.now now = Time.now
attachment = mock attachment = mock
......
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