In my active record model I have declared a ''before_save'' callback, that populates other fields before saving the data. However I am finding all my unit test cases are breaking because it seems the ''before_save'' callback is not getting called during a unit test run? In fact I have to provide the missing filed in unit test fixture yml file. How can I make the model behave the same in the unit test run as it does when I create and save a model object from the rails console? -- Kind Regards, Rajinder Yadav -- 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.
On 14 March 2010 12:08, Rajinder Yadav <devguy.ca-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In my active record model I have declared a ''before_save'' callback, that > populates other fields before saving the data. However I am finding all my > unit test cases are breaking because it seems the ''before_save'' callback is > not getting called during a unit test run? In fact I have to provide the > missing filed in unit test fixture yml file.Do you mean it is not calling the filter when loading data from the fixture file into the db before the test starts? If so I believe that is as it should be. Your code is not run when setting up prior to running the test. If you mean that the filter is not being called when save is called from your controller during the test then that is a problem, the filter should be called in this case. Colin> > How can I make the model behave the same in the unit test run as it does > when I create and save a model object from the rails console? > > > -- > Kind Regards, > Rajinder Yadav > > -- > 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. > >-- 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.
Rajinder Yadav wrote:> In my active record model I have declared a ''before_save'' callback, that > populates other fields before saving the data. However I am finding all > my unit test cases are breaking because it seems the ''before_save'' > callback is not getting called during a unit test run? In fact I have to > provide the missing filed in unit test fixture yml file. > > How can I make the model behave the same in the unit test run as it does > when I create and save a model object from the rails console?ok the answer just came to me, what I need to do is a post rather than a create on the model, make perfect sense! -- Kind Regards, Rajinder Yadav -- 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.