aconnelly
aconnelly

Reputation: 627

How do I get the Callbacks for an ActiveRecord object?

Is there a way to be able to see what callbacks an ActiveRecord object has? Say if I have:

class MyModel < ActiveRecord::Base
  after_save :my_after_save_function
end

How would you see the what the after_save callback points to?

e.g. MyModel.callbacks

I want to be able to test that my models have after_save callbacks that point to a particular function or callback class

Upvotes: 1

Views: 731

Answers (1)

aconnelly
aconnelly

Reputation: 627

Just found it.

You can use:

MyModel._save_callbacks.map(&:filter)

This article helped me.

Upvotes: 4

Related Questions