diff options
author | Joshua Peek <josh@joshpeek.com> | 2008-07-18 11:18:16 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2008-07-18 11:19:38 -0500 |
commit | e1f23da53cef20a60e4bf458d959fe2bfe7d52ea (patch) | |
tree | 97753d4e40ef08da5c0827b51e03a4e7f5c8c276 /activesupport/test | |
parent | 7430c4168fad07b480dbf80c8ac75ba7db8c634f (diff) | |
download | rails-e1f23da53cef20a60e4bf458d959fe2bfe7d52ea.tar.gz rails-e1f23da53cef20a60e4bf458d959fe2bfe7d52ea.tar.bz2 rails-e1f23da53cef20a60e4bf458d959fe2bfe7d52ea.zip |
Allow memoized methods to be reloaded and allow multiple symbols
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/memoizable_test.rb | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb index fc24a2942d..b649b31455 100644 --- a/activesupport/test/memoizable_test.rb +++ b/activesupport/test/memoizable_test.rb @@ -8,12 +8,16 @@ uses_mocha 'Memoizable' do def name fetch_name_from_floppy end - memoize :name def age nil end - memoize :age + + def random + rand(0) + end + + memoize :name, :age, :random private def fetch_name_from_floppy @@ -21,25 +25,34 @@ uses_mocha 'Memoizable' do end end + def setup + @person = Person.new + end + def test_memoization - person = Person.new - assert_equal "Josh", person.name + assert_equal "Josh", @person.name + + @person.expects(:fetch_name_from_floppy).never + 2.times { assert_equal "Josh", @person.name } + end - person.expects(:fetch_name_from_floppy).never - 2.times { assert_equal "Josh", person.name } + def test_reloadable + random = @person.random + assert_equal random, @person.random + assert_not_equal random, @person.random(:reload) end def test_memoized_methods_are_frozen - person = Person.new - person.freeze - assert_equal "Josh", person.name - assert_equal true, person.name.frozen? + assert_equal true, @person.name.frozen? + + @person.freeze + assert_equal "Josh", @person.name + assert_equal true, @person.name.frozen? end def test_memoization_frozen_with_nil_value - person = Person.new - person.freeze - assert_equal nil, person.age + @person.freeze + assert_equal nil, @person.age end def test_double_memoization |