Merge pull request #8441 from itzki/fix_decorate_columns

Fix decorate_columns for finding only non-serialized columns
This commit is contained in:
Carlos Antonio da Silva 2012-12-10 03:17:28 -08:00
commit f2d1e279af
3 changed files with 20 additions and 4 deletions

@ -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:

@ -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

@ -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