Skip to content

fix: ensure typed store attributes are cast even without default option#58

Open
glebson1988 wants to merge 1 commit intopalkan:masterfrom
glebson1988:fix/typed-keys-cast-without-default
Open

fix: ensure typed store attributes are cast even without default option#58
glebson1988 wants to merge 1 commit intopalkan:masterfrom
glebson1988:fix/typed-keys-cast-without-default

Conversation

@glebson1988
Copy link
Copy Markdown

Fixes #49

What is the purpose of this pull request?

Fix incorrect type casting for store_attribute typed keys when default: is not provided.
Previously, values could remain uncasted (e.g. String instead of BigDecimal) after create/load in some class ownership/decorated scenarios.

What changes did you make? (overview)

  • Updated store_attribute setup logic in lib/store_attribute/active_record/store.rb:
    • Removed the options.key?(:default) gate from the owner-change re-decoration path.
    • Now re-decoration happens whenever store owner changes, not only for attributes with defaults.
    • Updated owner assignment condition accordingly.
  • Added regression specs in spec/cases/store_attribute_spec.rb:
    • typecasts inherited typed store attributes without defaults on reload
    • typecasts typed store attributes without defaults on reload

Is there anything you'd like reviewers to focus on?

Please focus on:

  • correctness of the owner/re-decoration condition in store_attribute
  • potential side effects for defaults behavior and STI/inheritance flows
  • whether test coverage is sufficient for the reported regression path

Checklist

  • I've added tests for this change
  • I've added a Changelog entry
  • I've updated a documentation (Readme)

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.

Typed keys in store_attribute not casted correctly unless default: is specified

1 participant