# Issue with serialized fields and testing

**URL:** <https://www.ruby-forum.com/t/issue-with-serialized-fields-and-testing/169643>\
**Category:** Rails\
**Created:** [June 6, 2009, 3:49am UTC](https://www.ruby-forum.com/t/issue-with-serialized-fields-and-testing/169643 "2009-06-06T03:49:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![supasta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ebca7d/32.png) [@supasta](https://www.ruby-forum.com/u/supasta)\
**Post date:** [June 6, 2009, 3:49am UTC](https://www.ruby-forum.com/t/issue-with-serialized-fields-and-testing/169643/1 "2009-06-06T03:49:01Z")

</div>

Hi all,

I have a work-around for my problem, but there’s clearly something I  
don’t quite understand going on here and I’d like to learn.

I have a model that has a serialized field. In the unit test for that  
model I’m checking the field contents. In my fixture I have

foo:  
items: “\<%=[3,8].to\_yaml%\>”

(thanks to Fred earlier for helping me get the fixtures loading  
without error - needed the quotes around the yaml)

and in the test I have

assert things(:foo).items == [3,8]

and… the test fails. The problem is that things(:foo).items ends up  
being an array that has a single element, the string ‘3 - 8’. For  
longer arrays the string becomes ‘3 - 8 - 1 - 2 - 3’, for example.

I can get around this by explicitly stating the yaml string as

manage\_domains: “— \n- 3\n- 8”

which leads to the assertion being true… but… it’s inelegant, and  
I don’t understand why the workaround is even necessary. It would be a  
lot easier to use and understand if I could get the first version  
working. From a couple of tests (printing to stdout) I think .to\_yaml  
should be putting in the new-lines, but it seems not to be in this  
case.

Anyone care to enlighten me as to why the first version doesn’t work,  
please?

-Chris W
