Sha256: a1e7af314795d2c20240cd569666af5fe4d12722fde08f2a5c4bfaf62657332f

Contents?: true

Size: 1.1 KB

Versions: 13

Compression:

Stored size: 1.1 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(:$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

13 entries across 13 versions & 1 rubygems

Version Path
mongomapper_ext-0.5.2 test/types/test_timestamp.rb
mongomapper_ext-0.5.1 test/types/test_timestamp.rb
mongomapper_ext-0.5.0 test/types/test_timestamp.rb
mongomapper_ext-0.4.0 test/types/test_timestamp.rb
mongomapper_ext-0.3.0 test/types/test_timestamp.rb
mongomapper_ext-0.2.4 test/types/test_timestamp.rb
mongomapper_ext-0.2.3 test/types/test_timestamp.rb
mongomapper_ext-0.2.2 test/types/test_timestamp.rb
mongomapper_ext-0.2.1 test/types/test_timestamp.rb
mongomapper_ext-0.2.0 test/types/test_timestamp.rb
mongomapper_ext-0.1.5 test/types/test_timestamp.rb
mongomapper_ext-0.1.4 test/types/test_timestamp.rb
mongomapper_ext-0.1.3 test/types/test_timestamp.rb