Skip to content

Commit

Permalink
memoized protected methods should remain protected
Browse files Browse the repository at this point in the history
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information
akaspick authored and spastorino committed Sep 24, 2010
1 parent 72543b2 commit fb08e33
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activesupport/lib/active_support/memoizable.rb
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions activesupport/test/memoizable_test.rb
Expand Up @@ -36,6 +36,13 @@ def age

memoize :name, :age

protected

def memoize_protected_test
'protected'
end
memoize :memoize_protected_test

private

def is_developer?
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit fb08e33

Please sign in to comment.