Skip to content
This repository
Browse code

memoized protected methods should remain protected

Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
  • Loading branch information...
commit fb08e334d61b1706db754733b209075b0154b57e 1 parent 72543b2
Andrew Kaspick authored September 23, 2010 spastorino committed September 24, 2010
2  activesupport/lib/active_support/memoizable.rb
@@ -95,6 +95,8 @@ def #{symbol}(*args)                                                   #   def m
95 95
                                                                                    #
96 96
           if private_method_defined?(#{original_method.inspect})                   # if private_method_defined?(:_unmemoized_mime_type)
97 97
             private #{symbol.inspect}                                              #   private :mime_type
  98
+          elsif protected_method_defined?(#{original_method.inspect})              # elsif protected_method_defined?(:_unmemoized_mime_type)
  99
+            protected #{symbol.inspect}                                            #   protected :mime_type
98 100
           end                                                                      # end
99 101
         EOS
100 102
       end
14  activesupport/test/memoizable_test.rb
@@ -36,6 +36,13 @@ def age
36 36
 
37 37
     memoize :name, :age
38 38
 
  39
+    protected
  40
+
  41
+    def memoize_protected_test
  42
+      'protected'
  43
+    end
  44
+    memoize :memoize_protected_test
  45
+
39 46
     private
40 47
 
41 48
     def is_developer?
@@ -237,6 +244,13 @@ def test_double_memoization
237 244
     assert_raise(RuntimeError) { company.memoize :name }
238 245
   end
239 246
 
  247
+  def test_protected_method_memoization
  248
+    person = Person.new
  249
+
  250
+    assert_raise(NoMethodError) { person.memoize_protected_test }
  251
+    assert_equal "protected", person.send(:memoize_protected_test)
  252
+  end
  253
+
240 254
   def test_private_method_memoization
241 255
     person = Person.new
242 256
 

0 notes on commit fb08e33

Please sign in to comment.
Something went wrong with that request. Please try again.