kaspth / oaken

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

Add global defaults support #82

Closed kaspth closed 5 months ago

kaspth commented 5 months ago

You can now set up default attributes that's applied to created/inserted records, like this:

Oaken.prepare do
  # Assign broad global defaults for every type.
  defaults name: -> { Faker::Name.name }, public_key: -> { SecureRandom.hex }

  # Assign a more specific default on one type, which overrides the global default above.
  accounts.defaults name: -> { Faker::Business.name }
end

In a bit, I'd like to add built-in global defaults using Faker for the ~200 unique column names that a typical Rails app has.

kaspth commented 5 months ago

Still wish we'd gotten the method(:name) shorthand in Ruby, could've been really interesting for this:

defaults Faker::Name.:name, public_key: SecureRandom.:hex
kaspth commented 5 months ago

I think this is ok for now and I'll move forward with it.