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

DatabaseCleaner configuration for TestCase #19

Merged
merged 5 commits into from
Mar 12, 2022
Merged

DatabaseCleaner configuration for TestCase #19

merged 5 commits into from
Mar 12, 2022

Conversation

fractaledmind
Copy link
Owner

@fractaledmind fractaledmind commented Mar 12, 2022

The short version is that we store whatever the system DatabaseCleaner configuration is at the start of before_setup in an instance variable and then restore that configuration at the end of after_teardown. In between, we run the configuration thru a pipeline that selectively replaces any transaction strategies with a corresponding deletion strategy, leaving any other configured strategies untouched.

Ensure that the system's original DatabaseCleaner configuration is maintained, options included, except that any `transaction` strategies for any ORMs are replaced with a `deletion` strategy.
@fractaledmind fractaledmind self-assigned this Mar 12, 2022
@fractaledmind fractaledmind merged commit e10b2d3 into main Mar 12, 2022
@fractaledmind fractaledmind deleted the testing branch March 12, 2022 12:47
@julianrubisch
Copy link
Contributor

Yeah that looks quite involved...

@fractaledmind
Copy link
Owner Author

Yeah, DatabaseCleaner doesn't make such things easy, but their structures are consistent and easy to reason about, so while the code requires a fair number of lines, it is at least relatively easy to know what it needs to do and to do simply do it. So I'm not overly worried about the maintenance burden. Plus, I see that in that master of DatabaseCleaner currently, they do have a strategy getter, which should conceivably make this simpler in the future.

Anyway, suffice it to say, this is much less brittle and scary than the extensions I have for Sidekiq and Noticed. Compared to that code, I feel great about this.

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.

None yet

2 participants