Sha256: db35d7477032136024c94ba73eca17ffb8346a45ce9e4608a5826d77acaf9a37

Contents?: true

Size: 1.12 KB

Versions: 3

Compression:

Stored size: 1.12 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_datime => end_time.utc)

      Event.count.should == 2
      events = Event.all(:conditions => {:$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

3 entries across 3 versions & 1 rubygems

Version Path
mongoid_ext-0.7.1 test/types/test_timestamp.rb
mongoid_ext-0.6.2 test/types/test_timestamp.rb
mongoid_ext-0.6.1 test/types/test_timestamp.rb