deepl-rb 3.9.0 → 3.10.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/.gitlab-ci.yml +70 -52
- data/.rubocop.yml +26 -0
- data/CHANGELOG.md +429 -18
- data/Gemfile +4 -0
- data/README.md +981 -223
- data/Rakefile +18 -5
- data/VERSION +1 -1
- data/deepl-rb.gemspec +6 -6
- data/lib/deepl/admin_client.rb +183 -0
- data/lib/deepl/api.rb +30 -6
- data/lib/deepl/app_info.rb +20 -0
- data/lib/deepl/client.rb +969 -0
- data/lib/deepl/configuration.rb +56 -10
- data/lib/deepl/constants/admin_usage_group_by.rb +13 -0
- data/lib/deepl/constants/custom_tag_usage_aggregate_by.rb +13 -0
- data/lib/deepl/constants/document_status_code.rb +17 -0
- data/lib/deepl/constants/language_include.rb +17 -0
- data/lib/deepl/constants/language_resource_name.rb +21 -0
- data/lib/deepl/constants/tag_handling_version.rb +14 -0
- data/lib/deepl/deprecation.rb +42 -0
- data/lib/deepl/document_api.rb +41 -22
- data/lib/deepl/exceptions/bad_request.rb +1 -3
- data/lib/deepl/exceptions/connection_error.rb +37 -0
- data/lib/deepl/exceptions/document_not_ready_error.rb +17 -0
- data/lib/deepl/exceptions/document_translation_error.rb +17 -1
- data/lib/deepl/exceptions/error.rb +13 -1
- data/lib/deepl/exceptions/not_found.rb +8 -3
- data/lib/deepl/exceptions/not_supported.rb +6 -0
- data/lib/deepl/exceptions/request_error.rb +19 -2
- data/lib/deepl/exceptions/server_error.rb +7 -1
- data/lib/deepl/exceptions/validation_error.rb +14 -0
- data/lib/deepl/requests/admin/base.rb +94 -0
- data/lib/deepl/requests/admin/create_developer_key.rb +38 -0
- data/lib/deepl/requests/admin/custom_tag_usage_analytics.rb +38 -0
- data/lib/deepl/requests/admin/list_developer_keys.rb +28 -0
- data/lib/deepl/requests/admin/update_developer_key.rb +35 -0
- data/lib/deepl/requests/admin/usage_analytics.rb +36 -0
- data/lib/deepl/requests/base.rb +229 -59
- data/lib/deepl/requests/correct.rb +57 -0
- data/lib/deepl/requests/document/download.rb +11 -3
- data/lib/deepl/requests/document/get_status.rb +2 -2
- data/lib/deepl/requests/document/upload.rb +43 -10
- data/lib/deepl/requests/glossary/create.rb +6 -2
- data/lib/deepl/requests/glossary/language_pairs.rb +20 -4
- data/lib/deepl/requests/language_resources.rb +41 -0
- data/lib/deepl/requests/languages.rb +28 -4
- data/lib/deepl/requests/languages_for_resource.rb +54 -0
- data/lib/deepl/requests/multilingual_glossary/create.rb +37 -0
- data/lib/deepl/requests/multilingual_glossary/destroy.rb +36 -0
- data/lib/deepl/requests/multilingual_glossary/destroy_dictionary.rb +51 -0
- data/lib/deepl/requests/multilingual_glossary/entries.rb +66 -0
- data/lib/deepl/requests/multilingual_glossary/find.rb +35 -0
- data/lib/deepl/requests/multilingual_glossary/helpers.rb +63 -0
- data/lib/deepl/requests/multilingual_glossary/list.rb +39 -0
- data/lib/deepl/requests/multilingual_glossary/replace_dictionary.rb +41 -0
- data/lib/deepl/requests/multilingual_glossary/update.rb +40 -0
- data/lib/deepl/requests/rephrase.rb +5 -9
- data/lib/deepl/requests/spoken_terms/create.rb +37 -0
- data/lib/deepl/requests/spoken_terms/destroy.rb +36 -0
- data/lib/deepl/requests/spoken_terms/destroy_term_list.rb +41 -0
- data/lib/deepl/requests/spoken_terms/entries.rb +46 -0
- data/lib/deepl/requests/spoken_terms/find.rb +35 -0
- data/lib/deepl/requests/spoken_terms/helpers.rb +67 -0
- data/lib/deepl/requests/spoken_terms/list.rb +35 -0
- data/lib/deepl/requests/spoken_terms/replace_term_list.rb +41 -0
- data/lib/deepl/requests/spoken_terms/update.rb +40 -0
- data/lib/deepl/requests/style_profile/base.rb +83 -0
- data/lib/deepl/requests/style_profile/create.rb +35 -0
- data/lib/deepl/requests/style_profile/destroy.rb +34 -0
- data/lib/deepl/requests/style_profile/find.rb +33 -0
- data/lib/deepl/requests/style_profile/list.rb +43 -0
- data/lib/deepl/requests/style_profile/update.rb +35 -0
- data/lib/deepl/requests/style_rule/create.rb +1 -1
- data/lib/deepl/requests/style_rule/create_custom_instruction.rb +4 -2
- data/lib/deepl/requests/style_rule/destroy.rb +4 -2
- data/lib/deepl/requests/style_rule/destroy_custom_instruction.rb +5 -3
- data/lib/deepl/requests/style_rule/find.rb +4 -2
- data/lib/deepl/requests/style_rule/find_custom_instruction.rb +5 -3
- data/lib/deepl/requests/style_rule/helpers.rb +35 -0
- data/lib/deepl/requests/style_rule/list.rb +1 -1
- data/lib/deepl/requests/style_rule/update.rb +4 -2
- data/lib/deepl/requests/style_rule/update_configured_rules.rb +4 -2
- data/lib/deepl/requests/style_rule/update_custom_instruction.rb +5 -3
- data/lib/deepl/requests/translate.rb +52 -20
- data/lib/deepl/requests/translation_memory/base.rb +1 -4
- data/lib/deepl/requests/translation_memory/create_export.rb +1 -1
- data/lib/deepl/requests/translation_memory/create_import.rb +1 -1
- data/lib/deepl/requests/translation_memory/destroy.rb +1 -1
- data/lib/deepl/requests/translation_memory/download_export.rb +4 -0
- data/lib/deepl/requests/translation_memory/find.rb +1 -1
- data/lib/deepl/requests/translation_memory/find_job.rb +1 -1
- data/lib/deepl/requests/translation_memory/list.rb +2 -1
- data/lib/deepl/requests/translation_memory/segments.rb +3 -2
- data/lib/deepl/requests/translation_memory/storage_base.rb +40 -8
- data/lib/deepl/requests/translation_memory/upload_file.rb +1 -1
- data/lib/deepl/requests/usage.rb +28 -1
- data/lib/deepl/requests/write_improvements.rb +35 -0
- data/lib/deepl/resources/admin_usage_report.rb +73 -0
- data/lib/deepl/resources/custom_tag_usage_report.rb +59 -0
- data/lib/deepl/resources/developer_key.rb +57 -0
- data/lib/deepl/resources/document_handle.rb +24 -25
- data/lib/deepl/resources/document_translation_status.rb +23 -4
- data/lib/deepl/resources/language.rb +10 -2
- data/lib/deepl/resources/language_resource.rb +57 -0
- data/lib/deepl/resources/language_support.rb +56 -0
- data/lib/deepl/resources/multilingual_glossary.rb +112 -0
- data/lib/deepl/resources/spoken_terms.rb +61 -0
- data/lib/deepl/resources/style_profile.rb +44 -0
- data/lib/deepl/resources/style_rule.rb +3 -0
- data/lib/deepl/resources/text.rb +18 -2
- data/lib/deepl/resources/translation_memory.rb +8 -2
- data/lib/deepl/resources/translation_memory_import.rb +1 -1
- data/lib/deepl/resources/translation_memory_job.rb +23 -3
- data/lib/deepl/resources/translation_memory_segments.rb +8 -6
- data/lib/deepl/resources/usage.rb +93 -4
- data/lib/deepl/style_rule_api.rb +11 -0
- data/lib/deepl/translation_memory_api.rb +104 -24
- data/lib/deepl/utils/client_builder.rb +54 -0
- data/lib/deepl/utils/document_poller.rb +70 -0
- data/lib/deepl/utils/exception_builder.rb +3 -2
- data/lib/deepl/utils/http_client_builder.rb +79 -0
- data/lib/deepl/utils/number_parser.rb +34 -0
- data/lib/deepl/utils/term_validator.rb +33 -0
- data/lib/deepl/utils/time_parser.rb +14 -0
- data/lib/deepl.rb +166 -41
- data/lib/http_client_options.rb +21 -1
- data/lib/version.rb +1 -1
- data/spec/fixtures.rb +33 -0
- data/spec/offline/admin_client_spec.rb +551 -0
- data/spec/offline/client_spec.rb +273 -0
- data/spec/{api → offline}/configuration_spec.rb +45 -3
- data/spec/{constants → offline}/constants_spec.rb +23 -1
- data/spec/offline/correct_text_spec.rb +50 -0
- data/spec/offline/deprecation_spec.rb +32 -0
- data/spec/offline/errors_spec.rb +92 -0
- data/spec/offline/glossaries_spec.rb +98 -0
- data/spec/offline/http_client_spec.rb +319 -0
- data/spec/offline/languages_spec.rb +155 -0
- data/spec/offline/module_methods_spec.rb +13 -0
- data/spec/offline/multilingual_glossaries_spec.rb +358 -0
- data/spec/offline/offline_helper.rb +71 -0
- data/spec/offline/rephrase_text_spec.rb +73 -0
- data/spec/offline/spoken_terms_spec.rb +215 -0
- data/spec/offline/style_profiles_spec.rb +266 -0
- data/spec/offline/style_rules_spec.rb +318 -0
- data/spec/offline/translate_document_spec.rb +606 -0
- data/spec/offline/translate_text_spec.rb +286 -0
- data/spec/offline/translation_memories_client_spec.rb +256 -0
- data/spec/offline/translation_memories_spec.rb +463 -0
- data/spec/offline/usage_spec.rb +151 -0
- data/spec/real_api/admin_client_spec.rb +77 -0
- data/spec/real_api/correct_text_spec.rb +20 -0
- data/spec/real_api/glossaries_spec.rb +28 -0
- data/spec/real_api/languages_spec.rb +27 -0
- data/spec/real_api/multilingual_glossaries_spec.rb +53 -0
- data/spec/real_api/proxy_spec.rb +41 -0
- data/spec/real_api/real_api_helper.rb +65 -0
- data/spec/real_api/rephrase_text_spec.rb +16 -0
- data/spec/real_api/spoken_terms_spec.rb +56 -0
- data/spec/real_api/style_profiles_spec.rb +46 -0
- data/spec/real_api/style_rules_spec.rb +46 -0
- data/spec/real_api/translate_document_spec.rb +18 -0
- data/spec/real_api/translate_text_spec.rb +16 -0
- data/spec/real_api/translation_memories_spec.rb +56 -0
- data/spec/real_api/usage_spec.rb +20 -0
- data/spec/spec_helper.rb +1 -50
- metadata +116 -76
- data/.circleci/config.yml +0 -27
- data/.github/workflows/add_issues_to_kanban.yml +0 -16
- data/spec/api/api_spec.rb +0 -20
- data/spec/api/deepl_spec.rb +0 -262
- data/spec/integration_tests/document_api_spec.rb +0 -211
- data/spec/integration_tests/document_error_paths_spec.rb +0 -33
- data/spec/integration_tests/glossary_api_spec.rb +0 -114
- data/spec/integration_tests/glossary_error_paths_spec.rb +0 -107
- data/spec/integration_tests/integration_test_utils.rb +0 -178
- data/spec/integration_tests/languages_api_spec.rb +0 -54
- data/spec/integration_tests/languages_error_paths_spec.rb +0 -25
- data/spec/integration_tests/rephrase_api_spec.rb +0 -90
- data/spec/integration_tests/rephrase_error_paths_spec.rb +0 -53
- data/spec/integration_tests/smoke_test_spec.rb +0 -24
- data/spec/integration_tests/style_rule_api_spec.rb +0 -117
- data/spec/integration_tests/style_rule_error_paths_spec.rb +0 -45
- data/spec/integration_tests/translate_api_spec.rb +0 -117
- data/spec/integration_tests/translate_error_paths_spec.rb +0 -48
- data/spec/integration_tests/translation_memory_api_spec.rb +0 -244
- data/spec/integration_tests/translation_memory_error_paths_spec.rb +0 -87
- data/spec/integration_tests/usage_api_spec.rb +0 -29
- data/spec/integration_tests/usage_error_paths_spec.rb +0 -18
- data/spec/requests/document/upload_spec.rb +0 -130
- data/spec/requests/extra_body_parameters_types_spec.rb +0 -82
- data/spec/requests/glossary/create_spec.rb +0 -44
- data/spec/requests/glossary/destroy_spec.rb +0 -27
- data/spec/requests/glossary/entries_spec.rb +0 -27
- data/spec/requests/glossary/find_spec.rb +0 -28
- data/spec/requests/glossary/language_pairs_spec.rb +0 -27
- data/spec/requests/glossary/list_spec.rb +0 -27
- data/spec/requests/languages_spec.rb +0 -27
- data/spec/requests/rephrase_spec.rb +0 -46
- data/spec/requests/style_rule/create_custom_instruction_spec.rb +0 -30
- data/spec/requests/style_rule/create_spec.rb +0 -29
- data/spec/requests/style_rule/destroy_custom_instruction_spec.rb +0 -28
- data/spec/requests/style_rule/destroy_spec.rb +0 -27
- data/spec/requests/style_rule/find_custom_instruction_spec.rb +0 -29
- data/spec/requests/style_rule/find_spec.rb +0 -28
- data/spec/requests/style_rule/list_spec.rb +0 -27
- data/spec/requests/style_rule/update_configured_rules_spec.rb +0 -31
- data/spec/requests/style_rule/update_custom_instruction_spec.rb +0 -32
- data/spec/requests/style_rule/update_spec.rb +0 -29
- data/spec/requests/translate_spec.rb +0 -338
- data/spec/requests/translation_memory/create_export_spec.rb +0 -37
- data/spec/requests/translation_memory/create_import_spec.rb +0 -61
- data/spec/requests/translation_memory/destroy_spec.rb +0 -36
- data/spec/requests/translation_memory/download_export_spec.rb +0 -54
- data/spec/requests/translation_memory/find_job_spec.rb +0 -37
- data/spec/requests/translation_memory/find_spec.rb +0 -36
- data/spec/requests/translation_memory/list_spec.rb +0 -27
- data/spec/requests/translation_memory/segments_spec.rb +0 -58
- data/spec/requests/translation_memory/upload_file_spec.rb +0 -55
- data/spec/requests/usage_spec.rb +0 -27
- data/spec/resources/custom_instruction_spec.rb +0 -32
- data/spec/resources/glossary_spec.rb +0 -38
- data/spec/resources/language_pair_spec.rb +0 -23
- data/spec/resources/language_spec.rb +0 -45
- data/spec/resources/style_rule_spec.rb +0 -68
- data/spec/resources/text_spec.rb +0 -23
- data/spec/resources/translation_memory_export_spec.rb +0 -38
- data/spec/resources/translation_memory_import_spec.rb +0 -30
- data/spec/resources/translation_memory_job_spec.rb +0 -109
- data/spec/resources/translation_memory_segments_spec.rb +0 -78
- data/spec/resources/translation_memory_spec.rb +0 -52
- data/spec/resources/usage_spec.rb +0 -35
- data/spec/support/live_mock_server.rb +0 -12
- data/spec/support/managed_glossary.rb +0 -65
- data/spec/support/managed_style_rule.rb +0 -17
- data/spec/support/managed_translation_memory.rb +0 -55
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
# Copyright 2018 Daniel Herzog
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::Translate do
|
|
9
|
-
subject(:translate) { described_class.new(api, text, source_lang, target_lang, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:tags_str) { 'p,strong,span' }
|
|
18
|
-
let(:tags_array) { %w[p strong span] }
|
|
19
|
-
|
|
20
|
-
let(:api) { build_deepl_api }
|
|
21
|
-
let(:text) { 'Sample text' }
|
|
22
|
-
let(:source_lang) { 'EN' }
|
|
23
|
-
let(:target_lang) { 'ES' }
|
|
24
|
-
let(:options) { {} }
|
|
25
|
-
|
|
26
|
-
describe '#initialize' do
|
|
27
|
-
context 'when building a request' do
|
|
28
|
-
it 'creates a request object' do
|
|
29
|
-
expect(translate).to be_a(described_class)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
context 'when using `splitting_tags` options' do
|
|
34
|
-
it 'works with a nil values' do
|
|
35
|
-
request = described_class.new(api, nil, nil, nil, splitting_tags: nil)
|
|
36
|
-
expect(request.options[:splitting_tags]).to be_nil
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it 'works with a blank list' do
|
|
40
|
-
request = described_class.new(api, nil, nil, nil, splitting_tags: '')
|
|
41
|
-
expect(request.options[:splitting_tags]).to eq([])
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
it 'works with a comma-separated list and converts strings to an array' do
|
|
45
|
-
request = described_class.new(api, nil, nil, nil, splitting_tags: tags_str)
|
|
46
|
-
expect(request.options[:splitting_tags]).to eq(tags_array)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'works with an array of tags and leaves it as is' do
|
|
50
|
-
request = described_class.new(api, nil, nil, nil, splitting_tags: tags_array)
|
|
51
|
-
expect(request.options[:splitting_tags]).to eq(tags_array)
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
context 'when using `non_splitting_tags` options' do
|
|
56
|
-
it 'works with a nil values' do
|
|
57
|
-
request = described_class.new(api, nil, nil, nil, non_splitting_tags: nil)
|
|
58
|
-
expect(request.options[:non_splitting_tags]).to be_nil
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it 'works with a blank list' do
|
|
62
|
-
request = described_class.new(api, nil, nil, nil, non_splitting_tags: '')
|
|
63
|
-
expect(request.options[:non_splitting_tags]).to eq([])
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it 'works with a comma-separated list and converts strings to an array' do
|
|
67
|
-
request = described_class.new(api, nil, nil, nil, non_splitting_tags: tags_str)
|
|
68
|
-
expect(request.options[:non_splitting_tags]).to eq(tags_array)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
it 'works with an array and leaves it as it is' do
|
|
72
|
-
request = described_class.new(api, nil, nil, nil, non_splitting_tags: tags_array)
|
|
73
|
-
expect(request.options[:non_splitting_tags]).to eq(tags_array)
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
context 'when using `ignore_tags` options' do
|
|
78
|
-
it 'works with a nil values' do
|
|
79
|
-
request = described_class.new(api, nil, nil, nil, ignore_tags: nil)
|
|
80
|
-
expect(request.options[:ignore_tags]).to be_nil
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'works with a blank list' do
|
|
84
|
-
request = described_class.new(api, nil, nil, nil, ignore_tags: '')
|
|
85
|
-
expect(request.options[:ignore_tags]).to eq([])
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it 'works with a comma-separated list and converts a string to an array' do
|
|
89
|
-
request = described_class.new(api, nil, nil, nil, ignore_tags: tags_str)
|
|
90
|
-
expect(request.options[:ignore_tags]).to eq(tags_array)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it 'works with an array and leaves it as it is' do
|
|
94
|
-
request = described_class.new(api, nil, nil, nil, ignore_tags: tags_array)
|
|
95
|
-
expect(request.options[:ignore_tags]).to eq(tags_array)
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
context 'when using `split_sentences` options' do
|
|
100
|
-
it 'converts `true` to `1`' do
|
|
101
|
-
request = described_class.new(api, nil, nil, nil, split_sentences: true)
|
|
102
|
-
expect(request.options[:split_sentences]).to eq('1')
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
it 'converts `false` to `0`' do
|
|
106
|
-
request = described_class.new(api, nil, nil, nil, split_sentences: false)
|
|
107
|
-
expect(request.options[:split_sentences]).to eq('0')
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it 'leaves `0` as is' do
|
|
111
|
-
request = described_class.new(api, nil, nil, nil, split_sentences: '0')
|
|
112
|
-
expect(request.options[:split_sentences]).to eq('0')
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it 'leaves `nonewlines` as is' do
|
|
116
|
-
request = described_class.new(api, nil, nil, nil, split_sentences: 'nonewlines')
|
|
117
|
-
expect(request.options[:split_sentences]).to eq('nonewlines')
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
it 'leaves `1` as is' do
|
|
121
|
-
request = described_class.new(api, nil, nil, nil, split_sentences: '1')
|
|
122
|
-
expect(request.options[:split_sentences]).to eq('1')
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it 'works with provided constants' do
|
|
126
|
-
request = described_class.new(
|
|
127
|
-
api,
|
|
128
|
-
nil,
|
|
129
|
-
nil,
|
|
130
|
-
nil,
|
|
131
|
-
split_sentences: DeepL::Constants::SplitSentences::SPLIT_ON_PUNCTUATION_AND_NEWLINES
|
|
132
|
-
)
|
|
133
|
-
expect(request.options[:split_sentences]).to eq('1')
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
context 'when using `preserve_formatting` options' do
|
|
138
|
-
it 'leaves `true` as is' do
|
|
139
|
-
request = described_class.new(api, nil, nil, nil, preserve_formatting: true)
|
|
140
|
-
expect(request.options[:preserve_formatting]).to be(true)
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
it 'leaves `false` as is' do
|
|
144
|
-
request = described_class.new(api, nil, nil, nil, preserve_formatting: false)
|
|
145
|
-
expect(request.options[:preserve_formatting]).to be(false)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
it 'converts `0` to `false`' do
|
|
149
|
-
request = described_class.new(api, nil, nil, nil, preserve_formatting: '0')
|
|
150
|
-
expect(request.options[:preserve_formatting]).to be(false)
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
it 'converts `1` to `true`' do
|
|
154
|
-
request = described_class.new(api, nil, nil, nil, preserve_formatting: '1')
|
|
155
|
-
expect(request.options[:preserve_formatting]).to be(true)
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
context 'when using `outline_detection` options' do
|
|
160
|
-
it 'leaves `true` as is' do
|
|
161
|
-
request = described_class.new(api, nil, nil, nil, outline_detection: true)
|
|
162
|
-
expect(request.options[:outline_detection]).to be(true)
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
it 'leaves `false` as is' do
|
|
166
|
-
request = described_class.new(api, nil, nil, nil, outline_detection: false)
|
|
167
|
-
expect(request.options[:outline_detection]).to be(false)
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
it 'converts `0` to `false`' do
|
|
171
|
-
request = described_class.new(api, nil, nil, nil, outline_detection: '0')
|
|
172
|
-
expect(request.options[:outline_detection]).to be(false)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it 'converts `1` to `true`' do
|
|
176
|
-
request = described_class.new(api, nil, nil, nil, outline_detection: '1')
|
|
177
|
-
expect(request.options[:outline_detection]).to be(true)
|
|
178
|
-
end
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
context 'when using `glossary_id` options' do
|
|
182
|
-
it 'works with a nil values' do
|
|
183
|
-
request = described_class.new(api, nil, nil, nil, glossary_id: nil)
|
|
184
|
-
expect(request.options[:glossary_id]).to be_nil
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
it 'works with a string' do
|
|
188
|
-
request = described_class.new(api, nil, nil, nil, glossary_id: 'sample_id')
|
|
189
|
-
expect(request.options[:glossary_id]).to eq('sample_id')
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
context 'when using `glossary_ids` options' do
|
|
194
|
-
it 'works with a nil value' do
|
|
195
|
-
request = described_class.new(api, nil, nil, nil, glossary_ids: nil)
|
|
196
|
-
expect(request.options[:glossary_ids]).to be_nil
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
it 'works with an array of strings' do
|
|
200
|
-
request = described_class.new(api, nil, nil, nil, glossary_ids: %w[id1 id2])
|
|
201
|
-
expect(request.options[:glossary_ids]).to eq(%w[id1 id2])
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
context 'when building the `glossary_ids` request parameter' do
|
|
206
|
-
def glossary_ids_param(source_lang, options)
|
|
207
|
-
described_class.new(api, text, source_lang, target_lang, options)
|
|
208
|
-
.send(:build_glossary_ids_param, source_lang)
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
it 'returns nil when `glossary_ids` is not provided' do
|
|
212
|
-
expect(glossary_ids_param('EN', {})).to be_nil
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
it 'returns nil when `glossary_ids` is nil' do
|
|
216
|
-
expect(glossary_ids_param('EN', { glossary_ids: nil })).to be_nil
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
it 'returns nil when `glossary_ids` is an empty array' do
|
|
220
|
-
expect(glossary_ids_param('EN', { glossary_ids: [] })).to be_nil
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
it 'resolves an array of IDs to an array of strings' do
|
|
224
|
-
expect(glossary_ids_param('EN', { glossary_ids: %w[id1 id2 id3] })).to eq(%w[id1 id2 id3])
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
it 'resolves glossary objects to their IDs' do
|
|
228
|
-
glossary = DeepL::Resources::Glossary.new({ 'glossary_id' => 'obj_id' }, nil, nil)
|
|
229
|
-
expect(glossary_ids_param('EN', { glossary_ids: [glossary, 'id2'] })).to eq(%w[obj_id id2])
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
it 'raises when `source_lang` is not set' do
|
|
233
|
-
expect { glossary_ids_param(nil, { glossary_ids: %w[id1] }) }
|
|
234
|
-
.to raise_error(ArgumentError, /requires `source_lang`/)
|
|
235
|
-
end
|
|
236
|
-
|
|
237
|
-
it 'raises when combined with the singular `glossary_id` option' do
|
|
238
|
-
expect { glossary_ids_param('EN', { glossary_id: 'single', glossary_ids: %w[id1] }) }
|
|
239
|
-
.to raise_error(ArgumentError, /cannot be used together with the `glossary_id`/)
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
it 'raises when more than 5 IDs are provided' do
|
|
243
|
-
expect { glossary_ids_param('EN', { glossary_ids: %w[id1 id2 id3 id4 id5 id6] }) }
|
|
244
|
-
.to raise_error(ArgumentError, /maximum of 5 glossary IDs/)
|
|
245
|
-
end
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
context 'when using `formality` options' do
|
|
249
|
-
it 'works with a nil values' do
|
|
250
|
-
request = described_class.new(api, nil, nil, nil, formality: nil)
|
|
251
|
-
expect(request.options[:formality]).to be_nil
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
it 'works with a string' do
|
|
255
|
-
request = described_class.new(api, nil, nil, nil, formality: 'more')
|
|
256
|
-
expect(request.options[:formality]).to eq('more')
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
it 'works with provided constants' do
|
|
260
|
-
request = described_class.new(api, nil, nil, nil,
|
|
261
|
-
formality: DeepL::Constants::Formality::MORE)
|
|
262
|
-
expect(request.options[:formality]).to eq('more')
|
|
263
|
-
end
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
context 'when using `tag_handling_version` options' do
|
|
267
|
-
it 'works with a nil value' do
|
|
268
|
-
request = described_class.new(api, nil, nil, nil, tag_handling_version: nil)
|
|
269
|
-
expect(request.options[:tag_handling_version]).to be_nil
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
it 'works with v1' do
|
|
273
|
-
request = described_class.new(api, nil, nil, nil, tag_handling_version: 'v1')
|
|
274
|
-
expect(request.options[:tag_handling_version]).to eq('v1')
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
it 'works with v2' do
|
|
278
|
-
request = described_class.new(api, nil, nil, nil, tag_handling_version: 'v2')
|
|
279
|
-
expect(request.options[:tag_handling_version]).to eq('v2')
|
|
280
|
-
end
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
context 'when using `model_type` options' do
|
|
284
|
-
it 'works with a nil value' do
|
|
285
|
-
request = described_class.new(api, nil, nil, nil, model_type: nil)
|
|
286
|
-
expect(request.options[:model_type]).to be_nil
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
it 'works with a string' do
|
|
290
|
-
request = described_class.new(api, nil, nil, nil, model_type: 'latency_optimized')
|
|
291
|
-
expect(request.options[:model_type]).to eq('latency_optimized')
|
|
292
|
-
end
|
|
293
|
-
|
|
294
|
-
it 'works with provided constants' do
|
|
295
|
-
request = described_class.new(api, nil, nil, nil,
|
|
296
|
-
model_type: DeepL::Constants::ModelType::LATENCY_OPTIMIZED)
|
|
297
|
-
expect(request.options[:model_type]).to eq('latency_optimized')
|
|
298
|
-
end
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
context 'when using `custom_instructions` options' do
|
|
302
|
-
it 'works with a nil value' do
|
|
303
|
-
request = described_class.new(api, nil, nil, nil, custom_instructions: nil)
|
|
304
|
-
expect(request.options[:custom_instructions]).to be_nil
|
|
305
|
-
end
|
|
306
|
-
|
|
307
|
-
it 'works with an array of strings' do
|
|
308
|
-
instructions = ['Use informal language', 'Be concise']
|
|
309
|
-
request = described_class.new(api, nil, nil, nil, custom_instructions: instructions)
|
|
310
|
-
expect(request.options[:custom_instructions]).to eq(instructions)
|
|
311
|
-
end
|
|
312
|
-
|
|
313
|
-
it 'works with a single string' do
|
|
314
|
-
request = described_class.new(api, nil, nil, nil, custom_instructions: ['Be concise'])
|
|
315
|
-
expect(request.options[:custom_instructions]).to eq(['Be concise'])
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
it 'works with a single string and converts it to an array' do
|
|
319
|
-
instructions = 'Use informal language,Be concise'
|
|
320
|
-
request = described_class.new(api, nil, nil, nil, custom_instructions: instructions)
|
|
321
|
-
expect(request.options[:custom_instructions]).to eq(['Use informal language', 'Be concise'])
|
|
322
|
-
end
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
context 'when passing additional headers' do
|
|
326
|
-
it 'merges the headers into the request headers' do
|
|
327
|
-
request = described_class.new(api, nil, nil, nil, {},
|
|
328
|
-
{ 'X-DeepL-Reporting-Tag' => 'my-tag' })
|
|
329
|
-
expect(request.send(:headers)).to include('X-DeepL-Reporting-Tag' => 'my-tag')
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
it 'defaults to no additional headers' do
|
|
333
|
-
request = described_class.new(api, nil, nil, nil)
|
|
334
|
-
expect(request.send(:headers).keys).to contain_exactly('Authorization', 'User-Agent')
|
|
335
|
-
end
|
|
336
|
-
end
|
|
337
|
-
end
|
|
338
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::CreateExport do
|
|
9
|
-
subject(:translation_memory_create_export) { described_class.new(api, id, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:id) { 'a74d88fb-ed2a-4943-a664-a4512398b994' }
|
|
19
|
-
let(:options) { {} }
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
context 'when building a request' do
|
|
23
|
-
it 'creates a request object' do
|
|
24
|
-
expect(translation_memory_create_export).to be_a(described_class)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '#to_s' do
|
|
30
|
-
context 'when building a request' do
|
|
31
|
-
it 'posts to the export endpoint below the v3 prefix' do
|
|
32
|
-
expect(translation_memory_create_export.to_s)
|
|
33
|
-
.to eq("POST /v3/translation_memories/#{id}/export")
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::CreateImport do
|
|
9
|
-
subject(:translation_memory_create_import) do
|
|
10
|
-
described_class.new(api, file_name, content_length, options)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
around do |tests|
|
|
14
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
15
|
-
tests.call
|
|
16
|
-
ENV.replace(tmp_env)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
let(:api) { build_deepl_api }
|
|
20
|
-
let(:file_name) { 'legal.tmx' }
|
|
21
|
-
let(:content_length) { 128 }
|
|
22
|
-
let(:options) { {} }
|
|
23
|
-
|
|
24
|
-
describe '#initialize' do
|
|
25
|
-
context 'when building a request' do
|
|
26
|
-
it 'creates a request object' do
|
|
27
|
-
expect(translation_memory_create_import).to be_a(described_class)
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe '#to_s' do
|
|
33
|
-
context 'when building a request' do
|
|
34
|
-
it 'posts to the import endpoint below the v3 prefix' do
|
|
35
|
-
expect(translation_memory_create_import.to_s)
|
|
36
|
-
.to eq('POST /v3/translation_memories/import')
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
describe '#details' do
|
|
42
|
-
context 'when only the required parameters are given' do
|
|
43
|
-
it 'declares the source file without the optional fields' do
|
|
44
|
-
expect(translation_memory_create_import.details).to include('legal.tmx', '128')
|
|
45
|
-
expect(translation_memory_create_import.details).not_to include('content_type')
|
|
46
|
-
expect(translation_memory_create_import.details).not_to include('parameters')
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
context 'when the optional parameters are given' do
|
|
51
|
-
let(:options) { { content_type: 'text/xml', display_name: 'Legal' } }
|
|
52
|
-
|
|
53
|
-
it 'declares the content type and the display name' do
|
|
54
|
-
expect(translation_memory_create_import.details)
|
|
55
|
-
.to include('content_type', 'text/xml')
|
|
56
|
-
expect(translation_memory_create_import.details)
|
|
57
|
-
.to include('parameters', 'display_name', 'Legal')
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::Destroy do
|
|
9
|
-
subject(:translation_memory_destroy) { described_class.new(api, id, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:id) { 'a74d88fb-ed2a-4943-a664-a4512398b994' }
|
|
19
|
-
let(:options) { {} }
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
context 'when building a request' do
|
|
23
|
-
it 'creates a request object' do
|
|
24
|
-
expect(translation_memory_destroy).to be_a(described_class)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '#to_s' do
|
|
30
|
-
context 'when building a request' do
|
|
31
|
-
it 'deletes the translation memory below the v3 prefix' do
|
|
32
|
-
expect(translation_memory_destroy.to_s).to eq("DELETE /v3/translation_memories/#{id}")
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::DownloadExport do
|
|
9
|
-
subject(:download_export) { described_class.new(api, download_url, output_path) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:download_url) { 'https://storage.example.com/download/tm?signature=abc' }
|
|
19
|
-
let(:output_path) { '/tmp/export.tmx' }
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
context 'when building a request' do
|
|
23
|
-
it 'creates a request object' do
|
|
24
|
-
expect(download_export).to be_a(described_class)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
context 'when no download URL is given' do
|
|
29
|
-
let(:download_url) { nil }
|
|
30
|
-
|
|
31
|
-
it 'raises an error' do
|
|
32
|
-
expect { download_export }.to raise_error(DeepL::Exceptions::Error, /must not be empty/)
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
describe '#to_s' do
|
|
38
|
-
context 'when building a request' do
|
|
39
|
-
it 'gets from the pre-signed storage URL' do
|
|
40
|
-
expect(download_export.to_s).to eq('GET /download/tm?signature=abc')
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
describe '#details' do
|
|
46
|
-
context 'when building a request' do
|
|
47
|
-
# The download URL points outside of the DeepL API, so the auth key must not be sent there.
|
|
48
|
-
it 'does not send the DeepL authorization header' do
|
|
49
|
-
expect(download_export.details).not_to include('Authorization')
|
|
50
|
-
expect(download_export.details).to include('User-Agent')
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::FindJob do
|
|
9
|
-
subject(:translation_memory_find_job) { described_class.new(api, job_id, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:job_id) { '5b1a0a52-1f3b-4b7f-9f6b-9d4d3f5b6c7d' }
|
|
19
|
-
let(:options) { {} }
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
context 'when building a request' do
|
|
23
|
-
it 'creates a request object' do
|
|
24
|
-
expect(translation_memory_find_job).to be_a(described_class)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '#to_s' do
|
|
30
|
-
context 'when building a request' do
|
|
31
|
-
it 'requests the job below the v3 prefix' do
|
|
32
|
-
expect(translation_memory_find_job.to_s)
|
|
33
|
-
.to eq("GET /v3/translation_memories/jobs/#{job_id}")
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::Find do
|
|
9
|
-
subject(:translation_memory_find) { described_class.new(api, id, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:id) { 'a74d88fb-ed2a-4943-a664-a4512398b994' }
|
|
19
|
-
let(:options) { {} }
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
context 'when building a request' do
|
|
23
|
-
it 'creates a request object' do
|
|
24
|
-
expect(translation_memory_find).to be_a(described_class)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '#to_s' do
|
|
30
|
-
context 'when building a request' do
|
|
31
|
-
it 'requests the translation memory below the v3 prefix' do
|
|
32
|
-
expect(translation_memory_find.to_s).to eq("GET /v3/translation_memories/#{id}")
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::List do
|
|
9
|
-
subject(:translation_memory_list) { described_class.new(api, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:options) { {} }
|
|
19
|
-
|
|
20
|
-
describe '#initialize' do
|
|
21
|
-
context 'when building a request' do
|
|
22
|
-
it 'creates a request object' do
|
|
23
|
-
expect(translation_memory_list).to be_a(described_class)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# Copyright 2026 DeepL SE (https://www.deepl.com)
|
|
2
|
-
# Use of this source code is governed by an MIT
|
|
3
|
-
# license that can be found in the LICENSE.md file.
|
|
4
|
-
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
require 'spec_helper'
|
|
7
|
-
|
|
8
|
-
describe DeepL::Requests::TranslationMemory::Segments do
|
|
9
|
-
subject(:translation_memory_segments) { described_class.new(api, id, options) }
|
|
10
|
-
|
|
11
|
-
around do |tests|
|
|
12
|
-
tmp_env = replace_env_preserving_deepl_vars_except_mock_server
|
|
13
|
-
tests.call
|
|
14
|
-
ENV.replace(tmp_env)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:api) { build_deepl_api }
|
|
18
|
-
let(:id) { 'a74d88fb-ed2a-4943-a664-a4512398b994' }
|
|
19
|
-
let(:options) { {} }
|
|
20
|
-
|
|
21
|
-
describe '#initialize' do
|
|
22
|
-
context 'when building a request' do
|
|
23
|
-
it 'creates a request object' do
|
|
24
|
-
expect(translation_memory_segments).to be_a(described_class)
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
describe '#to_s' do
|
|
30
|
-
context 'when no options are given' do
|
|
31
|
-
it 'requests the segments below the v3 prefix without a query string' do
|
|
32
|
-
expect(translation_memory_segments.to_s)
|
|
33
|
-
.to eq("GET /v3/translation_memories/#{id}/segments")
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'when the supported options are given' do
|
|
38
|
-
let(:options) { { page_size: 10, page_cursor: 'NQ', filter_case_sensitive: true } }
|
|
39
|
-
|
|
40
|
-
it 'adds the options to the query string' do
|
|
41
|
-
expect(translation_memory_segments.to_s)
|
|
42
|
-
.to eq("GET /v3/translation_memories/#{id}/segments" \
|
|
43
|
-
'?page_size=10&page_cursor=NQ&filter_case_sensitive=true')
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
context 'when the text filter contains characters that must be escaped' do
|
|
48
|
-
let(:options) { { filter_text: 'a b+c' } }
|
|
49
|
-
|
|
50
|
-
# A space must be percent-encoded in a URI query string; `+` only means a space in a form
|
|
51
|
-
# body, and a literal `+` has to survive as %2B.
|
|
52
|
-
it 'percent-encodes the spaces instead of writing them as a plus' do
|
|
53
|
-
expect(translation_memory_segments.to_s)
|
|
54
|
-
.to eq("GET /v3/translation_memories/#{id}/segments?filter_text=a%20b%2Bc")
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|