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

Remove Database Cleaner and share FactoryBot factories #1028

Merged
merged 1 commit into from
Dec 17, 2022

Conversation

texpert
Copy link
Collaborator

@texpert texpert commented Dec 16, 2022

Threads sharing a DB connection has been fixed in Rails 5.1 by Rails team and Capybara author, so Database Cleaner can be removed.

Changes:

  • database_cleaner gem removed and all its calls from the rails_helper hooks
  • config.use_transactional_fixtures set to true
  • factory_bot gem replaced by the factory_bot_rails
  • Fetching factories into FactoryBot.definition_file_paths is defined in the CamaleonCMS::Engine, thus sharing the factories from the camaleon_cms gem with the main application
  • config.serve_static_files replaced by config.public_file_server.enabled (a change from Rails 5.1 also)
  • Capybara::Webkit is no longer used, so removed the related code from the spec_helper
  • The favicon added into the dummy's public, because the captcha specs started failing on GET /favicon requests.
  • The init_site method from spec/support/common.rb has been slightly refactored to call CamaleonCms::Site.delete_all before every test run, and to nullify the @site, @post ivars, as well as the CamaleonCMS::Site class ivar @main_site. The latter being a class ivar has been persisting through all the specs, causing failures
  • Due to database_cleaner removal, the DB now is not cleaned entirely after every test, so the Site associations like posts, post_types, categories, etc., have been refactored to be dynamically fetched as @site associations.
    • This could be better refactored in the future. Particularily the site factory slug should be made rendom to not cause validation issues, after which the CamaleonCms::Site.delete_all before each test will be possible to remove, and the @site and @post ivars refactored to RSpec let memoizers.

@brian-kephart
Copy link
Collaborator

@texpert This looks awesome! Thanks, I didn't realize the transaction issue was fixed. One more dependency down, and a bunch of config removed! Plus, the tests for edge Rails are working again.

I'm curious, why does the diff show a change to the dummy app's favicon?

@texpert
Copy link
Collaborator Author

texpert commented Dec 16, 2022

@texpert This looks awesome! Thanks, I didn't realize the transaction issue was fixed. One more dependency down, and a bunch of config removed! Plus, the tests for edge Rails are working again.

I'm curious, why does the diff show a change to the dummy app's favicon?

Oh, I had to add the favicon into the dummy's public, because the captcha specs started failing on GET /favicon requests.

Yeah, I am also, like you, always glad to remove some dependencies :)

@texpert texpert force-pushed the remove-database-cleaner branch from c040062 to 3625236 Compare December 17, 2022 06:49
Change `factory_bot` to `factory_bot_rails` in all the `gemfiles`

Share the factories from the gem into the main application, adding `FactoryBot.definition_file_paths` to the engine

[skip ci]
@texpert texpert force-pushed the remove-database-cleaner branch from 7c6b454 to a274c52 Compare December 17, 2022 07:16
@texpert texpert merged commit d20e0a9 into owen2345:master Dec 17, 2022
@texpert texpert changed the title Remove Database Cleaner Remove Database Cleaner and share FactoryBot factories Dec 17, 2022
@texpert texpert deleted the remove-database-cleaner branch December 29, 2022 19: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.

2 participants