From: Peter Vandenabeele Date: 2012-01-24T03:21:00+09:00 Subject: Re: Microrant on Ruy's Math Skills --0023544719808ebbf204b73617ab Content-Type: text/plain; charset=UTF-8 On Mon, Jan 23, 2012 at 6:38 PM, Chad Perrin wrote: > On Mon, Jan 23, 2012 at 08:38:56PM +0900, Peter Vandenabeele wrote: > > > > Thanks for the idea. > > > > I fixed my feature request with this code in > > a library file: > > > > require 'bigdecimal' > > class ::String > > def to_bd > > BigDecimal.new(self) > > end > > end > > > > So it only works on strings (that's what I want). > > > > Now I can say: > > > > describe "balance setter and getter" do > > subject.balance = "15.4".to_bd > > subject.balance.should == "15.4".to_bd > > end > > Is there any reason this would not be better done with symbols than with > strings? > For an initial test without format checking or accessing the database the exact type that is saved is indeed not relevant, so a symbol would be a good idea to reduce GC effort (thanks). But, in this test, I really needed to actually save to the database (and that "balance" column is obviously in "decimal" format). So at that time it would need to be in the exact format. The reason I needed a "real" save is that I have delegated this "balance" to a different model and I had forgotten the :autosave option on the association, which made the save of the associated model fail in the condition that the current model was not changed? The actual test code is more complex and involves saving, and finding the record back from the database and then checking for the value. But I see your point, for simpler test cases a symbol would be a nice and more efficient way to test this. Peter --0023544719808ebbf204b73617ab--