Sha256: 742d8bbec87b85137f54a85da29803f577d9b3fc3e2e75e9ef6ee3f3b5ae5fe8
Contents?: true
Size: 1.36 KB
Versions: 1
Compression:
Stored size: 1.36 KB
Contents
require 'spec_helper' module Structural 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 Integer do subject { Integer.new("2").cast } it 'casts strings to integers' do expect(subject).to eql(2) end end describe Float do subject { Float.new("2.0").cast } it 'casts strings to floats' do expect(subject).to eql(2.0) 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
structural-0.0.3 | spec/lib/structural/model/type_casts_spec.rb |