spec/unit/virtus/attribute/integer_spec.rb in virtus-0.0.5 vs spec/unit/virtus/attribute/integer_spec.rb in virtus-0.0.6
- old
+ new
@@ -1,18 +1,20 @@
require 'spec_helper'
describe Virtus::Attribute::Integer do
it_should_behave_like 'Attribute' do
- let(:attribute_name) { :age }
- let(:attribute_value) { 28 }
- let(:attribute_value_other) { "28" }
+ let(:attribute_name) { :age }
+ let(:attribute_value) { 28 }
+ let(:attribute_value_other) { "28" }
+ let(:attribute_default) { 0 }
+ let(:attribute_default_proc) { lambda { |instance, attribute| attribute.name == :age } }
end
- describe '#typecast' do
- let(:attribute) { Virtus::Attribute::Integer.new(:age) }
+ describe '#coerce' do
+ let(:attribute) { described_class.new(:age) }
- subject { attribute.typecast(value) }
+ subject { attribute.coerce(value) }
context "with an integer" do
let(:value) { 24 }
it { should eql(value) }
end
@@ -85,11 +87,11 @@
context 'with a negative decimal' do
let(:value) { BigDecimal('-24.35') }
it { should eql(-24) }
end
- [ Object.new, true, '00.0', '0.', '-.0', 'string' ].each do |non_num_value|
- context "does not typecast non-numeric value #{non_num_value.inspect}" do
+ [ Object.new, true, false, '00.0', '0.', '-.0', 'string' ].each do |non_num_value|
+ context "does not coerce non-numeric value #{non_num_value.inspect}" do
let(:value) { non_num_value }
it { should equal(non_num_value) }
end
end
end