test/fetch_test.rb in identity_cache-0.4.0 vs test/fetch_test.rb in identity_cache-0.4.1

- old
+ new

@@ -15,11 +15,11 @@ @blob_key = "#{NAMESPACE}blob:Item:#{cache_hash("created_at:datetime,id:integer,item_id:integer,title:string,updated_at:datetime")}:1" @index_key = "#{NAMESPACE}attr:Item:id:title:#{cache_hash('bob')}" end def test_fetch_with_garbage_input - assert_equal nil, Item.fetch_by_id('garbage') + assert_nil Item.fetch_by_id('garbage') end def test_fetch_cache_hit IdentityCache.cache.expects(:fetch).with(@blob_key).returns(@cached_value) @@ -108,11 +108,11 @@ def test_fetch_by_id_not_found_should_return_nil nonexistent_record_id = 10 fetcher.expects(:add).with(@blob_key + '0', IdentityCache::CACHED_NIL) - assert_equal nil, Item.fetch_by_id(nonexistent_record_id) + assert_nil Item.fetch_by_id(nonexistent_record_id) end def test_fetch_not_found_should_raise nonexistent_record_id = 10 fetcher.expects(:add).with(@blob_key + '0', IdentityCache::CACHED_NIL) @@ -121,11 +121,11 @@ end def test_cached_nil_expiry_on_record_creation key = @record.primary_cache_index_key - assert_equal nil, Item.fetch_by_id(@record.id) + assert_nil Item.fetch_by_id(@record.id) assert_equal IdentityCache::CACHED_NIL, backend.read(key) @record.save! assert_equal IdentityCache::DELETED, backend.read(key) end @@ -160,14 +160,14 @@ def test_fetch_by_title_stores_idcnil Item.connection.expects(:exec_query).once.returns(ActiveRecord::Result.new([], [])) add = Spy.on(fetcher, :add).and_call_through fetch = Spy.on(fetcher, :fetch).and_call_through - assert_equal nil, Item.fetch_by_title('bob') # exec_query => nil + assert_nil Item.fetch_by_title('bob') # exec_query => nil - assert_equal nil, Item.fetch_by_title('bob') # returns cached nil - assert_equal nil, Item.fetch_by_title('bob') # returns cached nil + assert_nil Item.fetch_by_title('bob') # returns cached nil + assert_nil Item.fetch_by_title('bob') # returns cached nil assert add.has_been_called_with?(@index_key, IdentityCache::CACHED_NIL) assert_equal 3, fetch.calls.length end @@ -239,9 +239,20 @@ Item.expects(:resolve_cache_miss).with(1).once.returns(@record) refute IdentityCache.should_use_cache? refute fetch.has_been_called_with?(@blob_key) refute Item.fetch(1).readonly?, "Fetched item was read-only" + end + end + end + + def test_respects_should_use_cache_on_record + @record.save + Item.stubs(:should_use_cache?).returns(false) + + assert_memcache_operations(0) do + assert_queries(1) do + Item.fetch_by_id(@record.id) end end end end