-
-
Notifications
You must be signed in to change notification settings - Fork 518
[rails] fix / simplify and improve test rails app setup #2762
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
Conversation
sentry-rails/spec/dummy/test_rails_app/app/controllers/hello_controller.rb
Fixed
Show fixed
Hide fixed
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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