Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #8441 from itzki/fix_decorate_columns

Fix decorate_columns for finding only non-serialized columns
  • Loading branch information...
commit f2d1e279afea3f53277b3ce6edf398f501708c0b 2 parents 9e42cd8 + 7efcc5d
Carlos Antonio da Silva carlosantoniodasilva authored
4 activerecord/CHANGELOG.md
View
@@ -1,5 +1,9 @@
## Rails 4.0.0 (unreleased) ##
+* Fix decorating columns for serialized attributes. Fixes #8441
+
+ *itzki*
+
* Session variables can be set for the `mysql`, `mysql2`, and `postgresql` adapters
in the `variables: <hash>` parameter in `database.yml`. The key-value pairs of this
hash will be sent in a `SET key = value` query on new database connections. See also:
7 activerecord/lib/active_record/model_schema.rb
View
@@ -224,11 +224,10 @@ def column_types # :nodoc:
def decorate_columns(columns_hash) # :nodoc:
return if columns_hash.empty?
- serialized_attributes.each_key do |key|
- columns_hash[key] = AttributeMethods::Serialization::Type.new(columns_hash[key])
- end
-
columns_hash.each do |name, col|
+ if serialized_attributes.key?(name)
+ columns_hash[name] = AttributeMethods::Serialization::Type.new(col)
+ end
if create_time_zone_conversion_attribute?(name, col)
columns_hash[name] = AttributeMethods::TimeZoneConversion::Type.new(col)
end
13 activerecord/test/cases/serialized_attribute_test.rb
View
@@ -212,4 +212,17 @@ def dump(thing)
assert_kind_of BCrypt::Password, topic.content
assert_equal(true, topic.content == password, 'password should equal')
end
+
+ def test_serialize_attribute_via_select_method_when_time_zone_available
+ ActiveRecord::Base.time_zone_aware_attributes = true
+ Topic.serialize(:content, MyObject)
+
+ myobj = MyObject.new('value1', 'value2')
+ topic = Topic.create(content: myobj)
+
+ assert_equal(myobj, Topic.select(:content).find(topic.id).content)
+ assert_raise(ActiveModel::MissingAttributeError) { Topic.select(:id).find(topic.id).content }
+ ensure
+ ActiveRecord::Base.time_zone_aware_attributes = false
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.