kaspth / oaken

A fresh blended alternative to Fixtures & FactoryBot for dev and test data.
MIT License
190 stars 6 forks source link

Rewrite loading …and also the gem it seems #54

Closed kaspth closed 1 year ago

kaspth commented 1 year ago

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
kaspth commented 1 year ago

Ok, I kinda went goblin mode for a bit here to push things forward quite a bit. I think we're in a much better place now though.

tcannonfodder commented 1 year ago

👹👹👹👹👹👹