test/fetch_test.rb in identity_cache-0.2.2 vs test/fetch_test.rb in identity_cache-0.2.3

- old
+ new

@@ -17,11 +17,11 @@ @index_key = "#{NAMESPACE}index:Item:title:#{cache_hash('bob')}" end def test_fetch_with_garbage_input Item.connection.expects(:exec_query) - .with('SELECT `items`.* FROM `items` WHERE `items`.`id` = 0 LIMIT 1', anything) + .with(Item.where(id: 0).limit(1).to_sql, any_parameters) .returns(ActiveRecord::Result.new([], [])) assert_equal nil, Item.fetch_by_id('garbage') end @@ -185,7 +185,18 @@ def test_fetch_does_not_communicate_to_cache_with_nil_id fetcher.expects(:fetch).never fetcher.expects(:add).never assert_raises(ActiveRecord::RecordNotFound) { Item.fetch(nil) } + end + + def test_fetch_cache_hit_does_not_checkout_database_connection + @record.save! + record = Item.fetch(@record.id) + + ActiveRecord::Base.clear_active_connections! + + assert_equal record, Item.fetch(@record.id) + + assert_equal false, ActiveRecord::Base.connection_handler.active_connections? end end