Hi all, I just burned two hours of development time trying to debug this issue. Can someone please tell me if there is a way to disable database caching when running unit tests or another way to avoid running into this type of problem?? This does not work: assert periods(:period1).ongoing? # Asserts true plays(:end_of_first_half).process # Ends the period assert !periods(:period1).ongoing? # Asserts false This DOES work: assert periods(:period1).ongoing? # Asserts true plays(:end_of_first_half).process # Ends the period assert !Period.find(periods(:period1).id).ongoing? # Asserts true I''ve only just now run into this issue after dozens of tests. Am I missing something obvious about expected behavior? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ricky Barnaby wrote:> Hi all, > > I just burned two hours of development time trying to debug this issue. > Can someone please tell me if there is a way to disable database caching > when running unit tests or another way to avoid running into this type > of problem?? > > This does not work: > assert periods(:period1).ongoing? # Asserts true > plays(:end_of_first_half).process # Ends the period > assert !periods(:period1).ongoing? # Asserts false > > This DOES work: > assert periods(:period1).ongoing? # Asserts true > plays(:end_of_first_half).process # Ends the period > assert !Period.find(periods(:period1).id).ongoing? # Asserts true > > I''ve only just now run into this issue after dozens of tests. Am I > missing something obvious about expected behavior?I have run into this same problem, but don''t understand it either. To be safe, I always do a find on the object first, but wish I had a more reliable solution to this as well. I too have wasted lots of debugging time only to find it was just an issue with my test code! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Mar-18 18:39 UTC
Re: Issues with database/object caching and testing
On Mar 18, 3:48 am, Ricky Barnaby <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi all, > > I just burned two hours of development time trying to debug this issue. > Can someone please tell me if there is a way to disable database caching > when running unit tests or another way to avoid running into this type > of problem?? > > This does not work: > assert periods(:period1).ongoing? # Asserts true > plays(:end_of_first_half).process # Ends the period > assert !periods(:period1).ongoing? # Asserts false > > This DOES work: > assert periods(:period1).ongoing? # Asserts true > plays(:end_of_first_half).process # Ends the period > assert !Period.find(periods(:period1).id).ongoing? # Asserts true >I don''t know exactly what this code is doing, but activerecord does cache associations and so on (and fixtures are only loaded once per test when you do periods(:period1). There''s no easy way to disable this, periods(:period1).reload.ongoing? is a little less ugly than other alternatives. Fred> I''ve only just now run into this issue after dozens of tests. Am I > missing something obvious about expected behavior? > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---