Sha256: 3063e55aaa6bbc4956aaecee2aab5ccbddc150c101dcfd97fd5a74d4a794822b

Contents?: true

Size: 942 Bytes

Versions: 10

Compression:

Stored size: 942 Bytes

Contents

require 'pathname'
require Pathname(__FILE__).dirname.parent.expand_path + 'spec_helper'

describe DataMapper::Types::EpochTime do

  describe ".dump" do
    it "should accept Time objects" do
      t = Time.now

      DataMapper::Types::EpochTime.dump(t, :property).should == t.to_i
    end

    it "should accept DateTime objects" do
      t = DateTime.now

      DataMapper::Types::EpochTime.dump(t, :property).should == Time.parse(t.to_s).to_i
    end

    it "should accept Integer objects" do
      t = Time.now.to_i

      DataMapper::Types::EpochTime.dump(t, :property).should == t
    end
  end

  describe ".load" do

    it "should load null as nil" do
      DataMapper::Types::EpochTime.load(nil, :property).should == nil
    end

    it "should load #{Time.now.to_i} as Time.at(#{Time.now.to_i})" do
      t = Time.now.to_i
      DataMapper::Types::EpochTime.load(Time.now.to_i, :property).should == Time.at(t)
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dm-types-0.9.4 spec/unit/epoch_time_spec.rb
dm-types-0.9.3 spec/unit/epoch_time_spec.rb
dm-types-0.9.2 spec/unit/epoch_time_spec.rb
dm-types-0.9.11 spec/unit/epoch_time_spec.rb
dm-types-0.9.10 spec/unit/epoch_time_spec.rb
dm-types-0.9.5 spec/unit/epoch_time_spec.rb
dm-types-0.9.6 spec/unit/epoch_time_spec.rb
dm-types-0.9.9 spec/unit/epoch_time_spec.rb
dm-types-0.9.7 spec/unit/epoch_time_spec.rb
dm-types-0.9.8 spec/unit/epoch_time_spec.rb