2013-03-11 21:15:21 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ObjectCacheTest < ActiveSupport::TestCase
|
|
|
|
test 'object cache' do
|
|
|
|
|
2015-04-27 13:43:34 +00:00
|
|
|
name = 'object cache test ' + rand(9_999_999).to_s
|
2013-03-11 21:15:21 +00:00
|
|
|
group = Group.create(
|
2015-04-27 13:42:53 +00:00
|
|
|
name: name,
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2013-03-11 21:15:21 +00:00
|
|
|
)
|
2015-04-27 13:42:53 +00:00
|
|
|
group_where = Group.where( name: name ).first
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( name, group_where[:name], 'verify by where' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_name = Group.lookup( name: name )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( name, group_lookup_name[:name], 'verify by lookup.name' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_id = Group.lookup( id: group.id )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( name, group_lookup_id[:name], 'verify by lookup.id' )
|
|
|
|
|
|
|
|
name_new = name + ' next'
|
|
|
|
group.name = name_new
|
|
|
|
group.save
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_where = Group.where( name: name ).first
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( nil, group_where, 'verify by where name_old' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_where = Group.where( name: name_new ).first
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( name_new, group_where[:name], 'verify by where name_new' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_name = Group.lookup( name: name )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_name = Group.lookup( name: name_new )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( name_new, group_lookup_name[:name], 'verify by lookup.name name_new' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_id = Group.lookup( id: group.id )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( name_new, group_lookup_id[:name], 'verify by lookup.id' )
|
|
|
|
|
|
|
|
group.destroy
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_where = Group.where( name: name ).first
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( nil, group_where, 'verify by where name_old' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_where = Group.where( name: name_new ).first
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( nil, group_where, 'verify by where name_new' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_name = Group.lookup( name: name )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_name = Group.lookup( name: name_new )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( nil, group_lookup_name, 'verify by lookup.name name_new' )
|
|
|
|
|
2015-04-27 13:42:53 +00:00
|
|
|
group_lookup_id = Group.lookup( id: group.id )
|
2013-03-11 21:15:21 +00:00
|
|
|
assert_equal( nil, group_lookup_id, 'verify by lookup.id' )
|
|
|
|
|
|
|
|
end
|
2015-02-01 12:36:22 +00:00
|
|
|
end
|