[rails] fix / simplify and improve test rails app setup#2762
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2762 +/- ##
==========================================
- Coverage 97.25% 90.41% -6.84%
==========================================
Files 130 131 +1
Lines 5240 5250 +10
==========================================
- Hits 5096 4747 -349
- Misses 144 503 +359
🚀 New features to boost your workflow:
|
a280fbd to
2246749
Compare
d7edc11 to
50cd1fe
Compare
c828b49 to
2bdf4ff
Compare
9f127f5 to
7907032
Compare
7907032 to
1470de3
Compare
265ae9b to
1470de3
Compare
| ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: db_path) | ||
|
|
||
| # Load schema from db/schema.rb into the current connection | ||
| require Test::Application.schema_file |
There was a problem hiding this comment.
Bug: Pathname to Require: Potential String Conversion Pitfall
The require statement at line 76 is passed a Pathname object from Test::Application.schema_file. While Pathname objects often implicitly convert to a string path, require expects a string, which could lead to unexpected behavior or errors in certain Ruby versions or environments.
sl0thentr0py
approved these changes
Nov 4, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes and simplifies test rails app setup for our
sentry-railstest suite. Previous solution suffered from too much duplication and global state pollution. I tried to stick to a regular Rails setup as much as possible here.In summary:
PostsController#attachwhich needed special handling ofservice_namefor Rails 6.1+db/schema.rbfile and load it just once inbefore(:suite)Sentry::TestRailsAppfrom a baseSentry:Rails:::Test::Applicationso that we can just leverage regular inheritance for version-specific tweaksmake_basic_appcalls - this causes issues as more global bloat is created (hence some specs were tweaked to not do this)make_basic_appto a dedicatedSentry::Rails::TestHelperthat gets included in all spec examplesThis makes the spec suite more stable and faster:
Notice that the suite gets slower and slower with each Rails version. This is because Rails accumulates more global state and there are still some leakages. We can keep improving it every time there's a chance. I'm gonna call it a day for now as it's already a huge improvement 😄
#skip-changelog