test/fetch_test.rb in identity_cache-0.2.5 vs test/fetch_test.rb in identity_cache-0.3.0

- old
+ new

@@ -9,21 +9,16 @@ Item.cache_index :id, :title, :unique => true @record = Item.new @record.id = 1 @record.title = 'bob' - @cached_value = {:class => @record.class} - @record.encode_with(@cached_value) + @cached_value = {class: @record.class, attributes: @record.attributes_before_type_cast} @blob_key = "#{NAMESPACE}blob:Item:#{cache_hash("created_at:datetime,id:integer,item_id:integer,title:string,updated_at:datetime")}:1" - @index_key = "#{NAMESPACE}index:Item:title:#{cache_hash('bob')}" + @index_key = "#{NAMESPACE}attr:Item:id:title:#{cache_hash('bob')}" end def test_fetch_with_garbage_input - Item.connection.expects(:exec_query) - .with(Item.where(id: 0).limit(1).to_sql, any_parameters) - .returns(ActiveRecord::Result.new([], [])) - assert_equal nil, Item.fetch_by_id('garbage') end def test_fetch_cache_hit IdentityCache.cache.expects(:fetch).with(@blob_key).returns(@cached_value) @@ -196,7 +191,25 @@ ActiveRecord::Base.clear_active_connections! assert_equal record, Item.fetch(@record.id) assert_equal false, ActiveRecord::Base.connection_handler.active_connections? + end + + def test_fetch_raises_when_called_on_a_scope + assert_raises(IdentityCache::UnsupportedScopeError) do + Item.where(updated_at: nil).fetch(1) + end + end + + def test_fetch_by_raises_when_called_on_a_scope + assert_raises(IdentityCache::UnsupportedScopeError) do + Item.where(updated_at: nil).fetch_by_id(1) + end + end + + def test_fetch_on_derived_model_raises + assert_raises(IdentityCache::DerivedModelError) do + StiRecordTypeA.fetch(1) + end end end