Improved tests.
This commit is contained in:
parent
f7c57d4a3b
commit
9e8fc2c058
1 changed files with 47 additions and 21 deletions
|
@ -10,50 +10,76 @@ class ObjectCacheTest < ActiveSupport::TestCase
|
|||
updated_by_id: 1,
|
||||
created_by_id: 1,
|
||||
)
|
||||
group_where = Group.where( name: name ).first
|
||||
assert_equal( name, group_where[:name], 'verify by where' )
|
||||
group_new = Group.where( name: name ).first
|
||||
assert_equal( name, group_new[:name], 'verify by where' )
|
||||
|
||||
group_lookup_name = Group.lookup( name: name )
|
||||
assert_equal( name, group_lookup_name[:name], 'verify by lookup.name' )
|
||||
# lookup by 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 )
|
||||
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'
|
||||
group.name = name_new
|
||||
group.save
|
||||
|
||||
group_where = Group.where( name: name ).first
|
||||
assert_equal( nil, group_where, 'verify by where name_old' )
|
||||
# lookup by name
|
||||
cache_key = "#{group.name}"
|
||||
assert_nil( Group.cache_get(cache_key) )
|
||||
|
||||
group_where = Group.where( name: name_new ).first
|
||||
assert_equal( name_new, group_where[:name], 'verify by where name_new' )
|
||||
group_lookup = Group.where( name: group_new.name ).first
|
||||
assert_nil( group_lookup, 'verify by where name_old' )
|
||||
assert_nil( Group.cache_get(cache_key) )
|
||||
|
||||
group_lookup_name = Group.lookup( name: name )
|
||||
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' )
|
||||
group_lookup = Group.where( name: group.name ).first
|
||||
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( 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 )
|
||||
assert_equal( name_new, group_lookup_id[:name], 'verify by lookup.id' )
|
||||
assert( Group.cache_get(cache_key) )
|
||||
|
||||
group.destroy
|
||||
|
||||
group_where = Group.where( name: name ).first
|
||||
assert_equal( nil, group_where, 'verify by where name_old' )
|
||||
# lookup by name
|
||||
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
|
||||
assert_equal( nil, group_where, 'verify by where name_new' )
|
||||
group_lookup = Group.where( name: group.name ).first
|
||||
assert_nil( group_lookup, 'verify by where name_new' )
|
||||
|
||||
group_lookup_name = Group.lookup( name: name )
|
||||
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' )
|
||||
group_lookup_name = Group.lookup( name: group_new.name )
|
||||
assert_nil( group_lookup_name, 'verify by lookup.name name_old' )
|
||||
|
||||
group_lookup_name = Group.lookup( name: name_new )
|
||||
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_new' )
|
||||
group_lookup_name = Group.lookup( name: group.name )
|
||||
assert_nil( group_lookup_name, 'verify by lookup.name name_new' )
|
||||
|
||||
# lookup by 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
|
||||
|
|
Loading…
Reference in a new issue