I have a callback defined in my model as
after_commit :method, on: [:create, :update]
In my test I want to disable this callback using set_callback method. How can I do it?
set_callback is used to add a callback to a model:
http://apidock.com/rails/ActiveSupport/Callbacks/ClassMethods/set_callback
I think skip_callback is to be used here:
http://apidock.com/rails/ActiveSupport/Callbacks/ClassMethods/skip_callback
You would call it like this:
SomeModel.skip_callback(:commit, :after, :method)
It's often used in test factories, for instance to skip a before_save method called some_method:
factory :user do
after(:build) do |user|
user.class.skip_callback(:save, :before, :some_method)
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With