Replies: 2 comments
-
I would load the static data into a table, and specify an eager-loadable association. That way you let your 2 data sources be 2 data sources, rather than something in between. Just FYI, doing a |
Beta Was this translation helpful? Give feedback.
-
Turns out I was stubbing things wrong (or at least not as minitest expects me to do so). So, I can stub now and I don't need to change my code for testing. However, I see the problem of having 2 data sources. I'll probably refactor on a future version. I'm testing previous to refactoring actually. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I need to create a model with 2 data sources: SQL and a ruby array.
I've been able to do what I need using the
after_initialize
plugin, but testing its behavior has been challenging, so, I'm looking for suggestions on alternative implementations.Here is what I'm doing:
An example
../data/product.rb
would be:For testing, I could replace the
Product.static_data
method on my tests. But I'm not sure that's a good strategy (would change the source data for all tests).Other approach, instead of using after_initialize, could be defining a
load
method to be executed after the loading of data from database. I think that is sub-optimal since I will always load data from both sources.What would be your approach to the matter?
Beta Was this translation helpful? Give feedback.
All reactions