# Error loading fixture with serialized field - undefined method \`key?'

**URL:** <https://www.ruby-forum.com/t/error-loading-fixture-with-serialized-field-undefined-method-key/169467>\
**Category:** Rails\
**Created:** [June 4, 2009, 1:56am UTC](https://www.ruby-forum.com/t/error-loading-fixture-with-serialized-field-undefined-method-key/169467 "2009-06-04T01:56:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [June 4, 2009, 1:56am UTC](https://www.ruby-forum.com/t/error-loading-fixture-with-serialized-field-undefined-method-key/169467/1 "2009-06-04T01:56:57Z")

</div>

Hi all,

I’m hoping some kind person out there can help me understand what I’m  
doing wrong…

I have a user model, which has two serialized fields-  
class User \< ActiveRecord::Base  
acts\_as\_authentic :validate\_email\_field =\> false

has\_many :user\_domain\_roles

serialize :admin\_domains  
serialize :manage\_domains  
end

and I’m trying to create some test fixtures for this model:  
usersiteadmin:  
id: 2  
login: usersiteadmin  
password\_salt: \<%= salt = User.unique\_token %\>  
crypted\_password: \<%= Authlogic::CryptoProviders::Sha512.encrypt  
(“usersiteadmin” + salt) %\>  
persistence\_token:  
6cde0674657a8a313ce952df979de2830309aa4c11ca65805dd00bfdc65dbcc2f5e36718660a1d2e68c1a08c276d996763985d2f06fd3d076eb7bc4d97b1e317  
login\_count: 1  
last\_request\_at: 2009-03-09 19:56:38  
last\_login\_at: 2009-03-09 19:56:38  
current\_login\_at: 2009-03-09 19:56:38  
last\_login\_ip: MyString  
current\_login\_ip: MyString  
first\_name: usersiteadminfname  
last\_name: usersiteadminlname  
email: removed\_email\_address@domain.invalid  
admin\_domains: \<%= [1,3,8,2,9,10,11,7].to\_yaml %\>  
manage\_domains: — []

However, when I try to rake I get this error when the fixtures are  
loading:  
NoMethodError: undefined method `key?’ for [1, 3, 8, 2, 9, 10, 11,  
{“7\nmanage\_domains”=\>"— []"}]:Array

I get the exact same error when I try to generate the string  
explicitly:  
admin\_domains: \<%= “— \n- 1\n- 3\n- 8\n- 2\n- 9\n- 10\n- 11\n- 7”  
%\>

I have no idea why it doesn’t like my fixture and would really  
appreciate any pointers on the matter. Thanks

-Chris W

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [June 4, 2009, 9:43am UTC](https://www.ruby-forum.com/t/error-loading-fixture-with-serialized-field-undefined-method-key/169467/2 "2009-06-04T09:43:01Z")

</div>

On Jun 4, 12:55 am, Chris [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have no idea why it doesn’t like my fixture and would really  
> appreciate any pointers on the matter. Thanks

You might want to stick quotes around that string to stop yaml parsing  
it

Fred

---

<div class="post-metadata">

**Author:** ![chris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/958977/32.png) [@chris](https://www.ruby-forum.com/u/chris)\
**Post date:** [June 6, 2009, 1:26am UTC](https://www.ruby-forum.com/t/error-loading-fixture-with-serialized-field-undefined-method-key/169467/3 "2009-06-06T01:26:52Z")

</div>

Hi Fred,

Yup - quotes did the trick! In hindsight that makes perfect sense, but  
it would have taken me a long time to figure it out on my own.

Much thanks!

-Chris W

On Thu, Jun 4, 2009 at 3:42 AM, Frederick
