wovnrb 3.3.1 → 3.4.0
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/docker/rails/TestSite/Gemfile +1 -1
- data/docker/rails/TestSite/start.sh +0 -1
- data/docker/rails/TestSite/yarn.lock +3 -3
- data/lib/wovnrb/api_translator.rb +10 -9
- data/lib/wovnrb/version.rb +1 -1
- data/test/lib/api_translator_test.rb +18 -14
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '06193b75ac22b47169f8d766af6fefbd2313ab08d064bb375f5f0966c7545f8a'
|
|
4
|
+
data.tar.gz: 58dc13795166410b91a33a8de5c13ecbf44f2cc777c6b0696475ef1d938449b5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f696a3e0078b1c51eee646143b90cd9cbb20ddfa95406f652db770ba28b9c655e76d6e907736dd35919089bb27671af792f938ceb4da20de46ddddfa4d122f06
|
|
7
|
+
data.tar.gz: 4ef3a31120a8052f5ac5a0b8fe8e289b269cd5ec85640eb677e1792f202d1dfdf396787be38876442be8f10ca33987cb8a472e1b9fb4b611ea36b3e759a9d544
|
|
@@ -5129,9 +5129,9 @@ path-key@^2.0.0, path-key@^2.0.1:
|
|
|
5129
5129
|
integrity sha1-QRyttXTFoUDTpLGRDUDYDMn0C0A=
|
|
5130
5130
|
|
|
5131
5131
|
path-parse@^1.0.6:
|
|
5132
|
-
version "1.0.
|
|
5133
|
-
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.
|
|
5134
|
-
integrity sha512-
|
|
5132
|
+
version "1.0.7"
|
|
5133
|
+
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
|
|
5134
|
+
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
|
|
5135
5135
|
|
|
5136
5136
|
path-to-regexp@0.1.7:
|
|
5137
5137
|
version "0.1.7"
|
|
@@ -24,18 +24,19 @@ module Wovnrb
|
|
|
24
24
|
|
|
25
25
|
case response
|
|
26
26
|
when Net::HTTPSuccess
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
begin
|
|
28
|
+
raw_response_body = @store.dev_mode? ? response.body : Zlib::GzipReader.new(StringIO.new(response.body)).read
|
|
29
|
+
rescue Zlib::GzipFile::Error
|
|
30
|
+
raw_response_body = response.body
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
begin
|
|
34
|
+
JSON.parse(raw_response_body)['body'] || body
|
|
35
|
+
rescue JSON::JSONError
|
|
35
36
|
body
|
|
36
37
|
end
|
|
37
38
|
else
|
|
38
|
-
WovnLogger.error("Received \"#{response.message}\" from WOVNio translation API.")
|
|
39
|
+
WovnLogger.error("HTML-swapper call failed. Received \"#{response.message}\" from WOVNio translation API.")
|
|
39
40
|
body
|
|
40
41
|
end
|
|
41
42
|
end
|
data/lib/wovnrb/version.rb
CHANGED
|
@@ -10,20 +10,24 @@ module Wovnrb
|
|
|
10
10
|
|
|
11
11
|
def test_translate_falls_back_to_original_body_if_exception
|
|
12
12
|
Net::HTTP.any_instance.expects(:request).raises
|
|
13
|
-
assert_translation('test.html', 'test_translated.html', false, nil)
|
|
13
|
+
assert_translation('test.html', 'test_translated.html', false, response: nil)
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def test_translate_falls_back_to_original_body_if_api_error
|
|
17
|
-
assert_translation('test.html', 'test_translated.html', false, status_code: 500)
|
|
17
|
+
assert_translation('test.html', 'test_translated.html', false, response: { encoding: 'text/json', status_code: 500 })
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
def
|
|
21
|
-
assert_translation('test.html', 'test_translated.html',
|
|
20
|
+
def test_translate_continues_if_api_response_is_not_compressed
|
|
21
|
+
assert_translation('test.html', 'test_translated.html', true, response: { encoding: 'unknown', status: 200 }, compress_data: false)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def test_translate_continues_if_api_response_is_compressed
|
|
25
|
+
assert_translation('test.html', 'test_translated.html', true, response: { encoding: 'unknown', status: 200 })
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
def test_translate_accepts_uncompressed_response_from_api_in_dev_mode
|
|
25
29
|
Wovnrb::Store.instance.update_settings('wovn_dev_mode' => true)
|
|
26
|
-
assert_translation('test.html', 'test_translated.html', true, encoding: 'text/json')
|
|
30
|
+
assert_translation('test.html', 'test_translated.html', true, response: { encoding: 'text/json', status: 200 }, compress_data: false)
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
def test_translate_without_api_compression_sends_json
|
|
@@ -60,10 +64,10 @@ module Wovnrb
|
|
|
60
64
|
|
|
61
65
|
private
|
|
62
66
|
|
|
63
|
-
def assert_translation(original_html_fixture, translated_html_fixture, success_expected, response
|
|
67
|
+
def assert_translation(original_html_fixture, translated_html_fixture, success_expected, response: { encoding: 'gzip', status_code: 200 }, compress_data: true)
|
|
64
68
|
original_html = File.read("test/fixtures/html/#{original_html_fixture}")
|
|
65
69
|
translated_html = File.read("test/fixtures/html/#{translated_html_fixture}")
|
|
66
|
-
actual_translated_html = translate(original_html, translated_html, response)
|
|
70
|
+
actual_translated_html = translate(original_html, translated_html, response, compress_data: compress_data)
|
|
67
71
|
|
|
68
72
|
if success_expected
|
|
69
73
|
assert_equal(actual_translated_html, translated_html)
|
|
@@ -72,9 +76,9 @@ module Wovnrb
|
|
|
72
76
|
end
|
|
73
77
|
end
|
|
74
78
|
|
|
75
|
-
def translate(original_html, translated_html, response)
|
|
76
|
-
api_translator, store,
|
|
77
|
-
translation_request_stub = stub_translation_api_request(store,
|
|
79
|
+
def translate(original_html, translated_html, response, compress_data: true)
|
|
80
|
+
api_translator, store, _headers = create_sut
|
|
81
|
+
translation_request_stub = stub_translation_api_request(store, original_html, translated_html, response, compress_data: compress_data)
|
|
78
82
|
|
|
79
83
|
actual_translated_html = api_translator.translate(original_html)
|
|
80
84
|
assert_requested(translation_request_stub, times: 1) if translation_request_stub
|
|
@@ -101,7 +105,7 @@ module Wovnrb
|
|
|
101
105
|
[api_translator, store, headers]
|
|
102
106
|
end
|
|
103
107
|
|
|
104
|
-
def stub_translation_api_request(store,
|
|
108
|
+
def stub_translation_api_request(store, original_html, translated_html, response, compress_data: true)
|
|
105
109
|
if response
|
|
106
110
|
cache_key = generate_cache_key(store, original_html)
|
|
107
111
|
api_host = if store.dev_mode?
|
|
@@ -119,10 +123,10 @@ module Wovnrb
|
|
|
119
123
|
'User-Agent' => 'Ruby'
|
|
120
124
|
}
|
|
121
125
|
stub_response_json = "{\"body\":\"#{translated_html.gsub("\n", '\n')}\"}"
|
|
122
|
-
stub_response = if
|
|
123
|
-
stub_response_json
|
|
124
|
-
else
|
|
126
|
+
stub_response = if compress_data
|
|
125
127
|
compress(stub_response_json)
|
|
128
|
+
else
|
|
129
|
+
stub_response_json
|
|
126
130
|
end
|
|
127
131
|
response_headers = { 'Content-Encoding' => response[:encoding] || 'gzip' }
|
|
128
132
|
stub_request(:post, api_url)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wovnrb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wovn Technologies, Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2021-
|
|
11
|
+
date: 2021-11-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|