Skip to content

Commit af7a99c

Browse files
author
Jon Yurek
committed
Fixed bug with DateTimes not having a #to_i method.
1 parent a05fb27 commit af7a99c

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

lib/paperclip/attachment.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def content_type
187187
# lives in the <attachment>_updated_at attribute of the model.
188188
def updated_at
189189
time = instance_read(:updated_at)
190-
time && time.to_i
190+
time && time.to_f.to_i
191191
end
192192

193193
# Paths and URLs can have a number of variables interpolated into them

test/attachment_test.rb

+6-5
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,10 @@ def do_after_all; end
531531
@attachment.stubs(:instance_read).with(:file_name).returns("5k.png")
532532
@attachment.stubs(:instance_read).with(:content_type).returns("image/png")
533533
@attachment.stubs(:instance_read).with(:file_size).returns(12345)
534-
now = Time.now
535-
Time.stubs(:now).returns(now)
536-
@attachment.stubs(:instance_read).with(:updated_at).returns(Time.now)
534+
dtnow = DateTime.now
535+
@now = Time.now
536+
Time.stubs(:now).returns(@now)
537+
@attachment.stubs(:instance_read).with(:updated_at).returns(dtnow)
537538
end
538539

539540
should "return a correct url even if the file does not exist" do
@@ -542,11 +543,11 @@ def do_after_all; end
542543
end
543544

544545
should "make sure the updated_at mtime is in the url if it is defined" do
545-
assert_match %r{#{Time.now.to_i}$}, @attachment.url(:blah)
546+
assert_match %r{#{@now.to_i}$}, @attachment.url(:blah)
546547
end
547548

548549
should "make sure the updated_at mtime is NOT in the url if false is passed to the url method" do
549-
assert_no_match %r{#{Time.now.to_i}$}, @attachment.url(:blah, false)
550+
assert_no_match %r{#{@now.to_i}$}, @attachment.url(:blah, false)
550551
end
551552

552553
context "with the updated_at field removed" do

0 commit comments

Comments
 (0)