Michał Szajbe at Code Tunes provides this useful tidbit.
Add a small bit of code to test_helper.rb inside TestCase
def without_timestamping_of(*klasses)After that, just wrap Factory calls in without_timestamping_of to turn off dating.
if block_given?
klasses.delete_if { |klass| !klass.record_timestamps }
klasses.each { |klass| klass.record_timestamps = false }
begin
yield
ensure
klasses.each { |klass| klass.record_timestamps = true }
end
end
end
without_timestamping_of Article, Comment, User doSimple and very useful. Many thanks again to Michał Szajbe at Code Tunes
Factory(:article, :created_at => 1.week.ago, :updated_at => 1.week.ago)
Factory(:comment, :created_at => 1.day.ago)
Factory(:user, :updated_at => 5.hours.ago)
end
No comments:
Post a Comment