I have a Company model that has an after_create callback that creates default roles, users, etc for the new company. In the development environment, this all works great. In my company unit test however, an ActiveRecord::RecordNotSaved is thrown on the first attempt to create a role for the new company (and this is also the first attempt to create anything in the after_create callback). I have added logger statements in the code to verify that both the company and new role are valid, and they are. Is there something I am missing? If not, is there a better way to track down why I am getting a RecordNotSaved? TIA, -Bill -- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 19, 2008 9:41 AM, William Pratt <billp-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> > I have a Company model that has an after_create callback that creates > default roles, users, etc for the new company. In the development > environment, this all works great. In my company unit test however, an > ActiveRecord::RecordNotSaved is thrown on the first attempt to create a > role for the new company (and this is also the first attempt to create > anything in the after_create callback). I have added logger statements > in the code to verify that both the company and new role are valid, and > they are. Is there something I am missing? If not, is there a better way > to track down why I am getting a RecordNotSaved? > > TIA, > -Bill > > -- > Sincerely, > > William Pratt > > > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What I meant to say was: Do @company.save and then puts @company.errors to see what errors there are. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
There are no errors. Both the company and the role are valid and the company is already saved at this point. I logged a company.inspect and it shows new_record to be false. Both the company and the role return true from a call to valid?. -Bill Ryan Bigg wrote:> What I meant to say was: > > Do @company.save and then puts @company.errors to see what errors > there are. > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nm, I found it. I have an abstract base class that was catching a condition and not injecting the error before returning false. Thanks anyway Ryan. -Bill William Pratt wrote:> I have a Company model that has an after_create callback that creates > default roles, users, etc for the new company. In the development > environment, this all works great. In my company unit test however, an > ActiveRecord::RecordNotSaved is thrown on the first attempt to create a > role for the new company (and this is also the first attempt to create > anything in the after_create callback). I have added logger statements > in the code to verify that both the company and new role are valid, and > they are. Is there something I am missing? If not, is there a better way > to track down why I am getting a RecordNotSaved? > > TIA, > -Bill > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---