App works but test/unit fail w/ hash (undefined method 'each

My app takes an account_type from a reference table when creating user
accounts and, when the obj is saved the model the numeric key for the
account_type is used for a lookup to get a user role which is then put
into a hash (used for app authorization). Before actually saving into
the DB the model converts the hash into a string. The following code
shows the conversion method:

before_save :hash_domains
def hash_domains
#first get the domain name from the ref_tables via the key
@ref = RefTable.find[:first,
:conditions => [“key_name = ?”, self.account_type])

if > 0 #the domains hash exists {|dom| #<- HERE IS WHERE IT BOMBS OUT!!
if not dom == “ADMIN”[@ref.key_desc] = ‘1’
else = {@ref.key_desc => ‘1’}
write_attribute “domains”, User.domain2str(

Obviously when test/unit runs the domains obj is a string and doesn’t
have the each_key method. What is killing me is the app WORKS with
identical data when a record is inserted/created. Also, oddly the
error from test/unit includes a correctly formatted ‘domains’ obj
string, which shouldn’t exist until the last line. This makes me think
that even though the .save method is only called once in the
test, it’s actually be called twice in test/unit.

Any thoughts are much appreciated.

Hi Toddnix,

forgot the `serialize :domains, Hash’ ?


Am 07.06.2007 um 18:30 schrieb Toddnix:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs