wovnrb 3.0.1 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,91 +0,0 @@
1
- require 'wovnrb/text_caches/cache_base'
2
- require 'wovnrb/text_caches/memory_cache'
3
- require 'minitest/autorun'
4
- require 'timecop'
5
-
6
- class MemoryCacheTest < Minitest::Test
7
- def test_initialize
8
- memory = Wovnrb::MemoryCache.new(
9
- 'cache_megabytes' => 1,
10
- 'ttl_seconds' => 1
11
- )
12
- option = memory.options
13
- assert_equal(1.megabytes, option[:size])
14
- assert_equal(1.megabytes, option[:size])
15
- assert_equal(1.seconds, option[:expires_in])
16
- end
17
-
18
- def test_initialize_without_cache_megabytes
19
- memory = Wovnrb::MemoryCache.new(
20
- 'ttl_seconds' => 1
21
- )
22
- option = memory.options
23
- assert_equal(200.megabytes, option[:size])
24
- assert_equal(1.seconds, option[:expires_in])
25
- end
26
-
27
- def test_initialize_without_ttl
28
- memory = Wovnrb::MemoryCache.new(
29
- 'cache_megabytes' => 1
30
- )
31
- option = memory.options
32
- assert_equal(1.megabytes, option[:size])
33
- assert_equal(300.seconds, option[:expires_in])
34
- end
35
-
36
- def test_initialize_with_no_config
37
- memory = Wovnrb::MemoryCache.new({})
38
- option = memory.options
39
- assert_equal(200.megabytes, option[:size])
40
- assert_equal(300.seconds, option[:expires_in])
41
- end
42
-
43
- def test_put_without_cache
44
- memory = Wovnrb::MemoryCache.new({})
45
- memory.put('a', 'b')
46
- assert_equal('b', memory.get('a'))
47
- end
48
-
49
- def test_put_with_cache
50
- memory = Wovnrb::MemoryCache.new({})
51
- memory.put('a', 'b')
52
- memory.put('a', 'b2')
53
- assert_equal('b2', memory.get('a'))
54
- end
55
-
56
- def test_get_with_cache
57
- memory = Wovnrb::MemoryCache.new({})
58
- memory.put('a', 'b')
59
- assert_equal('b', memory.get('a'))
60
- end
61
-
62
- def test_get_without_cache
63
- memory = Wovnrb::MemoryCache.new({})
64
- assert_nil(memory.get('a'))
65
-
66
- end
67
-
68
- def test_get_with_timeout
69
- memory = Wovnrb::MemoryCache.new({})
70
- memory.put('a', 'b')
71
- Timecop.travel(1.day.since)
72
- assert_nil(memory.get('a'))
73
- end
74
-
75
- def test_get_with_over_memory
76
- # ActiveSupport::Cache::MemoryStore has 240 bytes overhead per instance
77
- memory = Wovnrb::MemoryCache.new(
78
- 'cache_megabytes' => 400.0 / 1000 / 1000
79
- )
80
- memory.put('a', 'c')
81
- memory.put('b', 'd')
82
- assert_nil(memory.get('a'))
83
- assert_equal('d', memory.get('b'))
84
- end
85
-
86
- def test_get_with_utf8
87
- memory = Wovnrb::MemoryCache.new({})
88
- memory.put('http://www.example.com', 'あいうえお')
89
- assert_equal('あいうえお', memory.get('http://www.example.com'))
90
- end
91
- end