Our loading was a whole mess of things, but now I'm rewriting this to just use Ruby's PStore for storage.
I'm gonna leave this for now and sleep on it, but I think we're already at feature parity with much simpler code.
…and this turned into an almost rewrite.
Now we've got db/seeds.rb as the main entry point:
Oaken.seeds do
register Menu::Item # Lets you set up a register that you use throughout seed files. May add a `namespace "Menu"` or similar so you don't need to register every namespaced model.
load include_env: Rails.env # Load every non-environment file in db/seeds/**/* and loads the current env too.
end
And then in test_helper.rb you can do:
include Oaken.seeds # We'll run what `db:seed` runs here.
I still haven't figured out any lazy-loading in case you don't need a particular case. That'll be for another PR as this structure should start falling down quickly but then give us more dexterity to figure out what to fix.
Edit: ok, the above even got changed to this:
# db/seeds.rb
Oaken.seeds do
register Menu::Item
load :accounts, :data # Checks both db/seeds/ and db/seeds/<Rails.env>
end
And now you can seed in an individual case too:
require "test_helper"
class PaginationTest < ActiveSupport::TestCase
# Seeds db/seeds/cases/pagination.rb and db/seeds/<Rails.env>/cases/pagination.rb
# But I recommend only having a `db/seeds/test/cases` directory.
seed "cases/pagination"
end
Our loading was a whole mess of things, but now I'm rewriting this to just use Ruby's
PStore
for storage.I'm gonna leave this for now and sleep on it, but I think we're already at feature parity with much simpler code.
…and this turned into an almost rewrite.
Now we've got
db/seeds.rb
as the main entry point:And then in
test_helper.rb
you can do:I still haven't figured out any lazy-loading in case you don't need a particular case. That'll be for another PR as this structure should start falling down quickly but then give us more dexterity to figure out what to fix.
Edit: ok, the above even got changed to this:
And now you can seed in an individual case too: