From 250853364a0c872891b518ee47a76ac4ae2bd864 Mon Sep 17 00:00:00 2001 From: Leigh Caplan Date: Wed, 21 Jul 2010 17:48:20 -0700 Subject: [PATCH 1/2] Override new on proxy objects so that they never wrap nil or false. --- activesupport/lib/active_support/deprecation.rb | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/activesupport/lib/active_support/deprecation.rb b/activesupport/lib/active_support/deprecation.rb index e334f89..2c86a6f 100644 --- a/activesupport/lib/active_support/deprecation.rb +++ b/activesupport/lib/active_support/deprecation.rb @@ -120,6 +120,13 @@ module ActiveSupport end class DeprecationProxy #:nodoc: + def self.new(*args, &block) + object = args.first + + return object unless object + super + end + silence_warnings do instance_methods.each { |m| undef_method m unless m =~ /^__/ } end -- 1.6.5.3 From d1a3fa4c0f2562dbabb85fcbd5f275517fedb4a5 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