-
Notifications
You must be signed in to change notification settings - Fork 11
Add ActiveRecord model integration tests #208
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
Merged
Merged
Conversation
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
a64ece0 to
76da18d
Compare
mateuscruz
added a commit
that referenced
this pull request
Jan 3, 2026
Every time there's a new Rails release, active record internals are refactored which, inadvertently, breaks the intended behaviour for this gem. I've had to fix it _multiple times_ (#201, #84, #79, #41 – that one was a _patch_ which is supposed to be non-breaking) and, at this point, I'm just done. I don't want to fix the same issue, over and over again, every time they release a new version. On top of that, it looks like they intend to [deprecate](rails/rails@3fc2ca0) many of these internal methods we hijack to favour the higher-level ones, and I think that makes total sense. The higher level methods have been mostly stable since Rails 5.1. When new changes are added, they are usually backwards compatible. With that in mind, I'm changing how we hijack the adapter methods. | Lower-level method | higher-level counterpart | |---------------------|-------------------------| | `exec_insert`| `insert` | | `internal_exec_query` | `select`| | `exec_query` | N/A | | `execute` | N/A | | `exec_update` | `update` | | `exec_delete` | `delete` | `exec_query` and `execute` do not have higher-level counterparts, as they're meant to be used directly, so they will still be hijacked. I'm also adding `exec_insert_all` to the list, it's an exception to the rule. It doesn't have a higher-level counterpart, but also, it's not meant to be used directly. Instead it is called by `InsertAll.execute` when `Model.insert!` is called. All the higher-level counterparts are stable API and are compatible with both raw SQL strings and Arel trees. That also gives us the chance to leverage a custom Arel parser to simplifly the AST when pattern matching read replica queries. I'm also removing all the multiple tests for each hijackable method, since they test the exact same thing. Instead, I'll be adding new integration tests for the active record model API in #208 (i.e. `Model.all | create | first`, `model.save | update | destroy`, etc). Those will help us detect breaking changes more easily. The current test suite is not able to find those automatically and yields false positives.
8cefbf9 to
fafcda5
Compare
fafcda5 to
c0be2a6
Compare
malaguitte
reviewed
Jan 5, 2026
malaguitte
reviewed
Jan 5, 2026
malaguitte
reviewed
Jan 5, 2026
malaguitte
approved these changes
Jan 5, 2026
Collaborator
malaguitte
left a comment
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.
LGTM! 🚀
Co-authored-by: Anderson <upmalagutti@gmail.com>
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.
#213 follow-up.
This change adds integration tests for common ActiveRecord model methods (e.g.
create,save,update,destroy,reload, etc).The current test coverage ensures that the methods we're hijacking at the adapter layer itself work, but the on the higher model layer, the chaining of those methods has changed at each major Rails release, which introduces regression on this gem every single time.
The goal os these tests is to try and catch those errors in advance and fix them before we loosen the gem constraints to allow newer rails versions. It should also catch regression overall whenever a change is made.