mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
serialized attributes should be serialized before validation [#5525 state:resolved]
This commit is contained in:
@@ -1685,8 +1685,8 @@ MSG
|
||||
if include_readonly_attributes || (!include_readonly_attributes && !self.class.readonly_attributes.include?(name))
|
||||
value = read_attribute(name)
|
||||
|
||||
if value && ((self.class.serialized_attributes.has_key?(name) && (value.acts_like?(:date) || value.acts_like?(:time))) || value.is_a?(Hash) || value.is_a?(Array))
|
||||
value = value.to_yaml
|
||||
if value && self.class.serialized_attributes.key?(name)
|
||||
value = YAML.dump value
|
||||
end
|
||||
attrs[self.class.arel_table[name]] = value
|
||||
end
|
||||
|
||||
@@ -17,6 +17,11 @@ module ActiveRecord
|
||||
table = finder_class.unscoped
|
||||
|
||||
table_name = record.class.quoted_table_name
|
||||
|
||||
if value && record.class.serialized_attributes.key?(attribute.to_s)
|
||||
value = YAML.dump value
|
||||
end
|
||||
|
||||
sql, params = mount_sql_and_params(finder_class, table_name, attribute, value)
|
||||
|
||||
relation = table.where(sql, *params)
|
||||
|
||||
@@ -909,9 +909,13 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
MyObject = Struct.new :attribute1, :attribute2
|
||||
|
||||
def test_serialized_attribute
|
||||
Topic.serialize("content", MyObject)
|
||||
|
||||
myobj = MyObject.new('value1', 'value2')
|
||||
topic = Topic.create("content" => myobj)
|
||||
Topic.serialize("content", MyObject)
|
||||
assert_equal(myobj, topic.content)
|
||||
|
||||
topic.reload
|
||||
assert_equal(myobj, topic.content)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user