From fb95dee9264efa86d1024fbb42a79bd877d1a10d Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 16 Jul 2011 14:21:53 +0100 Subject: [PATCH] Deprecated the AssociationCollection constant --- activerecord/CHANGELOG | 8 ++++++++ .../associations/collection_proxy.rb | 7 +++++++ .../has_many_associations_test.rb | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index ea4e2edcae..4c58664a19 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,13 @@ *Rails 3.1.0 (unreleased)* +* Deprecated the AssociationCollection constant. CollectionProxy is now the appropriate constant + to use, though be warned that this is not really a public API. + + This should solve upgrade problems with the will_paginate plugin (and perhaps others). Thanks + Paul Battley for reporting. + + [Jon Leighton] + * ActiveRecord::MacroReflection::AssociationReflection#build_record has a new method signature. Before: def build_association(*options) diff --git a/activerecord/lib/active_record/associations/collection_proxy.rb b/activerecord/lib/active_record/associations/collection_proxy.rb index d67475053e..ebc6b3efb0 100644 --- a/activerecord/lib/active_record/associations/collection_proxy.rb +++ b/activerecord/lib/active_record/associations/collection_proxy.rb @@ -1,5 +1,12 @@ +require 'active_support/deprecation' + module ActiveRecord module Associations + AssociationCollection = ActiveSupport::Deprecation::DeprecatedConstantProxy.new( + 'ActiveRecord::Associations::AssociationCollection', + 'ActiveRecord::Associations::CollectionProxy' + ) + # Association proxies in Active Record are middlemen between the object that # holds the association, known as the @owner, and the actual associated # object, known as the @target. The kind of association any proxy is diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 8b7d2e4276..380ef57214 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1599,4 +1599,23 @@ class HasManyAssociationsTest < ActiveRecord::TestCase undef_method :old_build_association end end + + def test_AssociationCollection_deprecated + assert_deprecated do + ActiveRecord::Associations::AssociationCollection.class_eval do + def foo + "bar" + end + end + end + + author = Author.new + assert_equal "bar", author.posts.foo + ensure + ActiveSupport::Deprecation.silence do + ActiveRecord::Associations::AssociationCollection.class_eval do + undef_method :foo + end + end + end end