object_cache_test.rb 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # encoding: utf-8
  2. require 'test_helper'
  3. class ObjectCacheTest < ActiveSupport::TestCase
  4. test 'object cache' do
  5. name = 'object cache test ' + rand(9999999).to_s
  6. group = Group.create(
  7. :name => name,
  8. :updated_by_id => 1,
  9. :created_by_id => 1,
  10. )
  11. group_where = Group.where( :name => name ).first
  12. assert_equal( name, group_where[:name], 'verify by where' )
  13. group_lookup_name = Group.lookup( :name => name )
  14. assert_equal( name, group_lookup_name[:name], 'verify by lookup.name' )
  15. group_lookup_id = Group.lookup( :id => group.id )
  16. assert_equal( name, group_lookup_id[:name], 'verify by lookup.id' )
  17. name_new = name + ' next'
  18. group.name = name_new
  19. group.save
  20. group_where = Group.where( :name => name ).first
  21. assert_equal( nil, group_where, 'verify by where name_old' )
  22. group_where = Group.where( :name => name_new ).first
  23. assert_equal( name_new, group_where[:name], 'verify by where name_new' )
  24. group_lookup_name = Group.lookup( :name => name )
  25. assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' )
  26. group_lookup_name = Group.lookup( :name => name_new )
  27. assert_equal( name_new, group_lookup_name[:name], 'verify by lookup.name name_new' )
  28. group_lookup_id = Group.lookup( :id => group.id )
  29. assert_equal( name_new, group_lookup_id[:name], 'verify by lookup.id' )
  30. group.destroy
  31. group_where = Group.where( :name => name ).first
  32. assert_equal( nil, group_where, 'verify by where name_old' )
  33. group_where = Group.where( :name => name_new ).first
  34. assert_equal( nil, group_where, 'verify by where name_new' )
  35. group_lookup_name = Group.lookup( :name => name )
  36. assert_equal( nil, group_lookup_name, 'verify by lookup.name name_old' )
  37. group_lookup_name = Group.lookup( :name => name_new )
  38. assert_equal( nil, group_lookup_name, 'verify by lookup.name name_new' )
  39. group_lookup_id = Group.lookup( :id => group.id )
  40. assert_equal( nil, group_lookup_id, 'verify by lookup.id' )
  41. end
  42. end