From 34c5d0a3eeb75aff68e075a6061ab2d2df61fb7d Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 21 Jul 2010 16:46:38 -0700 Subject: [PATCH 1/2] Override new on proxy objects so that they never wrap nil or false. --- .../active_support/deprecation/proxy_wrappers.rb | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb index dec5671..b22d0a6 100644 --- a/activesupport/lib/active_support/deprecation/proxy_wrappers.rb +++ b/activesupport/lib/active_support/deprecation/proxy_wrappers.rb @@ -3,6 +3,13 @@ require 'active_support/inflector' module ActiveSupport module Deprecation class DeprecationProxy #:nodoc: + def self.new(*args, &block) + object = args.first + + return object unless object + super + end + instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ } # Don't give a deprecation warning on inspect since test/unit and error -- 1.6.5.3 From e8aafd04615b1dfe76d5fa4de1affbcfadabd601 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 21 Jul 2010 16:51:15 -0700 Subject: [PATCH 2/2] Test to ensure that falsy objects aren't wrapped by deprecation proxies --- .../test/deprecation/proxy_wrappers_test.rb | 22 ++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-) create mode 100644 activesupport/test/deprecation/proxy_wrappers_test.rb diff --git a/activesupport/test/deprecation/proxy_wrappers_test.rb b/activesupport/test/deprecation/proxy_wrappers_test.rb new file mode 100644 index 0000000..c507eff --- /dev/null +++ b/activesupport/test/deprecation/proxy_wrappers_test.rb @@ -0,0 +1,22 @@ +require 'abstract_unit' +require 'active_support/deprecation' + +class ProxyWrappersTest < Test::Unit::TestCase + Waffles = false + NewWaffles = :hamburgers + + def test_deprecated_object_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(nil, "message") + assert !proxy + end + + def test_deprecated_instance_variable_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(nil, :waffles) + assert !proxy + end + + def test_deprecated_constant_proxy_doesnt_wrap_falsy_objects + proxy = ActiveSupport::Deprecation::DeprecatedConstantProxy.new(Waffles, NewWaffles) + assert !proxy + end +end \ No newline at end of file -- 1.6.5.3