-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ActiveRecord as a dependency #5
Comments
@alexandreruban nice, thanks for writing this up! Right now, I'm trying to see if I can build some structure around supporting both in-memory models and database based ones. So the Active Record connection bit is coming up soon. Let me try to work on the above, and then I'll get back to you. |
Nice!
Could we write a custom We could change the API to distinguish # test/seeds/users.rb
User = Struct.new(:name, keyword_init: true)
memory.register :users, User
# We call `create` in the seed files.
# As we are "creating" the data, I think it also makes a clearer API.
users.create :kasper, name: "Kasper" # test/oaken_test.rb
def test_updating_fixture
# Calling `update` stores the original object somewhere and enables us
# to interact with a copy.
users.update :kasper, name: "Kasper2"
assert_equal "Kasper2", users.kasper.name
# The `after_teardown` hook drops the copy and goes back to referencing the
# original object so we don't need this anymore.
# users.update :kasper, name: "Kasper"
end What do you think? It may be a silly idea! |
Potentially, yeah! I think this is a little further along for me right now, if you or someone else wants to trial it out in a PR, please do!
I'm curious to see what it enables or unlocks if we build with the idea that seeds can also be rerun incrementally and doesn't always have to be rerun from scratch. So I want to stick with just |
I just realized we probably will need the create API for times when you don't need the named reference, ala: 100.times do |n|
posts.create title: "Post number #{n}"
end But it might be nice to have a dedicated API that could match that and skip the generation if needed. Maybe something like this? posts.fill_in 100.times, title: "Title :n" # Use :n to fill in the count via String#% Anyway, that's probably for a little further down the line. |
There are two TODOs in the code related to adding
ActiveRecord
as a dependency:Should we add
ActiveRecord
now with a memory database to be able to test on real models? I'd be happy to work on this if you think it's the right moment.Also if someone wants to do some pair-programming with me on this feel free to tell me!
The text was updated successfully, but these errors were encountered: