Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

memoized protected methods should remain protected

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit 0387d5b6f29a46884f2250caa8d82618f795bf13 1 parent 23f728a
@akaspick akaspick authored spastorino committed
View
2  activesupport/lib/active_support/memoizable.rb
@@ -95,6 +95,8 @@ def #{symbol}(*args) # def m
#
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
View
14 activesupport/test/memoizable_test.rb
@@ -36,6 +36,13 @@ def age
memoize :name, :age
+ protected
+
+ def memoize_protected_test
+ 'protected'
+ end
+ memoize :memoize_protected_test
+
private
def is_developer?
@@ -237,6 +244,13 @@ def test_double_memoization
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
Please sign in to comment.
Something went wrong with that request. Please try again.