aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb12
-rw-r--r--activerecord/test/cases/attribute_methods_test.rb10
2 files changed, 22 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index f3200aa78a..399c22fb18 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -36,6 +36,18 @@ module ActiveRecord
# Generates all the attribute related methods for columns in the database
# accessors, mutators and query methods.
def define_attribute_methods
+ unless defined?(@attribute_methods_mutex)
+ ActiveSupport::Deprecation.warn(
+ "It looks like something (probably a gem/plugin) is removing or overriding the " \
+ "ActiveRecord::Base.inherited method. It is important that this hook executes so " \
+ "that your models are set up correctly. A workaround has been added to stop this " \
+ "causing an error in 3.2, but future versions will simply not work if the hook is " \
+ "overridden."
+ )
+
+ @attribute_methods_mutex = Mutex.new
+ end
+
# Use a mutex; we don't want two thread simaltaneously trying to define
# attribute methods.
@attribute_methods_mutex.synchronize do
diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb
index 0fbe1813fb..fb53eb1a4b 100644
--- a/activerecord/test/cases/attribute_methods_test.rb
+++ b/activerecord/test/cases/attribute_methods_test.rb
@@ -770,6 +770,16 @@ class AttributeMethodsTest < ActiveRecord::TestCase
assert_equal "lol", topic.author_name
end
+ def test_inherited_hook_removed
+ parent = Class.new(ActiveRecord::Base)
+ parent.table_name = "posts"
+ def parent.inherited(k)
+ end
+
+ klass = Class.new(parent)
+ assert_deprecated { klass.define_attribute_methods }
+ end
+
private
def cached_columns
@cached_columns ||= time_related_columns_on_topic.map(&:name)