aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-12-24 11:02:02 +0000
committerJon Leighton <j@jonathanleighton.com>2011-12-24 11:08:16 +0000
commit800f0a6eb60c11575e55366c104d1e2d3e963d16 (patch)
treee472771c09910305a948b03fe33cdfa3a4d8579f /activerecord
parent0e3e34f0eba32ebc561f56e8eda22ed9b8ad76c7 (diff)
downloadrails-800f0a6eb60c11575e55366c104d1e2d3e963d16.tar.gz
rails-800f0a6eb60c11575e55366c104d1e2d3e963d16.tar.bz2
rails-800f0a6eb60c11575e55366c104d1e2d3e963d16.zip
Add deprecation for the change to the active_record load hook
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/model.rb25
-rw-r--r--activerecord/test/cases/inclusion_test.rb14
2 files changed, 38 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/model.rb b/activerecord/lib/active_record/model.rb
index 4e8ed14fb7..025f40359a 100644
--- a/activerecord/lib/active_record/model.rb
+++ b/activerecord/lib/active_record/model.rb
@@ -1,3 +1,5 @@
+require 'active_support/deprecation'
+
module ActiveRecord
module Model
# So we can recognise an AR class even while self.included is being
@@ -50,8 +52,29 @@ module ActiveRecord
self.connection_handler = Base.connection_handler
end
end
+
+ module DeprecationProxy #:nodoc:
+ class << self
+ instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$|^instance_eval$/ }
+
+ def method_missing(name, *args, &block)
+ if Model.respond_to?(name)
+ Model.send(name, *args, &block)
+ else
+ ActiveSupport::Deprecation.warn(
+ "The object passed to the active_record load hook was previously ActiveRecord::Base " \
+ "(a Class). Now it is ActiveRecord::Model (a Module). You have called `#{name}' which " \
+ "is only defined on ActiveRecord::Base. Please change your code so that it works with " \
+ "a module rather than a class. (Model is included in Base, so anything added to Model " \
+ "will be available on Base as well.)"
+ )
+ Base.send(name, *args, &block)
+ end
+ end
+ end
+ end
end
end
require 'active_record/connection_adapters/abstract/connection_specification'
-ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Model)
+ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Model::DeprecationProxy)
diff --git a/activerecord/test/cases/inclusion_test.rb b/activerecord/test/cases/inclusion_test.rb
index 4b3320cf04..374e4e01d3 100644
--- a/activerecord/test/cases/inclusion_test.rb
+++ b/activerecord/test/cases/inclusion_test.rb
@@ -74,6 +74,20 @@ class InclusionUnitTest < ActiveRecord::TestCase
def test_included_twice
@klass.send :include, ActiveRecord::Model
end
+
+ def test_deprecation_proxy
+ assert_equal ActiveRecord::Model.name, ActiveRecord::Model::DeprecationProxy.name
+ assert_equal ActiveRecord::Base.superclass, assert_deprecated { ActiveRecord::Model::DeprecationProxy.superclass }
+
+ sup = nil
+ ActiveSupport.on_load(:__test_active_record_model_deprecation) do
+ sup = superclass
+ end
+ assert_deprecated do
+ ActiveSupport.run_load_hooks(:__test_active_record_model_deprecation, ActiveRecord::Model::DeprecationProxy)
+ end
+ assert_equal ActiveRecord::Base.superclass, sup
+ end
end
class InclusionFixturesTest < ActiveRecord::TestCase