Sha256: 430fc0e2467e70dbc6f4174bdcd429aa8236d7ecf9313ded4d135c93137e6a67

Contents?: true

Size: 1.11 KB

Versions: 11

Compression:

Stored size: 1.11 KB

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

  describe "#typecast" do
    subject { property.typecast value }

    let(:value) { "2011-08-21T18:02:52.249Z" }

    it { should be_a(DateTime) }
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dm-parse-0.3.13 spec/parse_date_spec.rb
dm-parse-0.3.12 spec/parse_date_spec.rb
dm-parse-0.3.11 spec/parse_date_spec.rb
dm-parse-0.3.10 spec/parse_date_spec.rb
dm-parse-0.3.9 spec/parse_date_spec.rb
dm-parse-0.3.8 spec/parse_date_spec.rb
dm-parse-0.3.7 spec/parse_date_spec.rb
dm-parse-0.3.6 spec/parse_date_spec.rb
dm-parse-0.3.5 spec/parse_date_spec.rb
dm-parse-0.3.4 spec/parse_date_spec.rb
dm-parse-0.3.3 spec/parse_date_spec.rb