Forum: Ruby on Rails binary info in test fixtures?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
17fa7869b96bf7243280fe0c158b78d3?d=identicon&s=25 Michael Lascarides (mlas)
on 2006-04-17 20:01
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
17fa7869b96bf7243280fe0c158b78d3?d=identicon&s=25 Michael Lascarides (mlas)
on 2006-04-19 22:52
bumped... still seeking solution...

much thanks,

michael
3ec705c5dd3480c6268b72c5617e8dae?d=identicon&s=25 Michael Smedberg (Guest)
on 2006-04-19 23:16
(Received via mailing list)
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 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.
This topic is locked and can not be replied to.