Sha256: 74231f7175d4a60239a19f1d72b52043d05318a37bfc7570ae57116ff04c7a38

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

# -*- coding: utf-8 -*-
require "sixarm_ruby_to_id_test"

describe Hash do

  describe "#to_date_id casts to a date id" do

    describe "with fields for year, month, day #=> YYYY-MM-DD" do

      it "works with string keys" do
        {"year" => "2000", "month" => "12", "day" => "31"}.to_date_id.must_equal "2000-12-31"
      end

      it "works with symbol keys" do
        {year: "2000", month: "12", day: "31"}.to_date_id.must_equal "2000-12-31"
      end

    end

    describe "with fields for year, month, day any of which are blank strings #=> nil" do

      it "year is blank #=> nil" do
        {year: "", month: "12", day: "31"}.to_date_id.must_be_nil
      end

      it "month is blank #=> nil" do
        {year: "2000", month: "", day: "31"}.to_date_id.must_be_nil
      end

      it "day is blank #=> nil" do
        {year: "2000", month: "12", day: ""}.to_date_id.must_be_nil
      end

    end

    describe "without fields for year, or month, or day #=> nil" do

      it "missing year #=> nil" do
        {month: "12", day: "31"}.to_date_id.must_be_nil
      end

      it "missing month #=> nil" do
        {year: "2000", day: "31"}.to_date_id.must_be_nil
      end

      it "missing day #=> nil" do
        {year: "2000", month: "12"}.to_date_id.must_be_nil
      end

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sixarm_ruby_to_id-2.0.0 test/sixarm_ruby_to_id_test/hash_test.rb
sixarm_ruby_to_id-1.1.3 test/sixarm_ruby_to_id_test/hash_test.rb