Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed bug with DateTimes not having a #to_i method.

  • Loading branch information...
commit af7a99c5f0105a00cd3da88defad1369def0317a 1 parent a05fb27
@jyurek jyurek authored
Showing with 7 additions and 6 deletions.
  1. +1 −1  lib/paperclip/attachment.rb
  2. +6 −5 test/attachment_test.rb
View
2  lib/paperclip/attachment.rb
@@ -187,7 +187,7 @@ def content_type
# lives in the <attachment>_updated_at attribute of the model.
def updated_at
time = instance_read(:updated_at)
- time && time.to_i
+ time && time.to_f.to_i
end
# Paths and URLs can have a number of variables interpolated into them
View
11 test/attachment_test.rb
@@ -531,9 +531,10 @@ def do_after_all; end
@attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
@attachment.stubs(:instance_read).with(:content_type).returns("image/png")
@attachment.stubs(:instance_read).with(:file_size).returns(12345)
- now = Time.now
- Time.stubs(:now).returns(now)
- @attachment.stubs(:instance_read).with(:updated_at).returns(Time.now)
+ dtnow = DateTime.now
+ @now = Time.now
+ Time.stubs(:now).returns(@now)
+ @attachment.stubs(:instance_read).with(:updated_at).returns(dtnow)
end
should "return a correct url even if the file does not exist" do
@@ -542,11 +543,11 @@ def do_after_all; end
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)
+ assert_match %r{#{@now.to_i}$}, @attachment.url(:blah)
end
should "make sure the updated_at mtime is NOT in the url if false is passed to the url method" do
- assert_no_match %r{#{Time.now.to_i}$}, @attachment.url(:blah, false)
+ assert_no_match %r{#{@now.to_i}$}, @attachment.url(:blah, false)
end
context "with the updated_at field removed" do
Please sign in to comment.
Something went wrong with that request. Please try again.