Sha256: dc33f6e4c2c39c7292a636275c54fddd7d899fdfccd3c4f8b63c2951b1375ee3

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'helper'

class TimestampTest < Test::Unit::TestCase
  def from_db
    Event.find(@event.id)
  end

  context "working with timestamps" do
    setup do
      Event.delete_all

      Time.zone = 'UTC'
      @start_time = Time.zone.parse('01-01-2009')
      @end_time = @start_time.tomorrow

      @event = Event.create!(:start_date => @start_time.to_i, :end_date => @end_time.to_i)
    end

    should "store the date" do
      from_db.start_date.to_s.should == @start_time.to_s
    end

    should "be able to convert the time to the given timezone" do
      Time.zone = 'Hawaii'
      from_db.start_date.to_s.should == "2008-12-31 14:00:00 -1000"
    end

    should "be able to compare dates" do
      start_time = @start_time.tomorrow.tomorrow
      end_time = start_time.tomorrow

      @event2 = Event.create!(:start_date => start_time.utc, :end_date => end_time.utc)

      Event.count.should == 2
      events = Event.where("this.start_date >= %d && this.start_date <= %d" % [@event.start_date.yesterday.to_i, @event2.start_date.yesterday.to_i])

      events.should == [@event]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongoid_ext-0.9.0 test/types/test_timestamp.rb