aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/flush_cache_on_private_memoization_test.rb
blob: bc488cc743b1f143a1228ac15f9c8ef8002c4e56 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'abstract_unit'
require 'test/unit'

class FlushCacheOnPrivateMemoizationTest < Test::Unit::TestCase
  ActiveSupport::Deprecation.silence do
    extend ActiveSupport::Memoizable
  end

  def test_public
    assert_method_unmemoizable :pub
  end

  def test_protected
    assert_method_unmemoizable :prot
  end

  def test_private
    assert_method_unmemoizable :priv
  end

  def pub; rand end
  memoize :pub

  protected

  def prot; rand end
  memoize :prot

  private

  def priv; rand end
  memoize :priv

  def assert_method_unmemoizable(meth, message=nil)
    full_message = build_message(message, "<?> not unmemoizable.\n", meth)
    assert_block(full_message) do
      a = send meth
      b = send meth
      unmemoize_all
      c = send meth
      a == b && a != c
    end
  end

end