Hacker News new | ask | show | jobs
by danso 4518 days ago
This was a very useful writeup and am looking forward to your followup with DelayedJob...but what would you say to people who think you could've made the re-calculation methods part of the model? I guess you could argue that you still would want to test any batch task as part of the integration though.
1 comments

Thank you for your comment and question, danso.

The particular re-calculation method I presented in this blog post is (hopefully) only going to be run one time, as it serves to recalculate fields based on a database migration. Those fields are counter caches in my Rails models, meaning that their values get +1 automatically when an Answer is generated for a particular Question (approved or not).

Given the nature of the task at hand, I felt it was better practice to keep the model 'clean' and abstract the computation to the rake task itself. The computation will soon be extracted out to a DelayedJob, further isolating the re-calculation method in a modular fashion.

Hope that answers your question!