forked from instructure/canvas-lms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcacheSpec.coffee
More file actions
68 lines (56 loc) · 2.05 KB
/
Copy pathcacheSpec.coffee
File metadata and controls
68 lines (56 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#
# Copyright (C) 2012 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
define [
'underscore'
'compiled/class/cache'
], (_, cache) ->
QUnit.module 'class/cache',
setup: ->
# need to get the cache from its wrapper object
# because cache is meant to be used as a class
# mixin
@cache = cache.cache
test 'should store strings', ->
@cache.set 'key', 'value'
equal @cache.get('key'), 'value'
test 'should store arrays and objects', ->
@cache.set 'array', [1, 2, 3]
@cache.set 'object', a: 1, b: 2
ok _.isEqual @cache.get('array'), [1, 2, 3]
ok _.isEqual @cache.get('object'), a: 1, b: 2
test 'should delete keys', ->
@cache.set 'key', 'value'
@cache.remove 'key'
equal @cache.get('key'), null
test 'should accept complex keys', ->
@cache.set [1, 2, 3], 'value1'
@cache.set {a: 1, b: 1}, 'value2'
@cache.set [1, 2], {a: 1}, 'test', 'value3'
equal @cache.get([1, 2, 3]), 'value1'
equal @cache.get({a: 1, b: 1}), 'value2'
equal @cache.get([1, 2], {a: 1}, 'test'), 'value3'
test 'should accept a prefix', ->
@cache.prefix = 'prefix-'
@cache.set 'key', 'value'
equal typeof @cache.store['prefix-"key"'], 'string'
test 'should accept local and sessionStorage as stores', ->
@cache.use 'localStorage'
equal @cache.store, localStorage
@cache.use 'sessionStorage'
equal @cache.store, sessionStorage
# teardown for this test only
@cache.use 'memory'