Improved tests.

This commit is contained in:
Martin Edenhofer 2015-06-18 23:26:58 +02:00
parent f7c57d4a3b
commit 9e8fc2c058

View file

@ -10,50 +10,76 @@ class ObjectCacheTest < ActiveSupport::TestCase
updated_by_id: 1, updated_by_id: 1,
created_by_id: 1, created_by_id: 1,
) )
group_where = Group.where( name: name ).first group_new = Group.where( name: name ).first
assert_equal( name, group_where[:name], 'verify by where' ) assert_equal( name, group_new[:name], 'verify by where' )
group_lookup_name = Group.lookup( name: name ) # lookup by name
assert_equal( name, group_lookup_name[:name], 'verify by lookup.name' ) cache_key = "#{group_new.name}"
assert_nil( Group.cache_get(cache_key) )
group_lookup_name = Group.lookup( name: group_new.name )
assert_equal( group_new.name, group_lookup_name[:name], 'verify by lookup.name' )
assert( Group.cache_get(cache_key) )
# lookup by id
cache_key = "#{group_new.id}"
assert_nil( Group.cache_get(cache_key) )
group_lookup_id = Group.lookup( id: group.id ) group_lookup_id = Group.lookup( id: group.id )
assert_equal( name, group_lookup_id[:name], 'verify by lookup.id' ) assert_equal( group_new.name, group_lookup_id[:name], 'verify by lookup.id' )
assert( Group.cache_get(cache_key) )
# update / check if old name caches are deleted
name_new = name + ' next' name_new = name + ' next'
group.name = name_new group.name = name_new
group.save group.save
group_where = Group.where( name: name ).first # lookup by name
assert_equal( nil, group_where, 'verify by where name_old' ) cache_key = "#{group.name}"
assert_nil( Group.cache_get(cache_key) )
group_where = Group.where( name: name_new ).first group_lookup = Group.where( name: group_new.name ).first
assert_equal( name_new, group_where[:name], 'verify by where name_new' ) assert_nil( group_lookup, 'verify by where name_old' )
assert_nil( Group.cache_get(cache_key) )
group_lookup_name = Group.lookup( name: name ) group_lookup = Group.where( name: group.name ).first
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' ) assert_equal( name_new, group_lookup[:name], 'verify by where name_new' )
assert_nil( Group.cache_get(cache_key) )
group_lookup_name = Group.lookup( name: name_new ) group_lookup_name = Group.lookup( name: group_new.name )
assert_nil( group_lookup_name, 'verify by lookup.name name_old' )
assert_nil( Group.cache_get(cache_key) )
group_lookup_name = Group.lookup( name: group.name )
assert_equal( name_new, group_lookup_name[:name], 'verify by lookup.name name_new' ) assert_equal( name_new, group_lookup_name[:name], 'verify by lookup.name name_new' )
assert( Group.cache_get(cache_key) )
# lookup by id
cache_key = "#{group_new.id}"
assert_nil( Group.cache_get(cache_key) )
group_lookup_id = Group.lookup( id: group.id ) group_lookup_id = Group.lookup( id: group.id )
assert_equal( name_new, group_lookup_id[:name], 'verify by lookup.id' ) assert_equal( name_new, group_lookup_id[:name], 'verify by lookup.id' )
assert( Group.cache_get(cache_key) )
group.destroy group.destroy
group_where = Group.where( name: name ).first # lookup by name
assert_equal( nil, group_where, 'verify by where name_old' ) group_lookup = Group.where( name: group_new.name ).first
assert_nil( group_lookup, 'verify by where name_old' )
group_where = Group.where( name: name_new ).first group_lookup = Group.where( name: group.name ).first
assert_equal( nil, group_where, 'verify by where name_new' ) assert_nil( group_lookup, 'verify by where name_new' )
group_lookup_name = Group.lookup( name: name ) group_lookup_name = Group.lookup( name: group_new.name )
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' ) assert_nil( group_lookup_name, 'verify by lookup.name name_old' )
group_lookup_name = Group.lookup( name: name_new ) group_lookup_name = Group.lookup( name: group.name )
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_new' ) assert_nil( group_lookup_name, 'verify by lookup.name name_new' )
# lookup by id
group_lookup_id = Group.lookup( id: group.id ) group_lookup_id = Group.lookup( id: group.id )
assert_equal( nil, group_lookup_id, 'verify by lookup.id' ) assert_nil( group_lookup_id, 'verify by lookup.id' )
end end
end end