Sha256: 3cb8133894adeb21975d95fc4925277ceebedf0606f5b517b2dde2a2e55a66cf

Contents?: true

Size: 1.34 KB

Versions: 6

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

require "cases/helper"

class Mixin < ActiveRecord::Base
end

class TouchTest < ActiveRecord::TestCase
  fixtures :mixins

  setup do
    travel_to Time.now
  end

  def test_update
    stamped = Mixin.new

    assert_nil stamped.updated_at
    assert_nil stamped.created_at
    stamped.save
    assert_equal Time.now, stamped.updated_at
    assert_equal Time.now, stamped.created_at
  end

  def test_create
    obj = Mixin.create
    assert_equal Time.now, obj.updated_at
    assert_equal Time.now, obj.created_at
  end

  def test_many_updates
    stamped = Mixin.new

    assert_nil stamped.updated_at
    assert_nil stamped.created_at
    stamped.save
    assert_equal Time.now, stamped.created_at
    assert_equal Time.now, stamped.updated_at

    old_updated_at = stamped.updated_at

    travel 5.minutes
    stamped.lft_will_change!
    stamped.save

    assert_equal Time.now, stamped.updated_at
    assert_equal old_updated_at, stamped.created_at
  end

  def test_create_turned_off
    Mixin.record_timestamps = false

    mixin = Mixin.new

    assert_nil mixin.updated_at
    mixin.save
    assert_nil mixin.updated_at

  # Make sure Mixin.record_timestamps gets reset, even if this test fails,
  # so that other tests do not fail because Mixin.record_timestamps == false
  ensure
    Mixin.record_timestamps = true
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ibm_db-5.5.0 test/cases/mixin_test.rb
ibm_db-5.4.1 test/cases/mixin_test.rb
ibm_db-5.4.0 test/cases/mixin_test.rb
ibm_db-5.3.2 test/cases/mixin_test.rb
ibm_db-5.3.1 test/cases/mixin_test.rb
ruby-on-quails-0.1.0 activerecord/test/cases/mixin_test.rb