wovnrb 0.1.69 → 0.1.70
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/lib/wovnrb/headers.rb +1 -1
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/wovnrb_test.rb +99 -26
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4776a67c2ad218f974c0f0b4f3c0b832c90a5a09
|
4
|
+
data.tar.gz: cc37e82b4c978abe5ce1ea7ac395a9d185998dca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96e887e480911dc72395cd152840e9762dc1ae0037e10c34934c3cd4c2a55dafc39b5da62c4bd8dab77f9e91de1a973df8a562b0dfb0157f113f0492fff3e036
|
7
|
+
data.tar.gz: 41c97ebc38bf12c946f9ad0046fe916b8d37caf217a9ae9981bab406b8d0da768bbf2075a7b07cfc30994c4501cc52006ddae896097b9b3b0d68405df1246225
|
data/lib/wovnrb/headers.rb
CHANGED
@@ -154,7 +154,7 @@ module Wovnrb
|
|
154
154
|
when 'query'
|
155
155
|
return uri.sub(/(^|\?|&)wovn=#{lang}(&|$)/, '\1').gsub(/(\?|&)$/, '')
|
156
156
|
when 'subdomain'
|
157
|
-
rp = Regexp.new('(^|(//))' + lang + '\.')
|
157
|
+
rp = Regexp.new('(^|(//))' + lang + '\.', 'i')
|
158
158
|
return uri.sub(rp, '\1')
|
159
159
|
#when 'path'
|
160
160
|
else
|
data/lib/wovnrb/version.rb
CHANGED
data/test/lib/wovnrb_test.rb
CHANGED
@@ -1,28 +1,56 @@
|
|
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
|
-
|
1
|
+
require 'wovnrb'
|
2
|
+
require 'wovnrb/headers'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'pry'
|
5
|
+
|
6
|
+
class WovnrbTest < Minitest::Test
|
7
|
+
|
8
|
+
def test_initialize
|
9
|
+
i = Wovnrb::Interceptor.new(get_app)
|
10
|
+
refute_nil(i)
|
11
|
+
end
|
12
|
+
|
13
|
+
# def test_call(env)
|
14
|
+
# end
|
15
|
+
|
16
|
+
# def test_switch_lang(body, values, url, lang=STORE.settings['default_lang'], headers)
|
17
|
+
# end
|
18
|
+
|
19
|
+
# def test_get_langs(values)
|
20
|
+
# end
|
21
|
+
|
22
|
+
def get_app()
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_add_lang_code_trad_chinese
|
26
|
+
i = Wovnrb::Interceptor.new(get_app)
|
27
|
+
h = Wovnrb::Headers.new(get_env('url' => 'http://favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
28
|
+
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("http://favy.tips/topics/31", 'subdomain', 'zh-cht', h))
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_add_lang_code_trad_chinese_2
|
32
|
+
i = Wovnrb::Interceptor.new(get_app)
|
33
|
+
h = Wovnrb::Headers.new(get_env('url' => 'http://zh-cht.favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
34
|
+
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("/topics/31", 'subdomain', 'zh-cht', h))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_add_lang_code_trad_chinese_lang_in_link_already
|
38
|
+
i = Wovnrb::Interceptor.new(get_app)
|
39
|
+
h = Wovnrb::Headers.new(get_env('url' => 'http://zh-cht.favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
40
|
+
assert_equal("http://zh-cht.favy.tips/topics/31", i.add_lang_code("http://zh-cht.favy.tips/topics/31", 'subdomain', 'zh-cht', h))
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_add_lang_code_no_protocol
|
44
|
+
i = Wovnrb::Interceptor.new(get_app)
|
45
|
+
h = Wovnrb::Headers.new(get_env('url' => 'https://zh-cht.google.com'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
46
|
+
assert_equal("//zh-cht.google.com", i.add_lang_code("//google.com", 'subdomain', 'zh-cht', h))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_add_lang_code_no_protocol_2
|
50
|
+
i = Wovnrb::Interceptor.new(get_app)
|
51
|
+
h = Wovnrb::Headers.new(get_env('url' => 'https://zh-cht.favy.tips'), get_settings('url_pattern' => 'subdomain', 'url_pattern_reg' => '^(?<lang>[^.]+).'))
|
52
|
+
assert_equal("//google.com", i.add_lang_code("//google.com", 'subdomain', 'zh-cht', h))
|
53
|
+
end
|
26
54
|
# def test_add_lang_code_nil_href
|
27
55
|
# i = Wovnrb::Interceptor.new(get_app)
|
28
56
|
# assert_equal(nil, i.add_lang_code(nil,'path', 'en', nil))
|
@@ -157,4 +185,49 @@
|
|
157
185
|
# headers.expects(:pathname).returns('/hello/tab.html')
|
158
186
|
# assert_equal('/fr/hello/hey/index.html', i.add_lang_code('hey/index.html', 'path', 'fr', headers))
|
159
187
|
# end
|
160
|
-
|
188
|
+
|
189
|
+
def get_settings(options={})
|
190
|
+
settings = {}
|
191
|
+
settings['user_token'] = 'OHYx9'
|
192
|
+
settings['url_pattern'] = 'path'
|
193
|
+
settings['url_pattern_reg'] = "/(?<lang>[^/.?]+)"
|
194
|
+
settings['query'] = []
|
195
|
+
settings['backend_host'] = 'localhost'
|
196
|
+
settings['backend_port'] = '6379'
|
197
|
+
settings['default_lang'] = 'en'
|
198
|
+
settings['supported_langs'] = []
|
199
|
+
settings['secret_key'] = ''
|
200
|
+
return settings.merge(options)
|
201
|
+
end
|
202
|
+
|
203
|
+
def get_env(options={})
|
204
|
+
env = {}
|
205
|
+
env['rack.url_scheme'] = 'http'
|
206
|
+
env['HTTP_HOST'] = 'wovn.io'
|
207
|
+
env['REQUEST_URI'] = '/dashboard?param=val&hey=you'
|
208
|
+
env['SERVER_NAME'] = 'wovn.io'
|
209
|
+
env['HTTP_COOKIE'] = "olfsk=olfsk021093478426337242; hblid=KB8AAMzxzu2DSxnB4X7BJ26rBGVeF0yJ; optimizelyEndUserId=oeu1426233718869r0.5398541854228824; __zlcmid=UFeZqrVo6Mv3Yl; wovn_selected_lang=en; optimizelySegments=%7B%7D; optimizelyBuckets=%7B%7D; _equalizer_session=eDFwM3M2QUZJZFhoby9JZlArckcvSUJwNFRINXhUeUxtNnltQXZhV0tqdGhZQjJMZ01URnZTK05ydFVWYmM3U0dtMVN0M0Z0UnNDVG8vdUNDTUtPc21jY0FHREgrZ05CUnBTb0hyUlkvYlBWQVhQR3RZdnhjMWsrRW5rOVp1Z3V3bkgyd3NpSlRZQWU1dlZvNmM1THp6aUZVeE83Y1pWWENRNTBUVFIrV05WeTdDMlFlem1tUzdxaEtndFZBd2dtUjU2ak5EUmJPa3RWWmMyT1pSVWdMTm8zOVZhUWhHdGQ3L1c5bm91RmNSdFRrcC90Tml4N2t3ZWlBaDRya2lLT1I0S0J2TURhUWl6Uk5rOTQ4Y1MwM3VKYnlLMUYraEt5clhRdFd1eGdEWXdZd3pFbWQvdE9vQndhdDVQbXNLcHBURm9CbnZKenU2YnNXRFdqRVl0MVV3bmRyYjhvMDExcGtUVU9tK1lqUGswM3p6M05tbVRnTjE3TUl5cEdpTTZ4a2gray8xK0FvTC9wUDVka1JSeE5GM1prZmRjWDdyVzRhWW5uS2Mxc1BxOEVVTTZFS3N5bTlVN2p5eE5YSjNZWGI2UHd3Vzc0bDM5QjIwL0l5Mm85NmQyWFAwdVQ3ZzJYYk1QOHY2NVJpY2c9LS1KNU96eHVycVJxSDJMbEc4Rm9KVXpBPT0%3D--17e47555d692fb9cde20ef78a09a5eabbf805bb3; mp_a0452663eb7abb7dfa9c94007ebb0090_mixpanel=%7B%22distinct_id%22%3A%20%2253ed9ffa4a65662e37000000%22%2C%22%24initial_referrer%22%3A%20%22http%3A%2F%2Fp.dev-wovn.io%3A8080%2Fhttp%3A%2F%2Fdev-wovn.io%3A3000%22%2C%22%24initial_referring_domain%22%3A%20%22p.dev-wovn.io%3A8080%22%2C%22__mps%22%3A%20%7B%7D%2C%22__mpso%22%3A%20%7B%7D%2C%22__mpa%22%3A%20%7B%7D%2C%22__mpu%22%3A%20%7B%7D%2C%22__mpap%22%3A%20%5B%5D%7D"
|
210
|
+
env['HTTP_ACCEPT_LANGUAGE'] = 'ja,en-US;q=0.8,en;q=0.6'
|
211
|
+
env['QUERY_STRING'] = 'param=val&hey=you'
|
212
|
+
env['ORIGINAL_FULLPATH'] = '/dashboard?param=val&hey=you'
|
213
|
+
#env['HTTP_REFERER'] =
|
214
|
+
env['REQUEST_PATH'] = '/dashboard'
|
215
|
+
env['PATH_INFO'] = '/dashboard'
|
216
|
+
|
217
|
+
if options['url']
|
218
|
+
url = URI.parse(options['url'])
|
219
|
+
env['rack.url_scheme'] = url.scheme
|
220
|
+
env['HTTP_HOST'] = url.host
|
221
|
+
if (url.scheme == 'http' && url.port != 80) || (url.scheme == 'https' && url.port != 443)
|
222
|
+
env['HTTP_HOST'] += ":#{url.port}"
|
223
|
+
end
|
224
|
+
env['SERVER_NAME'] = url.host
|
225
|
+
env['REQUEST_URI'] = url.request_uri
|
226
|
+
env['ORIGINAL_FULLPATH'] = url.request_uri
|
227
|
+
env['QUERY_STRING'] = url.query
|
228
|
+
env['REQUEST_PATH'] = url.path
|
229
|
+
env['PATH_INFO'] = url.path
|
230
|
+
end
|
231
|
+
return env.merge(options)
|
232
|
+
end
|
233
|
+
end
|