# Unit Tests do not migrate correctly

**URL:** <https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941>\
**Category:** Rails\
**Created:** [April 5, 2008, 8:33am UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941 "2008-04-05T08:33:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alan9608](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@Alan9608](https://www.ruby-forum.com/u/Alan9608)\
**Post date:** [April 5, 2008, 8:33am UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941/1 "2008-04-05T08:33:46Z")

</div>

I have a collumn in my model which is a :decimal, :precision-

> 10, :scale=\>2 It needs to hold numbers  
> from 0 to 4294967295.

This is the output from inet\_aton(‘xxx.xxx.xxx.xxx’) in mysql. I NEED  
to have an unsigned integer or else it MUST be big int for other, less  
flexible databases.

The development migrations work great. The correct table is built and  
the number range is fine.  
However, if I try to use the test feature built into rails projects,  
it creates a table in the name\_test database with the :decimal column  
turned into an :integer(10). Of course, the fixtures will not load  
and I am hooped.

No one seems to have run across this? I even emailed Dave T. of  
‘Agile Web D. with Rails: Second Edition, 2nd Edition’ fame.  
He said he uses :decimal columns all the time and never has any  
problems.

Maybe no one has tried to put a number like 2190349144 into a test  
fixture.

Is there a fix for this?

---

<div class="post-metadata">

**Author:** ![Alan9608](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@Alan9608](https://www.ruby-forum.com/u/Alan9608)\
**Post date:** [April 5, 2008, 11:36am UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941/2 "2008-04-05T11:36:08Z")

</div>

On Apr 5, 7:32 am, Alan9608 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> However, if I try to use the test feature built into rails projects,  
> it creates a table in the name\_test database with the :decimal column  
> turned into an :integer(10). Of course, the fixtures will not load  
> and I am hooped.

It could be a problem with the schema dumper. In your environment.rb  
have your tried changing the schema dumper from :ruby to :sql ?

Fred

---

<div class="post-metadata">

**Author:** ![Alan9608](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@Alan9608](https://www.ruby-forum.com/u/Alan9608)\
**Post date:** [April 5, 2008, 10:01pm UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941/3 "2008-04-05T22:01:22Z")

</div>

On Sat, Apr 5, 2008 at 2:32 AM, Alan9608 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the number range is fine.  
> Maybe no one has tried to put a number like 2190349144 into a test  
> fixture.
> 
> Is there a fix for this?

You ran the migrations against your development db only I’m guessing.

Maybe rake db:test:prepare would fix this.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Alan9608](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@Alan9608](https://www.ruby-forum.com/u/Alan9608)\
**Post date:** [April 9, 2008, 9:38pm UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941/4 "2008-04-09T21:38:13Z")

</div>

Thanks Frederick. That solved the test migration.

On Apr 5, 3:35 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Alan9608](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@Alan9608](https://www.ruby-forum.com/u/Alan9608)\
**Post date:** [April 5, 2008, 10:39pm UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941/5 "2008-04-05T22:39:34Z")

</div>

Alan9608 wrote:

> I have a collumn in my model which is a :decimal, :precision-
> 
> > 10, :scale=\>2 It needs to hold numbers  
> > from 0 to 4294967295.
> 
> This is the output from inet\_aton(‘xxx.xxx.xxx.xxx’) in mysql.

Shouldn’t we disregard the underlying 32-bits, and store IP address  
numbers in  
“dotted octet notation” as strings? If ‘192.168.2.100’ was (literally)  
good  
enough for our grandparents, isn’t it good enough for us?

–  
Phlip

---

<div class="post-metadata">

**Author:** ![Alan9608](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@Alan9608](https://www.ruby-forum.com/u/Alan9608)\
**Post date:** [April 9, 2008, 9:39pm UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941/6 "2008-04-09T21:39:23Z")

</div>

Thanks Rick. Frederick C. came up with the solution.

---

<div class="post-metadata">

**Author:** ![Alan9608](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/0ea827/32.png) [@Alan9608](https://www.ruby-forum.com/u/Alan9608)\
**Post date:** [April 9, 2008, 9:44pm UTC](https://www.ruby-forum.com/t/unit-tests-do-not-migrate-correctly/133941/7 "2008-04-09T21:44:40Z")

</div>

The dotted decimal version as a string requires a lot of error  
checking to eliminate invalid ip addresses. Also, it doesn’t sort  
well at all. Internally, most of the networking commands use the long  
integer value (which you can test by going: “ping 174260237”)and  
seeing that it works fine but translates the number back to  
‘10.99.0.13’

No, I think there is a perfectly valid reason to want to store the ip  
number as an integer.  
(and I could possible be someone’s grandfather!)
