From 6ea1481d6991aa6eb67b9fb135b778908922d675 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Fri, 13 Jun 2014 10:52:39 -0600 Subject: Ensure we always define attribute methods --- activerecord/lib/active_record/core.rb | 1 + activerecord/test/cases/serialization_test.rb | 8 ++++++++ 2 files changed, 9 insertions(+) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 86b4cc90ea..3e965187e6 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -259,6 +259,7 @@ module ActiveRecord init_internals initialize_internals_callback + self.class.define_attribute_methods # +options+ argument is only needed to make protected_attributes gem easier to hook. # Remove it when we drop support to this gem. init_attributes(attributes, options) if attributes diff --git a/activerecord/test/cases/serialization_test.rb b/activerecord/test/cases/serialization_test.rb index 7dd1f10ce9..3f52e80e11 100644 --- a/activerecord/test/cases/serialization_test.rb +++ b/activerecord/test/cases/serialization_test.rb @@ -69,6 +69,14 @@ class SerializationTest < ActiveRecord::TestCase ActiveRecord::Base.include_root_in_json = original_root_in_json end + def test_read_attribute_for_serialization_with_format_without_method_missing + klazz = Class.new(ActiveRecord::Base) + klazz.table_name = 'books' + + book = klazz.new + assert_nil book.read_attribute_for_serialization(:format) + end + def test_read_attribute_for_serialization_with_format_after_init klazz = Class.new(ActiveRecord::Base) klazz.table_name = 'books' -- cgit v1.2.3