From fb08e334d61b1706db754733b209075b0154b57e Mon Sep 17 00:00:00 2001 From: Andrew Kaspick Date: Thu, 23 Sep 2010 16:48:35 -0500 Subject: memoized protected methods should remain protected Signed-off-by: Santiago Pastorino --- activesupport/lib/active_support/memoizable.rb | 2 ++ activesupport/test/memoizable_test.rb | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb index 9fb506fea1..0a7bcd5bb8 100644 --- a/activesupport/lib/active_support/memoizable.rb +++ b/activesupport/lib/active_support/memoizable.rb @@ -95,6 +95,8 @@ module ActiveSupport # if private_method_defined?(#{original_method.inspect}) # if private_method_defined?(:_unmemoized_mime_type) private #{symbol.inspect} # private :mime_type + elsif protected_method_defined?(#{original_method.inspect}) # elsif protected_method_defined?(:_unmemoized_mime_type) + protected #{symbol.inspect} # protected :mime_type end # end EOS end diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb index b11fa8d346..bceac1315b 100644 --- a/activesupport/test/memoizable_test.rb +++ b/activesupport/test/memoizable_test.rb @@ -36,6 +36,13 @@ class MemoizableTest < ActiveSupport::TestCase memoize :name, :age + protected + + def memoize_protected_test + 'protected' + end + memoize :memoize_protected_test + private def is_developer? @@ -237,6 +244,13 @@ class MemoizableTest < ActiveSupport::TestCase assert_raise(RuntimeError) { company.memoize :name } end + def test_protected_method_memoization + person = Person.new + + assert_raise(NoMethodError) { person.memoize_protected_test } + assert_equal "protected", person.send(:memoize_protected_test) + end + def test_private_method_memoization person = Person.new -- cgit v1.2.3