On Sep 7, 2010, at 7:18 AM, Zhenning Guan wrote:
>> In your original post you said you were getting two bankbook items after
>> the change. Do you want one or two? And where is the 2nd one coming
>> from?
> I always want one . after change the code I got two. and the original
> test doesn't fail.
> def process!
> #transaction block
> bank.withdraw
> bankbook = user.bank.bankbooks.build
> bankbook.withdraw
> #end
> end
>
> #change version
> def process!
> #transaction block
> bank.withdraw
> #end
> end
>
> so obviously, bankbook = user.bank.bankbooks.build create a bankbook
> record. and bank.withdraw jsut about decrease money.
> after change. bank.withdraw Model#withdraw the withdraw method will
> create bankbook record. so we just don't need create bankbook in
> process! but my test is
> @ning.bankbooks.last.price.should == BigDecimal('1.00')
> @ning.bankbooks.last.action.should == 'withdraw'
> it doesn't care how many bankbook record was created.
So are you asking how to specify that only one record gets created? If so, your
suggestion a few posts back is good:
lambda{ withdrawal.process! }.should change {Bankbook.count}.by(1)
HTH,
David
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users