Inherit locale and template_scope in subclassed messengers - #43
Open
ahmeij wants to merge 1 commit into
Open
Conversation
`locale` and `template_scope` were stored in class-instance variables and returned only the value set directly on the receiving class. A messenger that subclasses another (e.g. an STI-derived messenger) therefore silently lost its parent's template scope, causing template selection to run unscoped. Fall back to the superclass value when the subclass has not set its own, so subclasses inherit the configured locale/scope. Add tests covering inheritance and confirming an override on a subclass does not mutate the parent. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
BaseMessenger.localeandBaseMessenger.template_scopestore their value in a class-instance variable and returned only what was set directly on the receiving class. Because class-instance variables are not inherited, a messenger that subclasses another (for example an STI-derived messenger) silently returnednilfor these — losing its parent's configuration.The concrete impact downstream: a subclassed messenger with no explicit
template_scopecausedselect_templatesto skip the scope entirely (the default template scope is unrestricted), so template selection ran across all records instead of the intended (e.g. per-label) subset.This changes both getters to fall back to the superclass value when the subclass has not set its own, walking up the ancestry until a
BaseMessengerdescendant is found. Setting a value on a subclass still only affects that subclass (no parent mutation).Changes
locale/template_scope: return own value if set, otherwise delegate tosuperclass.test/messengers/messenger_inheritance_test.rbcovering:localefrom its parent messengertemplate_scopefrom its parent messengertemplate_scopeon a subclass does not mutate the parentTest plan
bin/rails test test/messengers test/life_cycle_test.rb test/state_machine_test.rb test/models/nuntius/template_test.rb(0 failures)nil) and passes afterMade with Cursor