Marcin Seroczyński
2011-Mar-09 18:24 UTC
ActiveRecord serialize method not returning YAML array in test environment.
Hello, I''ve got a problem with deserialization of AR "serialize" method (http://apidock.com/rails/ActiveRecord/Base/serialize/class) in my tests. It just gives me pure String instead of my data Array. Example: User > AR::Base serialize :roles, Array end Console: u = User.new u.roles = ["admin", "support"] u.save # => true User.first.roles # => ["admin", "support"] In test environment: User.first.roles # => "--- \n- admin\n" it is a String. It seems that YAML serialize is not working there but I have no idea what to do to get it working. I was already trying to figure it out with these, but with no luck. https://rails.lighthouseapp.com/projects/8994/tickets/5002-nested-objects-dont-deserialized-completely-rails-3-beta-4 http://itsignals.cascadia.com.au/?p=10 http://stackoverflow.com/questions/4705867/rails-doesnt-load-classes-on-deserializing-yaml-marshal-objects http://blog.sbf5.com/?p=39 Any advice would be greatly appreciated. Martin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marcin Seroczyński
2011-Mar-10 15:13 UTC
Re: ActiveRecord serialize method not returning YAML array in test environment.
After all to bypass this I needed to call the data in database directly without involvement of "serialize" AR method. YAML::load(User.first.roles_before_type_cast) And now test environment also directly parses the data and give me correct roles Array. On 9 Mar, 19:24, Marcin Seroczyński <mar...-nNLkqzqjKSbvte4fiY5lbg@public.gmane.org> wrote:> Hello, > > I''ve got a problem with deserialization of AR "serialize" method > (http://apidock.com/rails/ActiveRecord/Base/serialize/class) in my > tests. > It just gives me pure String instead of my data Array. > > Example: > User > AR::Base > serialize:roles, Array > end > > Console: > u = User.new > u.roles = ["admin", "support"] > u.save > # => true > > User.first.roles > # => ["admin", "support"] > > In test environment: > User.first.roles > # => "--- \n- admin\n" > > it is a String. It seems that YAMLserializeis not working there but > I have no idea what to do to get it working. > > I was already trying to figure it out with these, but with no luck.https://rails.lighthouseapp.com/projects/8994/tickets/5002-nested-obj...http://itsignals.cascadia.com.au/?p=10http://stackoverflow.com/questions/4705867/rails-doesnt-load-classes-...http://blog.sbf5.com/?p=39 > > Any advice would be greatly appreciated. > Martin-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.