App works but test/unit fail w/ hash (undefined method 'each_key' for :String)

T

Toddnix

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 self.domains.length > 0 #the domains hash exists
self.domains.each_key {|dom| #<- HERE IS WHERE IT BOMBS OUT!!
if not dom == "ADMIN"
self.domains.delete(dom)
self.domains[@ref.key_desc] = '1'
end
}
else
self.domains = {@ref.key_desc => '1'}
end
write_attribute "domains", User.domain2str(self.domains)
end

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.
 
F

Florian Aßmann

Hi Toddnix,

forgot the `serialize :domains, Hash' ?

Florian

Am 07.06.2007 um 18:30 schrieb Toddnix:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top