Commit 9421f2d3 by Jon Yurek

Added extra tests for mtime

parent 87d700dd
......@@ -87,7 +87,7 @@ module Paperclip
# performance reasons.
def url style = default_style
url = original_filename.nil? ? interpolate(@default_url, style) : interpolate(@url, style)
[url, mtime].compact.join(url.include?("?") ? "&" : "?")
updated_at ? [url, updated_at].compact.join(url.include?("?") ? "&" : "?") : url
end
# Returns the path of the attachment as defined by the :path option. If the
......@@ -141,7 +141,7 @@ module Paperclip
instance[:"#{name}_file_name"]
end
def mtime
def updated_at
time = instance[:"#{name}_updated_at"]
time && time.to_i
end
......
......@@ -174,6 +174,8 @@ class AttachmentTest < Test::Unit::TestCase
@instance.stubs(:[]).with(:test_file_name).returns("5k.png")
@instance.stubs(:[]).with(:test_content_type).returns("image/png")
@instance.stubs(:[]).with(:test_file_size).returns(12345)
now = Time.now
Time.stubs(:now).returns(now)
@instance.stubs(:[]).with(:test_updated_at).returns(Time.now)
end
......@@ -182,6 +184,20 @@ class AttachmentTest < Test::Unit::TestCase
assert_match %r{^/tests/41/blah/5k\.png}, @attachment.url(:blah)
end
should "make sure the updated_at mtime is in the url if it is defined" do
assert_match %r{#{Time.now.to_i}$}, @attachment.url(:blah)
end
context "with the updated_at field removed" do
setup do
@instance.stubs(:[]).with(:test_updated_at).returns(nil)
end
should "only return the url without the updated_at when sent #url" do
assert_match "/tests/41/blah/5k.png", @attachment.url(:blah)
end
end
should "return the proper path when filename has a single .'s" do
assert_equal "./test/../tmp/tests/dummies/original/41/5k.png", @attachment.path
end
......@@ -203,7 +219,7 @@ class AttachmentTest < Test::Unit::TestCase
context "and assigned a file" do
setup do
now = Time.mktime(2008)
now = Time.now
Time.stubs(:now).returns(now)
@instance.expects(:[]=).with(:test_file_name,
File.basename(@file.path))
......
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