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 PR adds a few integration tests on the number of ActiveRecord DB queries generated by specific route actions. The implementation in the
CaptureQueries
module uses theActiveSupport::Notifications
subscription API to capture all ActiveRecord queries generated within a block, and assert an expected count.This will allow us to more easily track (and automatically prevent regressions on) the number of database queries performed by high-traffic routes.
I've added a few basic tests to get started:
milestone
POST
(passing, signed-in user) expects 11 queriesmilestone
POST
(failing, signed-in user) expects 11 queriesuser_progress
GET
(signed-in user, with existinguser_level
) expects 7 queriesscript_levels
#show
(signed-in user with existinguser_level
) expects 22 (!) queriesThese query counts are not ideal, and the numbers will be reduced in an optimization PR that will come after these integration tests.
I've refactored the existing
CachingTest
tests to use this implementation instead of callingno_database
(which stubsActiveRecord::Base#connection
), since I think it's a cleaner approach.This PR also renames an API route-path fragment from
:script_name
to:script
- it turns out that:script_name
is a reserved word in Rails path helper, and its use was preventing the new integration tests from working properly.