Closed mateusdeap closed 1 year ago
@mateusdeap Thanks for submitting this issue!
I think the first step would be to submit a PR that adds a simple test case for DeprecationTracker::KernelWarnTracker.callbacks
Considering our CI is configured to run with ruby 2.7, we should see a failure in CI.
Then you can probably write an adapter that uses the right signature depending on the ruby version that's being used.
So, @etagwerker I've implemented the spec and the fix in #82. However, I decided to just check the ruby version and change the argument forwarding to super
based on that. CI seems to be fine with it. However, I am a fan of learning how to implement new patterns, so if you think using the adapter patters would still be better, just let me know.
Also, I've added the spec under the DeprecationTracker::KernelWarnTracker
describe block in a general manner, since I feel this is testing the warn method rather than the callbacks themselves....
Want me to tag you for review?
Also, I think our CI should probably have a job for Ruby 2.5.0, since that's the version that introduced the change. Should I add it in the current PR or in another one?
@mateusdeap Please submit a different PR for this:
Also, I think our CI should probably have a job for Ruby 2.5.0
Thanks!
@mateusdeap I went ahead and submitted #85 to verify that it all works well with other versions of Ruby.
Expected Behavior
When I configure the deprecation tracker in a
rails_helper
file using Ruby 2.7, and when thetransform_message
option attempts to call methods on themessage
variable not present inHash
, it shouldn't produce any errors.Actual Behavior
When I configure the deprecation tracker in a
rails_helper
file using Ruby 2.7, and when thetransform_message
option attempts to call methods on themessage
variable not present inHash
, it produced aNoMethodError
Possible Fix
The issue is because the
warn
method, as of ruby 2.5, has theuplevel
keyword arg. Since our signature only specifies*messages
, that ends up becoming a hash with both the messages and the uplevel arg.Hence, if your
transform_message
option attempts to manipulate whatnext_rails
provides as a message, it will eventually be given aHash
with theuplevel
key.The most immediate fix is to change the signature of
KernelWarnTracker#warn
to match the current signature. We'll need to check ruby versions, since this was introduced in ruby 2.5. We'll also probably have to study how to properly deal with the uplevel arg.To Reproduce
I was able to come up with a spec to reproduce the error. There might be some organizational changes needed concerning the use of contexts, but it catches the bug.
I will abide by the code of conduct