mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
memoized protected methods should remain protected
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
parent
72543b2e63
commit
fb08e334d6
2 changed files with 16 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue