středa 23. ledna 2008

ar_fixture: BigDecimal and YAML problem

When we used ar_fixture plugin, we found bug with BigDecimal. When we called Amount.to_fixture, this record was generated:

amount_03246:
deleted_at:
id: 3246
value: !ruby/object:BigDecimal {}
currency: 203


classic to_yaml on Amount class works fine. So I think that problem was violated by merging hash or some other magic ;-) in to_fixture method

Solution is easy (similiar as BigDecimal and YAML don't get along): in ar_fixture.rb override BigDecimal.to_yaml method like this:

class BigDecimal
alias :_original_to_yaml :to_yaml
def to_yaml (opts={},&block)
to_s.to_yaml(opts,&block)
end
end

1 komentář:

Anonymní řekl(a)...
Tento komentář byl odstraněn administrátorem blogu.