I am trying to test that a callback is run in an AR model (Rails 3) and am getting an error. As far as I can see I am following the api.doc example closely so am a bit confused as to the error. class SystemError < ActiveRecord::Base after_save :notify_administrator_of def notify_administrator_of sysadmin_user = User.find_by_role_id(Role.find_by_name(''sysadmin'').id) SystemMailer.generic_email(sysadmin_user.email, "Wavelineup Error: #{Rails.env} - #{self.error}", "#{self.incidentals}").deliver end end I am following the following instructions which look like are just an excerpt from the api.dock: http://gem-session.com/2010/03/how-to-test-callback-methods-in-rails I get the following failure: 1) SystemError after_save should send an email to the admin after save Failure/Error: system_error.run_callbacks(:after_save) *undefined method `_run_after_save_callbacks'' for #<SystemError:0x21a1a60>* # ./spec/models/system_error_spec.rb:8:in `block (2 levels) in <top (required)>'' My spec is: describe "SystemError after_save" do it "should send an email to the admin after save" do system_error = SystemError.new system_error.should_receive(:notify_administrator_of) system_error.run_callbacks(:after_save) end end -- 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.
I''m running into the same issue - did you resolve this or open up a ticket for it? On Dec 22 2010, 10:23 am, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> wrote:> I am trying to test that a callback is run in an AR model (Rails 3) and am > getting an error. As far as I can see I am following the api.doc example > closely so am a bit confused as to the error. > > class SystemError < ActiveRecord::Base > after_save :notify_administrator_of > def notify_administrator_of > sysadmin_user = User.find_by_role_id(Role.find_by_name(''sysadmin'').id) > SystemMailer.generic_email(sysadmin_user.email, "Wavelineup Error: > #{Rails.env} - #{self.error}", "#{self.incidentals}").deliver > end > end > > I am following the following instructions which look like are just an > excerpt from the api.dock:http://gem-session.com/2010/03/how-to-test-callback-methods-in-rails > > I get the following failure: > > 1) SystemError after_save should send an email to the admin after save > Failure/Error: system_error.run_callbacks(:after_save) > *undefined method `_run_after_save_callbacks'' for > #<SystemError:0x21a1a60>* > # ./spec/models/system_error_spec.rb:8:in `block (2 levels) in <top > (required)>'' > > My spec is: > > describe "SystemError after_save" do > > it "should send an email to the admin after save" do > system_error = SystemError.new > system_error.should_receive(:notify_administrator_of) > system_error.run_callbacks(:after_save) > end > > end-- 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.
I dug into this a bit more and found the following thread useful: https://rails.lighthouseapp.com/projects/8994/tickets/5472-unable-to-manually-run-activerecord-object-callbacks On Jan 19, 6:38 pm, nootch <noah....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m running into the same issue - did you resolve this or open up a > ticket for it? > > On Dec 22 2010, 10:23 am, David Kahn <d...-rfEMNHKVqOwNic7Bib+Ti1W1rNmOCjRP@public.gmane.org> > wrote: > > > > > I am trying to test that a callback is run in an AR model (Rails 3) and am > > getting an error. As far as I can see I am following the api.doc example > > closely so am a bit confused as to the error. > > > class SystemError < ActiveRecord::Base > > after_save :notify_administrator_of > > def notify_administrator_of > > sysadmin_user = User.find_by_role_id(Role.find_by_name(''sysadmin'').id) > > SystemMailer.generic_email(sysadmin_user.email, "Wavelineup Error: > > #{Rails.env} - #{self.error}", "#{self.incidentals}").deliver > > end > > end > > > I am following the following instructions which look like are just an > > excerpt from the api.dock:http://gem-session.com/2010/03/how-to-test-callback-methods-in-rails > > > I get the following failure: > > > 1) SystemError after_save should send an email to the admin after save > > Failure/Error: system_error.run_callbacks(:after_save) > > *undefined method `_run_after_save_callbacks'' for > > #<SystemError:0x21a1a60>* > > # ./spec/models/system_error_spec.rb:8:in `block (2 levels) in <top > > (required)>'' > > > My spec is: > > > describe "SystemError after_save" do > > > it "should send an email to the admin after save" do > > system_error = SystemError.new > > system_error.should_receive(:notify_administrator_of) > > system_error.run_callbacks(:after_save) > > end > > > end-- 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.