# YAML fixtures - type detection

**URL:** <https://www.ruby-forum.com/t/yaml-fixtures-type-detection/134250>\
**Category:** Rails\
**Created:** [April 9, 2008, 9:18am UTC](https://www.ruby-forum.com/t/yaml-fixtures-type-detection/134250 "2008-04-09T09:18:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 9, 2008, 9:18am UTC](https://www.ruby-forum.com/t/yaml-fixtures-type-detection/134250/1 "2008-04-09T09:18:28Z")

</div>

Hi all,

just wanted to share a little information (and vent my frustration)  
after almost 2h trying to figure out what was wrong with my  
application.

It’s a simple application which I’m using to train TDD.

Basically my authentication tests were not working. Manual tests on  
development environment all worked. I’m using hashing and salting, so  
that one item on my users.yml (fixtures for users model) is:

one:  
id: 1  
email: removed\_email\_address@domain.invalid  
hashed\_password: d8bb56db4f9783c2e8932aa4153bdf7ae5188ec2  
salt: 263168800.183078117780979

The hashed password + salt combination is obviously one that works,  
taken from development environment.

My tests would fail on authentication: would always say user found but  
authentication failed. Trough some debugging and logging I noticed  
that the expected\_password was different than the stored\_password.

OK, this kinda isolated the problem: what could possibly be causing  
the passwords to be wrong? I checked them billions of times, the entry  
on the development environment users table was exactly the same as the  
one on the users fixtures…

So I decided to use MySQL Query Browser to check the test database.  
Upon listing the rows on the users table I found the problem: the salt  
was WRONG! It was NOT the same as the one on my users fixture! How the  
hell could it be different? After all, the database is rolled back  
after each test, so even the change\_password tests I had would not  
have changed the salt…

Upon comparing both salts, I noticed that the difference was that one  
of them was trimmed. While the original (from fixture) was  
263168800.183078117780979 the one on the table was  
263168800.1830781177 (I didn’t count the number of trimmed characters  
so this might be wrong).

So, the only thing that makes sense would be that, when inserting  
stuff into the database from fixtures, Ruby/Rails thinks that the salt  
field is a float and stores it accordingly, although it is supposed to  
be a string.

I’ve checked [http://ar.rubyonrails.org/classes/Fixtures.html](http://ar.rubyonrails.org/classes/Fixtures.html) but they  
don’t mention anything about column types, and I guess they don’t  
need: It would make total sense IMO if the type wasn’t detected from  
fixtures but read from the table structure!

The way I made it work, then, was by using this fixture (note the  
quotation marks):

one:  
id: 1  
email: removed\_email\_address@domain.invalid  
hashed\_password: d8bb56db4f9783c2e8932aa4153bdf7ae5188ec2  
salt: “263168800.183078117780979”

So, a long post for just a simple hint: double check those fixtures!
