Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

serialized attributes should be serialized before validation [#5525 s…

…tate:resolved]
  • Loading branch information...
commit b1c104296e71799e0cb69aaab321245a98c78dec 1 parent ef66a08
@tenderlove tenderlove authored
View
4 activerecord/lib/active_record/base.rb
@@ -1705,8 +1705,8 @@ def arel_attributes_values(include_primary_key = true, include_readonly_attribut
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
View
5 activerecord/lib/active_record/validations/uniqueness.rb
@@ -17,6 +17,11 @@ def validate_each(record, attribute, value)
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)
View
6 activerecord/test/cases/base_test.rb
@@ -909,9 +909,13 @@ def test_quoting_arrays
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

1 comment on commit b1c1042

@Mange

Hope this gets released soon

Please sign in to comment.
Something went wrong with that request. Please try again.