Commit 1d756110 by Jon Yurek

Added :filename interpolation

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