GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This time rebased off master as requested in #2194
fix after_initialize edge case (close #2074 and close #2175)
fix behavior when after_initialize is defined and a block is passed to Base.create
simplify and be more explicit about create and after_initialize tests
Actually the ActiveRecord maintainers would prefer that you use existing models for new tests instead of add new models
I poked around existing models to see if there was one I could use for this test, but I didn't see one that I could easily repurpose. I didn't want to mess with one that looked they were being used for specific test cases, which most of the ones I looked at seemed to be. I could have put it at the top of the test file, but none of the other classes up there had method declarations. It's my first submitted patch, so I just tried to not mess with things that were already in place too much.
use existing model for testing Base.create with #after_initialize
@guilleiguaran Updated tests to use existing model. Personally, I don't see it as a good testing practice to be using one model for multiple unrelated tests. Leads to unnecessary coupling and hard to find bugs
I agree with you but we must try to avoid defining extra models since we already have tonnes of them and if every patch add a new model it would quickly get out of hand.
Your code and tests looks great, thanks!!!
Merge pull request #2236 from cldwalker/after_initialize
Fix after_initialize and Base.create edge case
Should a similar change also be applied to create! in validations.rb? I'm not familiar enough with the rails code to know if there are other similar places where code should be changed.