Invoke load_schema
in _default_attributes
Currently `_default_attributes` doesn't work unless `load_schema` is called before. The `MissingAttributeError` is caused by `reload_schema_from_cache` is invoked by `serialize`. I added `load_schema` in `_default_attributes` to `_default_attributes` works without any dependency like `attribute_types` etc. Closes #31905.
This commit is contained in:
parent
83c1ed9a1a
commit
06d04bc237
@ -379,6 +379,7 @@ def column_defaults
|
||||
end
|
||||
|
||||
def _default_attributes # :nodoc:
|
||||
load_schema
|
||||
@default_attributes ||= ActiveModel::AttributeSet.new({})
|
||||
end
|
||||
|
||||
|
@ -251,6 +251,13 @@ def test_becomes
|
||||
assert_equal "The First Topic", topics(:first).becomes(Reply).title
|
||||
end
|
||||
|
||||
def test_becomes_after_reload_schema_from_cache
|
||||
Reply.define_attribute_methods
|
||||
Reply.serialize(:content) # invoke reload_schema_from_cache
|
||||
assert_kind_of Reply, topics(:first).becomes(Reply)
|
||||
assert_equal "The First Topic", topics(:first).becomes(Reply).title
|
||||
end
|
||||
|
||||
def test_becomes_includes_errors
|
||||
company = Company.new(name: nil)
|
||||
assert_not_predicate company, :valid?
|
||||
|
Loading…
Reference in New Issue
Block a user