Sha256: a371a4ddd2302723e006612283b35a9a46e98ad18afabd4d96347258f04912a1

Contents?: true

Size: 1.23 KB

Versions: 22

Compression:

Stored size: 1.23 KB

Contents

require "helper"

class TestOhmTimestamping < Test::Unit::TestCase
  setup do
    Ohm.flush
  end

  class Person < Ohm::Model
    include Ohm::Timestamping
  end

  context "a new? record" do
    should "have no created_at" do
      assert_nil Person.new.created_at
    end

    should "have no updated_at" do
      assert_nil Person.new.updated_at
    end
  end

  context "on create" do
    setup do
      @now    = Time.utc(2010, 5, 12)
      Timecop.freeze(@now)
      @person = Person.create
      @person = Person[@person.id]
    end


    should "set the created_at equal to the current time" do
      assert_equal @now.to_s, @person.created_at
    end

    should "also set the updated_at equal to the current time" do
      assert_equal @now.to_s, @person.updated_at
    end
  end

  context "on update" do
    setup do
      @person = Person.create
      @old_created_at = @person.created_at.to_s

      @now = Time.utc(2010, 10, 31)
      Timecop.freeze(@now)

      @person.save
      @person = Person[@person.id]
    end

    should "leave created_at unchanged" do
      assert_equal @old_created_at, @person.created_at
    end

    should "set updated_at to the current Time" do
      assert_equal @now.to_s, @person.updated_at
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ohm-contrib-0.0.26 test/test_ohm_timestamping.rb
ohm-contrib-0.0.25 test/test_ohm_timestamping.rb
ohm-contrib-0.0.24 test/test_ohm_timestamping.rb
ohm-contrib-0.0.23 test/test_ohm_timestamping.rb
ohm-contrib-0.0.22 test/test_ohm_timestamping.rb
ohm-contrib-0.0.21 test/test_ohm_timestamping.rb
ohm-contrib-0.0.20 test/test_ohm_timestamping.rb
ohm-contrib-0.0.19 test/test_ohm_timestamping.rb
ohm-contrib-0.0.18 test/test_ohm_timestamping.rb
ohm-contrib-0.0.17 test/test_ohm_timestamping.rb
ohm-contrib-0.0.16 test/test_ohm_timestamping.rb
ohm-contrib-0.0.15 test/test_ohm_timestamping.rb
ohm-contrib-0.0.14 test/test_ohm_timestamping.rb
ohm-contrib-0.0.13 test/test_ohm_timestamping.rb
ohm-contrib-0.0.12 test/test_ohm_timestamping.rb
ohm-contrib-0.0.11 test/test_ohm_timestamping.rb
ohm-contrib-0.0.10 test/test_ohm_timestamping.rb
ohm-contrib-0.0.9 test/test_ohm_timestamping.rb
ohm-contrib-0.0.8 test/test_ohm_timestamping.rb
ohm-contrib-0.0.7 test/test_ohm_timestamping.rb