Sha256: 849f4141b3089afa8559a5dd112d721e40f1801aec1a1cd2b7956b94e2fd11e1

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

require 'spec_helper'

module Id
  module Model
    module TypeCasts

      describe Cast do
        it 'requires a type' do
          expect { Cast.new(1).type }.to raise_error NotImplementedError
        end

        it 'requires a conversion' do
          expect { Cast.new(1).conversion }.to raise_error NotImplementedError
        end

      end

      describe Date do
        it 'casts strings to dates' do
          Date.new("06-06-1983").cast.should eq ::Date.new(1983, 6, 6)
        end
      end

      describe Time do
        it 'casts strings to Times' do
          Time.new("06-06-1983").cast.should eq ::Time.parse("06-06-1983")
        end

        it 'does nothing if the value is already of the correct type' do
          time = ::Time.now
          Time.new(time).cast.should eq time
        end
      end

      describe Money do
        it 'ints or strings to Money' do
          Money.new("500").cast.should eq ::Money.new(5_00)
          Money.new(500).cast.should eq ::Money.new(5_00)
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
id-0.0.12 spec/lib/id/model/type_casts_spec.rb
id-0.0.11 spec/lib/id/model/type_casts_spec.rb
id-0.0.10 spec/lib/id/model/type_casts_spec.rb
id-0.0.9 spec/lib/id/model/type_casts_spec.rb
id-0.0.8 spec/lib/id/model/type_casts_spec.rb
id-0.0.7 spec/lib/id/model/type_casts_spec.rb