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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
C010ce052273c0af88ad56ac290ed683?d=identicon&s=25 Toddnix (Guest)
on 2007-06-07 18:40
(Received via mailing list)
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 <model>.save method is only called once in the
test, it's actually be called twice in test/unit.

Any thoughts are much appreciated.
Ee469623eb1b8e6e35d192822b9c4aa2?d=identicon&s=25 Florian Aßmann (Guest)
on 2007-06-07 19:12
(Received via mailing list)
Hi Toddnix,

forgot the `serialize :domains, Hash' ?


Am 07.06.2007 um 18:30 schrieb Toddnix:
This topic is locked and can not be replied to.