Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Problem with skipping callbacks after upgrade to Rails #931
We have a model
class Company < ApplicationRecord after_create :do_something # other methods def do_something # work end end
In our factories, we are skipping callbacks like so:
after(:build) do |company| company.class.skip_callback(:create, :after, :set_default_company_preference) end
This worked fine and all our tests pass on Rails 4.2, but after upgrading to Rails 5, we are getting
This is happening with all our models in which we have callbacks defined. Did Rails/Factory Girl change something in an unexpected way?
Looking at the changelog of Rails 5:
Here is the pull request with the message you are seeing.
So I think that the callback
@pawandubey FactoryGirl's callbacks are entirely decoupled from ActiveRecords', apart from the fact that FG calls
I came across this issue as well after upgrading to Rails 5. What I was able to figure out is that after creating one instance of a factory, the callback method is no longer defined on the model for any subsequent instances that are created. Rails 4 ignored this but Rails 5 raises the argument error. You can confirm in the console by calling
I was able to get test passing again by changing the factory callback to:
Not sure if this is the best approach if anyone has any suggestions. I suppose you could also call