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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to