# Binary info in test fixtures?

**URL:** <https://www.ruby-forum.com/t/binary-info-in-test-fixtures/58017>\
**Category:** Rails\
**Created:** [April 17, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/binary-info-in-test-fixtures/58017 "2006-04-17T20:01:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [April 17, 2006, 8:01pm UTC](https://www.ruby-forum.com/t/binary-info-in-test-fixtures/58017/1 "2006-04-17T20:01:39Z")

</div>

Hi all,

I have a shopping application I am testing, and one of the models is an  
Order model, within which a credit card number is encrypted and stored  
in the db (mysql) as a BLOB field. When trying to run my unit tests, I  
cannot get my model fixtures to load the encrypted data.

If, in my dynamic fixture (YAML) file, I could have access to my app’s  
models, the problem would be trivial… instead of:

valid\_order:  
id: 1  
storefront\_id: 1  
total\_charge: 50.00  
tax\_charge: 5.00  
ship\_charge: 10.00  
…  
payment\_number: 4111111111111111

(which doesn’t work), I could insert:

valid\_order:  
id: 1  
storefront\_id: 1  
total\_charge: 50.00  
tax\_charge: 5.00  
ship\_charge: 10.00  
…  
payment\_number: \<%= Order.encrypt(“4111111111111111”) %\>

which would give me what I want.

My question is one of two things: a) Is there any ruby code I can put in  
the YAML file to “require” the Order model? Or, b) is there a way to get  
the BLOB data out of the database and stick it in a fixture?

thanks,

Michael

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [April 19, 2006, 10:52pm UTC](https://www.ruby-forum.com/t/binary-info-in-test-fixtures/58017/2 "2006-04-19T22:52:00Z")

</div>

bumped… still seeking solution…

much thanks,

michael

---

<div class="post-metadata">

**Author:** ![dreamwave](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/7feea3/32.png) [@dreamwave](https://www.ruby-forum.com/u/dreamwave)\
**Post date:** [April 19, 2006, 11:16pm UTC](https://www.ruby-forum.com/t/binary-info-in-test-fixtures/58017/3 "2006-04-19T23:16:36Z")

</div>

If you have the binary data you want to store in YAML, I believe you can  
use  
the !binary directive to encode that data into your YAML file- some info  
is  
at [Binary Data Language-Independent Type for YAML™&nbsp;Version&nbsp;1.1](http://yaml.org/type/binary.html).

I think you might want to write a bit of code that will get the relevant  
binary data and convert it to Base64. Then you can store that string  
into  
your YAML and not have to worry about it again.

I think you can also do ‘require’ in your YAML (in a \<% %\> block) in the  
same way as in any other code, though the Rails load order may make this  
difficult in practice.
