2013-03-11 21:15:21 +00:00
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
class ObjectCacheTest < ActiveSupport::TestCase
|
2015-06-18 22:39:34 +00:00
|
|
|
test 'organization cache' do
|
|
|
|
org = Organization.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'some org cache member',
|
2015-06-18 22:39:34 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
|
|
|
)
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
roles = Role.where( name: %w[Agent Admin] )
|
2015-06-18 22:39:34 +00:00
|
|
|
groups = Group.all
|
|
|
|
user1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'object_cache1@example.org',
|
|
|
|
firstname: 'object_cache1',
|
|
|
|
lastname: 'object_cache1',
|
|
|
|
email: 'object_cache1@example.org',
|
|
|
|
password: 'some_pass',
|
|
|
|
active: true,
|
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2015-06-18 22:39:34 +00:00
|
|
|
organization_id: org.id,
|
2018-12-19 17:31:51 +00:00
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2015-06-18 22:39:34 +00:00
|
|
|
)
|
|
|
|
assets = org.assets({})
|
2016-02-22 08:51:32 +00:00
|
|
|
assert_equal(org.member_ids.sort, assets[:Organization][org.id]['member_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
|
|
|
|
user1.organization_id = nil
|
|
|
|
user1.save
|
2017-10-18 09:21:10 +00:00
|
|
|
org.reload
|
2015-06-18 22:39:34 +00:00
|
|
|
|
|
|
|
assets = org.assets({})
|
2016-02-22 08:51:32 +00:00
|
|
|
assert_equal(org.member_ids.sort, assets[:Organization][org.id]['member_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test 'user cache' do
|
2017-11-23 08:09:44 +00:00
|
|
|
roles = Role.where(name: %w[Agent Admin])
|
2017-06-16 20:43:09 +00:00
|
|
|
groups = Group.all.order(:id)
|
2017-04-19 07:37:43 +00:00
|
|
|
|
|
|
|
# be sure that minimum one admin is available
|
|
|
|
User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'last_admin_check@example.org',
|
|
|
|
firstname: 'last_admin_check',
|
|
|
|
lastname: 'last_admin_check',
|
|
|
|
email: 'last_admin_check@example.org',
|
|
|
|
password: 'some_pass',
|
|
|
|
active: true,
|
2017-04-19 07:37:43 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2018-12-19 17:31:51 +00:00
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2017-04-19 07:37:43 +00:00
|
|
|
)
|
|
|
|
|
2015-06-18 22:39:34 +00:00
|
|
|
user1 = User.create_or_update(
|
2018-12-19 17:31:51 +00:00
|
|
|
login: 'object_cache1@example.org',
|
|
|
|
firstname: 'object_cache1',
|
|
|
|
lastname: 'object_cache1',
|
|
|
|
email: 'object_cache1@example.org',
|
|
|
|
password: 'some_pass',
|
|
|
|
active: true,
|
2015-06-18 22:39:34 +00:00
|
|
|
updated_by_id: 1,
|
|
|
|
created_by_id: 1,
|
2018-12-19 17:31:51 +00:00
|
|
|
roles: roles,
|
|
|
|
groups: groups,
|
2015-06-18 22:39:34 +00:00
|
|
|
)
|
|
|
|
assets = user1.assets({})
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_equal(user1.group_ids_access_map.sort, assets[:User][user1.id]['group_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
|
|
|
|
# update group
|
|
|
|
group1 = groups.first
|
2015-07-03 15:32:48 +00:00
|
|
|
group1.note = "some note #{rand(9_999_999_999)}"
|
2015-06-18 22:39:34 +00:00
|
|
|
group1.save
|
|
|
|
|
|
|
|
assets = user1.assets({})
|
2017-06-16 20:43:09 +00:00
|
|
|
assert(assets[:Group][group1.id])
|
2016-02-22 08:51:32 +00:00
|
|
|
assert_equal(group1.note, assets[:Group][group1.id]['note'])
|
2015-06-18 22:39:34 +00:00
|
|
|
|
|
|
|
# update group
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_equal(user1.group_ids_access_map.sort, assets[:User][user1.id]['group_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
user1.group_ids = []
|
|
|
|
user1.save
|
|
|
|
|
|
|
|
assets = user1.assets({})
|
2017-06-16 20:43:09 +00:00
|
|
|
assert_equal(user1.group_ids_access_map.sort, assets[:User][user1.id]['group_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
|
|
|
|
# update role
|
2016-02-22 08:51:32 +00:00
|
|
|
assert_equal(user1.role_ids.sort, assets[:User][user1.id]['role_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
user1.role_ids = []
|
|
|
|
user1.save
|
|
|
|
|
|
|
|
assets = user1.assets({})
|
2016-02-22 08:51:32 +00:00
|
|
|
assert_equal(user1.role_ids.sort, assets[:User][user1.id]['role_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
|
|
|
|
# update groups
|
2016-02-22 08:51:32 +00:00
|
|
|
assert_equal(user1.organization_ids.sort, assets[:User][user1.id]['organization_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
user1.organization_ids = [1]
|
|
|
|
user1.save
|
|
|
|
|
|
|
|
assets = user1.assets({})
|
2016-02-22 08:51:32 +00:00
|
|
|
assert_equal(user1.organization_ids.sort, assets[:User][user1.id]['organization_ids'].sort)
|
2015-06-18 22:39:34 +00:00
|
|
|
|
|
|
|
end
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|