Permalink
Browse files

Added extra tests for mtime

  • Loading branch information...
1 parent 87d700d commit 9421f2d3a87b3d74ed8615e75bb2a4e202ea6632 @jyurek jyurek committed Aug 1, 2008
Showing with 19 additions and 3 deletions.
  1. +2 −2 lib/paperclip/attachment.rb
  2. +17 −1 test/attachment_test.rb
@@ -87,7 +87,7 @@ def assign uploaded_file
# 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 @@ def original_filename
instance[:"#{name}_file_name"]
end
- def mtime
+ def updated_at
time = instance[:"#{name}_updated_at"]
time && time.to_i
end
View
@@ -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))

0 comments on commit 9421f2d

Please sign in to comment.