Skip to content

Inherit locale and template_scope in subclassed messengers - #43

Open
ahmeij wants to merge 1 commit into
mainfrom
bugfix/inherit-messenger-config
Open

Inherit locale and template_scope in subclassed messengers#43
ahmeij wants to merge 1 commit into
mainfrom
bugfix/inherit-messenger-config

Conversation

@ahmeij

@ahmeij ahmeij commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

BaseMessenger.locale and BaseMessenger.template_scope store 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 returned nil for these — losing its parent's configuration.

The concrete impact downstream: a subclassed messenger with no explicit template_scope caused select_templates to 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 BaseMessenger descendant 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 to superclass.
  • New test/messengers/messenger_inheritance_test.rb covering:
    • a subclass inherits locale from its parent messenger
    • a subclass inherits template_scope from its parent messenger
    • overriding template_scope on a subclass does not mutate the parent

Test plan

  • bin/rails test test/messengers test/life_cycle_test.rb test/state_machine_test.rb test/models/nuntius/template_test.rb (0 failures)
  • New inheritance test fails before the fix (subclass returns nil) and passes after

Made with Cursor

`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>
@ahmeij
ahmeij changed the base branch from develop to main July 3, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant