Sha256: e6486e28dc6d1217c30bfdfe8ee651c33a1888a18c3d6d44cd05e30f73416e26

Contents?: true

Size: 981 Bytes

Versions: 8

Compression:

Stored size: 981 Bytes

Contents

require "spec_helper"

describe DataMapper::Property::ParseDate do
  subject { property }
  let(:property) { Article.properties[:created_at] }
  let(:datetime) { DateTime.parse("2011-08-21T18:02:52.249Z") }

  describe "#dump" do
    subject { property.dump value }
    let(:value) { datetime }

    it { should eq("__type" => "Date", "iso" => datetime.utc.iso8601(3)) }

    context "when value is nil" do
      let(:value) { nil }

      it { should be_nil }
    end
  end

  describe "#load" do
    subject { property.load value }
    let(:value) { {"__type" => "Date", "iso" => datetime.utc.iso8601(3)} }

    it { should eq(datetime) }

    context "when value is in string" do
      let(:value) { "2011-08-21T18:02:52.249Z" }

      it { should eq(datetime) }
    end

    context "when value is nil" do
      let(:value) { nil }

      it { should be_nil }
    end
  end

  describe "#valid?" do
    subject { property.valid? datetime }

    it { should be_true }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
dm-parse-0.3.2 spec/parse_date_spec.rb
dm-parse-0.3.1 spec/parse_date_spec.rb
dm-parse-0.3.0 spec/parse_date_spec.rb
dm-parse-0.2.3 spec/parse_date_spec.rb
dm-parse-0.2.2 spec/parse_date_spec.rb
dm-parse-0.2.1 spec/parse_date_spec.rb
dm-parse-0.2.0 spec/parse_date_spec.rb
dm-parse-0.1.0 spec/parse_date_spec.rb