wovnrb 0.2.01 → 0.2.02
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.
- checksums.yaml +4 -4
- data/.gitignore +3 -6
- data/README.md +116 -12
- data/lib/wovnrb/api_data.rb +59 -0
- data/lib/wovnrb/headers.rb +30 -5
- data/lib/wovnrb/html_replacers/image_replacer.rb +44 -0
- data/lib/wovnrb/html_replacers/link_replacer.rb +18 -0
- data/lib/wovnrb/html_replacers/meta_replacer.rb +20 -0
- data/lib/wovnrb/html_replacers/replacer_base.rb +17 -0
- data/lib/wovnrb/html_replacers/script_replacer.rb +39 -0
- data/lib/wovnrb/html_replacers/text_replacer.rb +19 -0
- data/lib/wovnrb/lang.rb +133 -23
- data/lib/wovnrb/services/url.rb +2 -68
- data/lib/wovnrb/services/wovn_logger.rb +45 -0
- data/lib/wovnrb/store.rb +19 -38
- data/lib/wovnrb/text_caches/cache_base.rb +52 -0
- data/lib/wovnrb/text_caches/memory_cache.rb +52 -0
- data/lib/wovnrb/version.rb +1 -1
- data/lib/wovnrb.rb +19 -224
- data/test/lib/api_data_test.rb +62 -0
- data/test/lib/headers_test.rb +1221 -1212
- data/test/lib/html_replacers/image_replacer_test.rb +86 -0
- data/test/lib/html_replacers/link_replacer_test.rb +43 -0
- data/test/lib/html_replacers/meta_replacer_test.rb +105 -0
- data/test/lib/html_replacers/replacer_base_test.rb +31 -0
- data/test/lib/html_replacers/script_replacer_test.rb +90 -0
- data/test/lib/html_replacers/text_replacer_test.rb +57 -0
- data/test/lib/lang_test.rb +446 -33
- data/test/lib/services/wovn_logger_test.rb +40 -0
- data/test/lib/store_test.rb +39 -29
- data/test/lib/text_caches/cache_base_test.rb +31 -0
- data/test/lib/text_caches/memory_cache_test.rb +91 -0
- data/test/lib/wovnrb_test.rb +39 -886
- data/test/test_helper.rb +96 -1
- data/wovnrb.gemspec +4 -0
- metadata +89 -2
@@ -0,0 +1,91 @@
|
|
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_equal(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_equal(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_equal(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
|