rails fixture without timestamping code example
Example 1: rails fixture without timestamping
# test_helper.rb
class Test::Unit::TestCase # or class ActiveSupport::TestCase in Rails 2.3.x
def without_timestamping_of(*klasses)
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
end
Example 2: rails fixture without timestamping
Factory(:article, :created_at => 1.week.ago, :updated_at => 1.week.ago)
Example 3: rails fixture without timestamping
without_timestamping_of Article do
Factory(:article, :created_at => 1.week.ago, :updated_at => 1.week.ago)
end
Example 4: rails fixture without timestamping
without_timestamping_of Article, Comment, User do
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