Assert_equal fails on BigDecimal with Oracle in Rails 1.2 RC


#1

This is an example of one of several test failures I get, when using
Rails
1.2 RC2 with an Oracle database setup.

test_tubular_access(WellTest) [./test/unit/well_test.rb:37]:
<1455.0> expected but was
<#BigDecimal:7f98584,‘0.1455E4’,4(12)>.

This is the test code :

assert_equal 1455.0, tubulars[1].shoe_depth

We don’t get this problem when using MySQL as the database.

This is the third, and last, of my test errors when running rake with
Rails
1.2 RC2.

Regards, Lori


#2

Hi Lori, you cannot use decimals with assert_equal. You’ll need to
use the following:

assert_in_delta(expected_float, actual_float, delta, message="")
Passes if expected_float and actual_float are equal within delta
tolerance.

Example:

assert_in_delta 0.05, (50000.0 / 10**6), 0.00001

Good luck,

-Conrad


#3

Ok, thanks. I was pretty sure we should not be using assert_equal
anyway (I
inherented this stuff), but it is puzzling that it worked in Rails
1.1.6,
and does not in Rails 1.2.

Regards, Lori


#4

I guess that would explain it, then :wink: Thanks for all your work on the
Oracle stuff, Michael!


#5

Lori O. wrote:

Ok, thanks. I was pretty sure we should not be using assert_equal
anyway (I inherented this stuff), but it is puzzling that it worked in
Rails 1.1.6, and does not in Rails 1.2.

That’s because the Oracle adapater didn’t support BigDecimals until
after 1.1.6 I believe – so before you were actually just getting back
floats.