Sha256: f85f9458ffdceb86a66d944399e4004b44d9a56fd7780ae832657bd57d2ae289

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))

describe "Property" do
  before :all do
    ENV['TZ'] = 'UTC'

    class ::User
      include DataMapper::Mongo::Resource

      property :id, ObjectId
      property :date_time_field, DateTime
      property :date_field, Date
      property :type, Discriminator
    end
  end

  describe "Class" do
    it "should be typecasted to a string" do
      lambda{
        user = User.create!(:type => User)
      }.should_not raise_error
    end
  end

  describe "DateTime" do
    it "should be typecasted from a Time object" do
      dt_now = DateTime.now
      t_now  = Time.now

      _id = $db.collection('users').insert(:type => 'User', :date_time_field => t_now)

      user = User.get(_id)

      user.date_time_field.class.should be(DateTime)

      Time.parse(user.date_time_field.to_s).to_i.should == Time.parse(dt_now.to_s).to_i
    end
  end

  describe "Date" do
    it "should be typecasted from a Time object" do
      today = Date.today

      _id = $db.collection('users').insert(:type => 'User', :date_field => Time.parse(today.to_s))

      user = User.get(_id)

      user.date_field.class.should be(Date)
      Time.parse(user.date_field.to_s).should == Time.parse(today.to_s)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-mongo-adapter-0.6.0 spec/legacy/property_spec.rb