I found a little bug with the Coercion in Integer from a string
All is in this gits : https://gist.github.com/daab3c0f31340c2f6460
attribute :int, Integer
attribute :float, Float
o = MyObject.new(
:int => "334490140000101135",
:float => "334490140000101135"
describe "Coercion" do
it 'should have good conversion in int' do
o.int.should == 334490140000101135
it 'should have good conversion in float' do
o.float.should == 334490140000101135.0
# $ rspec virtus_coercion_bug.rb [11:59:47
# 1) Coercion should have good conversion in int
# Failure/Error: o.int.should == 334490140000101135
# expected: 334490140000101135
# got: 334490140000101120 (using ==)
# # ./virtus_coercion_bug.rb:17:in `block (2 levels) in <top (required)>'
# Finished in 0.00043 seconds
# 2 examples, 1 failure
# Failed examples:
# rspec ./virtus_coercion_bug.rb:16 # Coercion should have good conversion in int
The coercion to_integer on String do a to_f on string before doing the to_i but in ruby we have :
I think this is caused by transforming the string into a float first (to evaluate any scientific notation included in the number) and then convert to an integer.
While I could probably write something to parse scientific notation and then evaluate it in-ruby, I think maybe we should just remove that as a requirement, and just look for positive and negative integers and floats, and that's it.
@solnic, @dkubb :
I fixed it: #111
Please review and merge, if you think my solution is OK.