Skip to content
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 part-way compatibility with Fixtures #24

Merged
merged 2 commits into from
Aug 22, 2023
Merged

Conversation

kaspth
Copy link
Owner

@kaspth kaspth commented Aug 19, 2023

Uses FixtureSet.identify to have the same logic as the primary key generation that fixtures use, in that way we're a drop in replacement that could potentially be used alongside fixtures.

Since Fixtures issues a DELETE FROM for every table that's loaded with it, I'm opting to not support loading with Oaken and Fixtures on the same table.

E.g. using both test/seeds.rb (or test/seeds/users.rb) with users.update and test/fixtures/users.yml aren't supported. Otherwise we'd need to override setup_fixtures which will have started transactions on the database connection already, so any data we create is rolled back after the test, and we'd need probably complex connection management to handle that.

@kaspth
Copy link
Owner Author

kaspth commented Aug 19, 2023

I'm still not quite sure about this, and I'm wondering if we should just lean more on converters like in #22 to help upgrade people instead.

@@ -0,0 +1,3 @@
first:
name: "YAML"
account: business
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapping to FixtureSet.identify above means that we can safely refer to the account created with accounts.update :business in here and get it connected.

Uses `FixtureSet.identify` to have the same logic as the primary key generation that fixtures use, in that way
we're a drop in replacement that could potentially be used alongside fixtures.

Since Fixtures issues a DELETE FROM for every table that's loaded with it, I'm opting to not support loading with Oaken and Fixtures on the same table.

E.g. using both `test/seeds.rb` (or `test/seeds/users.rb`) with `users.update` and `test/fixtures/users.yml` aren't supported.
Otherwise we'd need to override `setup_fixtures` which will have started transactions on the database connection already, so any data we create is rolled back after the test,
and we'd need probably complex connection management to handle that.
@kaspth
Copy link
Owner Author

kaspth commented Aug 22, 2023

I can't figure out if this is what we want, but it's not gonna get clearer unless we try it out. So I'm going to go with this and then we'll see what changes we need, if any.

@kaspth kaspth merged commit 3e8d1c2 into main Aug 22, 2023
2 checks passed
@kaspth kaspth deleted the fixtures-compatiblity branch August 22, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant