From a712acc42543b575a623e1a8880c0e9dd5505cfa Mon Sep 17 00:00:00 2001 From: Santosh Wadghule Date: Sat, 16 Apr 2016 16:16:17 +0530 Subject: Fix forced cache miss for fetch. - Raised an argument error if no block is passed to #fetch with 'force: true' option is set. - Added tests for the same. --- activesupport/test/caching_test.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'activesupport/test/caching_test.rb') diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 9e744afb2b..032367e10d 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -266,6 +266,20 @@ module CacheStoreBehavior end end + def test_fetch_with_forced_cache_miss_with_block + @cache.write('foo', 'bar') + assert_equal 'foo_bar', @cache.fetch('foo', force: true) { 'foo_bar' } + end + + def test_fetch_with_forced_cache_miss_without_block + @cache.write('foo', 'bar') + assert_raises(ArgumentError, 'Missing block') do + @cache.fetch('foo', force: true) + end + + assert_equal 'bar', @cache.read('foo') + end + def test_should_read_and_write_hash assert @cache.write('foo', {:a => "b"}) assert_equal({:a => "b"}, @cache.read('foo')) -- cgit v1.2.3