aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authoritzki <itzki.h@gmail.com>2012-12-07 04:30:00 +0900
committeritzki <itzki.h@gmail.com>2012-12-10 14:44:24 +0900
commit7efcc5d72fb7e42358b4cb9b7f627e1a69c20911 (patch)
treee7fe33d158296dab746fa2899ae9e0f0e73b749c /activerecord
parent9e42cd86869dcc158b0321b2d2dfcc185a7d0282 (diff)
downloadrails-7efcc5d72fb7e42358b4cb9b7f627e1a69c20911.tar.gz
rails-7efcc5d72fb7e42358b4cb9b7f627e1a69c20911.tar.bz2
rails-7efcc5d72fb7e42358b4cb9b7f627e1a69c20911.zip
Fix decorating columns for serialized attributes
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/model_schema.rb7
-rw-r--r--activerecord/test/cases/serialized_attribute_test.rb13
3 files changed, 20 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index b1988172cb..02aced31c9 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -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:
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index 628ab0f566..85fb4be992 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -224,11 +224,10 @@ module ActiveRecord
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
diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb
index 068f3cf3cd..6962da298e 100644
--- a/activerecord/test/cases/serialized_attribute_test.rb
+++ b/activerecord/test/cases/serialized_attribute_test.rb
@@ -212,4 +212,17 @@ class SerializedAttributeTest < ActiveRecord::TestCase
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