方法試圖測試:測試查詢與MINITEST Rails的
def self.by_date(date)
where("DATE(created_at) = ?", date)
end
Comments.yml(夾具):
one:
user_id: 1
job_id: 24
content: "This is a test"
電流測試:
require 'test_helper'
require 'date'
class CommentTest < ActiveSupport::TestCase
setup do
@comment = comments(:one)
end
test 'organizes by date' do
@comment.created_at = Date.today
assert_equal @comment.created_at, Comment.by_date(Date.today).first.created_at
end
end
我結束了:
2) Failure:
CommentTest#test_organizes_by_date
--- expected
+++ actual
@@ -1 +1 @@
-Fri, 22 Apr 2016 00:00:00 UTC +00:00
+Fri, 22 Apr 2016 20:48:42 UTC +00:00
我假設有一種更有效的方法來測試這個,但沒有找到運氣。有任何想法嗎?
啊啊完美!它現在有效。謝謝IIya! – user3007294