releaf-i18n_database 2.0.0 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +6 -46
- data/spec/builders/translations/builder_common_spec.rb +0 -39
- data/spec/builders/translations/edit_builder_spec.rb +0 -93
- data/spec/builders/translations/index_builder_spec.rb +0 -96
- data/spec/builders/translations/table_builder_spec.rb +0 -68
- data/spec/controllers/i18n_backend/translations_controller_spec.rb +0 -148
- data/spec/features/translations_spec.rb +0 -426
- data/spec/fixtures/all_translations_exported.xlsx +0 -0
- data/spec/fixtures/invalid.xls +0 -3
- data/spec/fixtures/invalid.xlsx +0 -3
- data/spec/fixtures/time.formats.xlsx +0 -0
- data/spec/fixtures/translations_import.xlsx +0 -0
- data/spec/fixtures/unsupported_import_file.png +0 -0
- data/spec/lib/releaf/i18n_database/backend_spec.rb +0 -200
- data/spec/lib/releaf/i18n_database/configuration_spec.rb +0 -13
- data/spec/lib/releaf/i18n_database/humanize_missing_translations_spec.rb +0 -24
- data/spec/lib/releaf/i18n_database/parse_spreadsheet_translations_spec.rb +0 -150
- data/spec/lib/releaf/i18n_database/translations_store_spec.rb +0 -530
- data/spec/lib/releaf/i18n_database/translations_utilities_spec.rb +0 -175
- data/spec/models/i18n_database/i18n_entry_spec.rb +0 -50
- data/spec/models/i18n_database/i18n_entry_translation_spec.rb +0 -9
@@ -1,426 +0,0 @@
|
|
1
|
-
require 'rails_helper'
|
2
|
-
feature "Translations" do
|
3
|
-
background(create_translations: true) do
|
4
|
-
auth_as_user
|
5
|
-
|
6
|
-
translation_1 = Releaf::I18nDatabase::I18nEntry.create(key: 'test.key1')
|
7
|
-
translation_2 = Releaf::I18nDatabase::I18nEntry.create(key: 'great.stuff')
|
8
|
-
translation_3 = Releaf::I18nDatabase::I18nEntry.create(key: 'geek.stuff')
|
9
|
-
translation_1.i18n_entry_translation.create(locale: 'en', text: 'testa atslēga')
|
10
|
-
translation_2.i18n_entry_translation.create(locale: 'en', text: 'awesome stuff')
|
11
|
-
translation_2.i18n_entry_translation.create(locale: 'lv', text: 'lieliska manta')
|
12
|
-
translation_3.i18n_entry_translation.create(locale: 'en', text: 'geek stuff')
|
13
|
-
translation_3.i18n_entry_translation.create(locale: 'lv', text: 'nūģu lieta')
|
14
|
-
end
|
15
|
-
|
16
|
-
scenario "blank only filtering", js: true, create_translations: true do
|
17
|
-
visit releaf_i18n_database_translations_path
|
18
|
-
expect(page).to have_number_of_resources(3)
|
19
|
-
|
20
|
-
check "Only blank"
|
21
|
-
expect(page).to have_number_of_resources(1)
|
22
|
-
|
23
|
-
click_link "Edit"
|
24
|
-
expect(page).to have_css(".table tbody.list tr", count: 1)
|
25
|
-
|
26
|
-
within ".table tr.item:first-child" do
|
27
|
-
fill_in "translations[][localizations][lv]", with: "lv tulkojums"
|
28
|
-
fill_in "translations[][localizations][en]", with: "en translation"
|
29
|
-
end
|
30
|
-
click_button "Save"
|
31
|
-
expect(page).to have_notification("Update succeeded")
|
32
|
-
|
33
|
-
# TODO: fix when phantomjs will have file download implemented
|
34
|
-
#click_link "Export"
|
35
|
-
#filename = page.response_headers["Content-Disposition"].split("=")[1].gsub("\"","")
|
36
|
-
#tmp_file = Dir.tmpdir + '/' + filename
|
37
|
-
#File.open(tmp_file, "wb") { |f| f.write(page.body) }
|
38
|
-
#fixture_path = File.expand_path('../fixtures/blank_translations_exported.xlsx', __dir__)
|
39
|
-
#expect(tmp_file).to match_excel(fixture_path)
|
40
|
-
#File.delete(tmp_file)
|
41
|
-
|
42
|
-
click_link "Back to list"
|
43
|
-
expect(page).to have_number_of_resources(0)
|
44
|
-
|
45
|
-
uncheck "Only blank"
|
46
|
-
expect(page).to have_number_of_resources(3)
|
47
|
-
end
|
48
|
-
|
49
|
-
scenario "index", create_translations: true do
|
50
|
-
visit releaf_i18n_database_translations_path
|
51
|
-
expect( page ).to have_content 'test.key1'
|
52
|
-
expect( page ).to have_content 'great.stuff'
|
53
|
-
expect( page ).to have_content 'geek.stuff'
|
54
|
-
|
55
|
-
expect( page ).to have_content 'testa atslēga'
|
56
|
-
expect( page ).to have_content 'awesome stuff'
|
57
|
-
expect( page ).to have_content 'lieliska manta'
|
58
|
-
expect( page ).to have_content 'geek stuff'
|
59
|
-
expect( page ).to have_content 'nūģu lieta'
|
60
|
-
end
|
61
|
-
|
62
|
-
scenario "Editing", js: true, create_translations: true do
|
63
|
-
visit releaf_i18n_database_translations_path
|
64
|
-
|
65
|
-
fill_in 'search', with: "stuff"
|
66
|
-
expect(page).to have_number_of_resources(2)
|
67
|
-
click_link "Edit"
|
68
|
-
|
69
|
-
within ".table tr.item:first-child" do
|
70
|
-
expect(find_field("translations[][key]").value).to eq("geek.stuff")
|
71
|
-
fill_in "translations[][key]", with: ""
|
72
|
-
fill_in "translations[][localizations][lv]", with: "lv tulkojums"
|
73
|
-
fill_in "translations[][localizations][en]", with: "en translation"
|
74
|
-
end
|
75
|
-
|
76
|
-
click_button "Save"
|
77
|
-
expect(page).to have_notification("Update failed", :error)
|
78
|
-
|
79
|
-
within ".table tr.item:last-child" do
|
80
|
-
click_button "Remove"
|
81
|
-
end
|
82
|
-
expect(page).to have_css(".table tr.item", count: 1) # wait for fade out to complete
|
83
|
-
|
84
|
-
within ".table tr.item:first-child" do
|
85
|
-
fill_in "translations[][key]", with: "great.stuff"
|
86
|
-
end
|
87
|
-
|
88
|
-
click_button "Save"
|
89
|
-
expect(page).to have_notification("Update succeeded")
|
90
|
-
|
91
|
-
# rename key
|
92
|
-
within ".table tr.item:first-child" do
|
93
|
-
fill_in "translations[][key]", with: "another.great.stuff"
|
94
|
-
end
|
95
|
-
click_button "Save"
|
96
|
-
expect(page).to have_notification("Update succeeded")
|
97
|
-
|
98
|
-
click_link "Back to list"
|
99
|
-
expect(page).to have_number_of_resources(1)
|
100
|
-
expect(page).to have_content 'lv tulkojums'
|
101
|
-
expect(page).to have_content 'en translation'
|
102
|
-
end
|
103
|
-
|
104
|
-
scenario "Do not save empty translations", create_translations: true do
|
105
|
-
visit releaf_i18n_database_translations_path
|
106
|
-
click_link "Edit"
|
107
|
-
click_button "Save"
|
108
|
-
|
109
|
-
expect(Releaf::I18nDatabase::I18nEntryTranslation.where(text: "").count).to eq(0)
|
110
|
-
end
|
111
|
-
|
112
|
-
scenario "Import excel file with translations", js: true, create_translations: true do
|
113
|
-
visit releaf_i18n_database_translations_path
|
114
|
-
expect(page).to have_no_css(".table td span", text: "Eksports")
|
115
|
-
expect(page).to have_no_css(".table td span", text: "Export")
|
116
|
-
expect(page).to have_no_css(".table td span", text: "jauns")
|
117
|
-
|
118
|
-
script = "$('form.import').css({display: 'block'});"
|
119
|
-
page.execute_script(script)
|
120
|
-
|
121
|
-
fixture_path = File.expand_path('../fixtures/translations_import.xlsx', __dir__)
|
122
|
-
|
123
|
-
within('form.import') do
|
124
|
-
attach_file(:import_file, fixture_path)
|
125
|
-
end
|
126
|
-
|
127
|
-
expect(page).to have_css(".breadcrumbs li:last-child", text: "Import")
|
128
|
-
find(:css, 'input[name="translations[][localizations][lv]"][value="Eksports"]')
|
129
|
-
find(:css, 'input[name="translations[][localizations][en]"][value="Export"]')
|
130
|
-
|
131
|
-
click_button "Import"
|
132
|
-
expect(page).to have_notification("successfuly imported 4 translations")
|
133
|
-
|
134
|
-
visit releaf_i18n_database_translations_path
|
135
|
-
expect(page).to have_css(".table td span", text: "Eksports")
|
136
|
-
expect(page).to have_css(".table td span", text: "Export")
|
137
|
-
expect(page).to have_css(".table td span", text: "jauns")
|
138
|
-
end
|
139
|
-
|
140
|
-
scenario "Import unsupported file", js: true, create_translations: true do
|
141
|
-
visit releaf_i18n_database_translations_path
|
142
|
-
|
143
|
-
script = "$('form.import').css({display: 'block'});"
|
144
|
-
page.execute_script(script)
|
145
|
-
|
146
|
-
fixture_path = File.expand_path('../fixtures/unsupported_import_file.png', __dir__)
|
147
|
-
|
148
|
-
within('form.import') do
|
149
|
-
attach_file(:import_file, fixture_path)
|
150
|
-
end
|
151
|
-
|
152
|
-
expect(page).to have_notification("Unsupported file format", "error")
|
153
|
-
end
|
154
|
-
|
155
|
-
scenario "Import corrupt xls file", js: true, create_translations: true do
|
156
|
-
visit releaf_i18n_database_translations_path
|
157
|
-
|
158
|
-
script = "$('form.import').css({display: 'block'});"
|
159
|
-
page.execute_script(script)
|
160
|
-
|
161
|
-
fixture_path = File.expand_path('../fixtures/invalid.xls', __dir__)
|
162
|
-
|
163
|
-
within('form.import') do
|
164
|
-
attach_file(:import_file, fixture_path)
|
165
|
-
end
|
166
|
-
|
167
|
-
expect(page).to have_notification("Unsupported file format", "error")
|
168
|
-
end
|
169
|
-
|
170
|
-
|
171
|
-
scenario "Import corrupt xlsx file", js: true, create_translations: true do
|
172
|
-
visit releaf_i18n_database_translations_path
|
173
|
-
|
174
|
-
script = "$('form.import').css({display: 'block'});"
|
175
|
-
page.execute_script(script)
|
176
|
-
|
177
|
-
fixture_path = File.expand_path('../fixtures/invalid.xlsx', __dir__)
|
178
|
-
|
179
|
-
within('form.import') do
|
180
|
-
attach_file(:import_file, fixture_path)
|
181
|
-
end
|
182
|
-
|
183
|
-
expect(page).to have_notification("Unsupported file format", "error")
|
184
|
-
end
|
185
|
-
|
186
|
-
|
187
|
-
scenario "Export translations", create_translations: true do
|
188
|
-
visit releaf_i18n_database_translations_path
|
189
|
-
click_link "Export"
|
190
|
-
|
191
|
-
expect(page.response_headers["Content-Type"]).to eq('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=utf-8')
|
192
|
-
|
193
|
-
filename = page.response_headers["Content-Disposition"].split("=")[1].gsub("\"","")
|
194
|
-
tmp_file = Dir.tmpdir + '/' + filename
|
195
|
-
File.open(tmp_file, "wb") { |f| f.write(page.body) }
|
196
|
-
|
197
|
-
fixture_path = File.expand_path('../fixtures/all_translations_exported.xlsx', __dir__)
|
198
|
-
expect(tmp_file).to match_excel(fixture_path)
|
199
|
-
|
200
|
-
File.delete(tmp_file)
|
201
|
-
end
|
202
|
-
|
203
|
-
describe "Lookup" do
|
204
|
-
background do
|
205
|
-
Releaf::I18nDatabase::Backend.reset_cache
|
206
|
-
allow( Releaf.application.config.i18n_database ).to receive(:translation_auto_creation).and_return(true)
|
207
|
-
end
|
208
|
-
|
209
|
-
context "when translation exists within higher level key (instead of being scope)" do
|
210
|
-
it "returns nil (Humanize key)" do
|
211
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "some.food")
|
212
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "suņi")
|
213
|
-
|
214
|
-
expect(I18n.t("some.food", locale: "lv")).to eq("suņi")
|
215
|
-
expect(I18n.t("some.food.asd", locale: "lv")).to eq("Asd")
|
216
|
-
end
|
217
|
-
end
|
218
|
-
|
219
|
-
context "when pluralized translation requested" do
|
220
|
-
context "when valid pluralized data matched" do
|
221
|
-
it "returns pluralized translation" do
|
222
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "dog.other")
|
223
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "suņi")
|
224
|
-
|
225
|
-
expect(I18n.t("dog", locale: "lv", count: 2)).to eq("suņi")
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
context "when invalid pluralized data matched" do
|
230
|
-
it "returns nil (Humanize key)" do
|
231
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "dog.food")
|
232
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "suņi")
|
233
|
-
|
234
|
-
expect(I18n.t("dog", locale: "lv", count: 2)).to eq("Dog")
|
235
|
-
end
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
context "when same translations with different cases exists" do
|
240
|
-
it "returns case sensitive translation" do
|
241
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "Save")
|
242
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Saglabāt")
|
243
|
-
|
244
|
-
expect(I18n.t("save", locale: "lv")).to eq("Save")
|
245
|
-
expect(I18n.t("Save", locale: "lv")).to eq("Saglabāt")
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
context "existing translation" do
|
250
|
-
context "when translations hash exists in parent scope" do
|
251
|
-
before do
|
252
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "dog.other")
|
253
|
-
translation.i18n_entry_translation.create(locale: "en", text: "dogs")
|
254
|
-
end
|
255
|
-
|
256
|
-
context "when pluralized translation requested" do
|
257
|
-
it "returns pluralized translation" do
|
258
|
-
expect(I18n.t("admin.controller.dog", count: 2)).to eq("dogs")
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
context "when non pluralized translation requested" do
|
263
|
-
it "returns nil" do
|
264
|
-
expect(I18n.t("admin.controller.dog")).to eq("Dog")
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
context "when ignorable pattern" do
|
270
|
-
it "does not auto create missing translation" do
|
271
|
-
expect{ I18n.t("attributes.title") }.to_not change{ Releaf::I18nDatabase::I18nEntry.count }
|
272
|
-
end
|
273
|
-
end
|
274
|
-
|
275
|
-
context "in parent scope" do
|
276
|
-
context "nonexistent translation in given scope" do
|
277
|
-
it "uses parent scope" do
|
278
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
279
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
280
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv")).to eq("Tukšs")
|
281
|
-
end
|
282
|
-
|
283
|
-
context "when `inherit_scopes` option is `false`" do
|
284
|
-
it "does not lookup upon higher level scopes" do
|
285
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
286
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
287
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv", inherit_scopes: false)).to eq("Blank")
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context "and empty translation value in given scope" do
|
293
|
-
it "uses parent scope" do
|
294
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.roles.blank")
|
295
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "")
|
296
|
-
|
297
|
-
parent_translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
298
|
-
parent_translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
299
|
-
|
300
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv")).to eq("Tukšs")
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
context "and existing translation value in given scope" do
|
305
|
-
it "uses given scope" do
|
306
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.roles.blank")
|
307
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Tukša vērtība")
|
308
|
-
|
309
|
-
parent_translation = Releaf::I18nDatabase::I18nEntry.create(key: "validation.admin.blank")
|
310
|
-
parent_translation.i18n_entry_translation.create(locale: "lv", text: "Tukšs")
|
311
|
-
|
312
|
-
expect(I18n.t("blank", scope: "validation.admin.roles", locale: "lv")).to eq("Tukša vērtība")
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
context "when scope defined" do
|
318
|
-
it "uses given scope" do
|
319
|
-
translation = Releaf::I18nDatabase::I18nEntry.create(key: "admin.content.cancel")
|
320
|
-
translation.i18n_entry_translation.create(locale: "lv", text: "Atlikt")
|
321
|
-
expect(I18n.t("cancel", scope: "admin.content", locale: "lv")).to eq("Atlikt")
|
322
|
-
end
|
323
|
-
end
|
324
|
-
end
|
325
|
-
|
326
|
-
context "nonexistent translation" do
|
327
|
-
context "loading multiple times" do
|
328
|
-
it "queries db only for the first time" do
|
329
|
-
I18n.t("save", scope: "admin.xx")
|
330
|
-
expect(Releaf::I18nDatabase::I18nEntry).not_to receive(:where)
|
331
|
-
I18n.t("save", scope: "admin.xx")
|
332
|
-
end
|
333
|
-
end
|
334
|
-
|
335
|
-
context "with nonexistent translation" do
|
336
|
-
before do
|
337
|
-
allow(Releaf.application.config).to receive(:all_locales).and_return(["ru", "lv"])
|
338
|
-
allow(I18n).to receive(:locale_available?).and_return(true)
|
339
|
-
end
|
340
|
-
|
341
|
-
it "creates empty translation" do
|
342
|
-
expect { I18n.t("save") }.to change { Releaf::I18nDatabase::I18nEntry.where(key: "save").count }.by(1)
|
343
|
-
end
|
344
|
-
|
345
|
-
context "when count option passed" do
|
346
|
-
context "when create_plurals option not passed" do
|
347
|
-
it "creates empty translation" do
|
348
|
-
expect { I18n.t("animals.horse", count: 1) }.to change { Releaf::I18nDatabase::I18nEntry.where(key: "animals.horse").count }.by(1)
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
context "when negative create_plurals option passed" do
|
353
|
-
it "creates empty translation" do
|
354
|
-
expect { I18n.t("animals.horse", create_plurals: false, count: 1) }.to change { Releaf::I18nDatabase::I18nEntry.where(key: "animals.horse").count }.by(1)
|
355
|
-
end
|
356
|
-
end
|
357
|
-
|
358
|
-
context "when positive create_plurals option passed" do
|
359
|
-
it "creates pluralized translations for all Releaf locales" do
|
360
|
-
result = ["animals.horse.one", "animals.horse.other", "animals.horse.zero"]
|
361
|
-
expect{ I18n.t("animals.horse", count: 1, create_plurals: true) }.to change{ Releaf::I18nDatabase::I18nEntry.pluck(:key).sort }.
|
362
|
-
from([]).to(result.sort)
|
363
|
-
end
|
364
|
-
end
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
context "when scope requested" do
|
370
|
-
it "returns all scope translations" do
|
371
|
-
translation_1 = Releaf::I18nDatabase::I18nEntry.create(key: "admin.content.cancel")
|
372
|
-
translation_1.i18n_entry_translation.create(locale: "lv", text: "Atlikt")
|
373
|
-
|
374
|
-
translation_2 = Releaf::I18nDatabase::I18nEntry.create(key: "admin.content.save")
|
375
|
-
translation_2.i18n_entry_translation.create(locale: "lv", text: "Saglabāt")
|
376
|
-
|
377
|
-
expect(I18n.t("admin.content", locale: "lv")).to eq(cancel: "Atlikt", save: "Saglabāt")
|
378
|
-
expect(I18n.t("admin.content", locale: "en")).to eq(cancel: nil, save: nil)
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
|
384
|
-
describe "pluralization" do
|
385
|
-
|
386
|
-
before do
|
387
|
-
locales = [:lv, :ru]
|
388
|
-
allow(I18n.config).to receive(:available_locales).and_return(locales)
|
389
|
-
allow(Releaf.application.config).to receive(:available_locales).and_return(locales)
|
390
|
-
allow(Releaf.application.config).to receive(:all_locales).and_return(locales)
|
391
|
-
|
392
|
-
I18n.reload!
|
393
|
-
|
394
|
-
[:few, :many, :one, :other, :zero].each do |rule|
|
395
|
-
translation = Releaf::I18nDatabase::I18nEntry.create!(key: "public.years.#{rule}")
|
396
|
-
locales.each do |locale|
|
397
|
-
translation.i18n_entry_translation.create!( locale: locale.to_s, text: "years #{locale} #{rule} XX" )
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
Releaf::I18nDatabase::Backend.reset_cache
|
402
|
-
end
|
403
|
-
|
404
|
-
after do
|
405
|
-
# force I18n reloading to restore the original state.
|
406
|
-
# for this to work, the stubs must be removed beforehand
|
407
|
-
allow(I18n.config).to receive(:available_locales).and_call_original
|
408
|
-
allow(Releaf.application.config).to receive(:available_locales).and_call_original
|
409
|
-
allow(Releaf.application.config).to receive(:all_locales).and_call_original
|
410
|
-
I18n.reload!
|
411
|
-
end
|
412
|
-
|
413
|
-
it "uses rails-i18n pluralization mechanism to detect correct pluralization keys" do
|
414
|
-
expect(I18n.t("years", scope: "public", count: 0, locale: :lv)).to eq 'years lv zero XX'
|
415
|
-
expect(I18n.t("years", scope: "public", count: 1, locale: :lv)).to eq 'years lv one XX'
|
416
|
-
expect(I18n.t("years", scope: "public", count: 3, locale: :lv)).to eq 'years lv other XX'
|
417
|
-
|
418
|
-
expect(I18n.t("years", scope: "public", count: 1, locale: :ru)).to eq 'years ru one XX'
|
419
|
-
expect(I18n.t("years", scope: "public", count: 3, locale: :ru)).to eq 'years ru few XX'
|
420
|
-
expect(I18n.t("years", scope: "public", count: 5, locale: :ru)).to eq 'years ru many XX'
|
421
|
-
end
|
422
|
-
|
423
|
-
end
|
424
|
-
|
425
|
-
|
426
|
-
end
|
Binary file
|
data/spec/fixtures/invalid.xls
DELETED
data/spec/fixtures/invalid.xlsx
DELETED
Binary file
|
Binary file
|
Binary file
|
@@ -1,200 +0,0 @@
|
|
1
|
-
require "rails_helper"
|
2
|
-
|
3
|
-
describe Releaf::I18nDatabase::Backend do
|
4
|
-
let(:translations_store){ Releaf::I18nDatabase::TranslationsStore.new }
|
5
|
-
|
6
|
-
describe ".configure_component" do
|
7
|
-
it "adds new `Releaf::I18nDatabase::Configuration` configuration with default config" do
|
8
|
-
stub_const("Releaf::I18nDatabase::Backend::DEFAULT_CONFIG", a: :b)
|
9
|
-
allow(Releaf::I18nDatabase::Configuration).to receive(:new)
|
10
|
-
.with(a: :b).and_return("_new")
|
11
|
-
expect(Releaf.application.config).to receive(:add_configuration).with("_new")
|
12
|
-
described_class.configure_component
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe ".reset_cache" do
|
17
|
-
it "reset translations cache to backend instance" do
|
18
|
-
subject.translations_cache = :x
|
19
|
-
allow(described_class).to receive(:backend_instance).and_return(subject)
|
20
|
-
expect{ described_class.reset_cache }.to change{ subject.translations_cache }.to(nil)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe ".backend_instance" do
|
25
|
-
context "when I18n backend has chained backends" do
|
26
|
-
it "returns Releaf::I18nDatabase::Backend instance" do
|
27
|
-
backends = I18n::Backend::Chain.new(subject, I18n::Backend::Simple.new)
|
28
|
-
allow(I18n).to receive(:backend).and_return(backends)
|
29
|
-
expect(described_class.backend_instance).to eq(subject)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "returns nil when chain hasn't Releaf::I18nDatabase::Backend instance" do
|
33
|
-
backends = I18n::Backend::Chain.new(I18n::Backend::Simple.new)
|
34
|
-
allow(I18n).to receive(:backend).and_return(backends)
|
35
|
-
expect(described_class.backend_instance).to be nil
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
context "when I18n backend has single backend and it is instance of Releaf::I18nDatabase::Backend" do
|
40
|
-
it "returns Releaf::I18nDatabase::Backend instance" do
|
41
|
-
allow(I18n).to receive(:backend).and_return(subject)
|
42
|
-
expect(described_class.backend_instance).to eq(subject)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
context "when I18n backend has single backend and it is not instance of Releaf::I18nDatabase::Backend" do
|
47
|
-
it "returns nil" do
|
48
|
-
allow(I18n).to receive(:backend).and_return(I18n::Backend::Simple.new)
|
49
|
-
expect(described_class.backend_instance).to be nil
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe ".initialize_component" do
|
55
|
-
it "adds itself as i18n backend as primary backend while keeping Rails default simple backend as secondary" do
|
56
|
-
allow(I18n).to receive(:backend).and_return(:current_backend)
|
57
|
-
allow(I18n::Backend::Chain).to receive(:new).with(:new_backend, :current_backend).and_return(:x)
|
58
|
-
allow(described_class).to receive(:new).and_return(:new_backend)
|
59
|
-
expect(I18n).to receive(:backend=).with(:x)
|
60
|
-
described_class.initialize_component
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe ".locales_pluralizations" do
|
65
|
-
it "returns array all pluralization forms for releaf locales" do
|
66
|
-
allow(Releaf.application.config).to receive(:all_locales).and_return([:de, :ru])
|
67
|
-
allow(I18n).to receive(:t).with(:'i18n.plural.keys', locale: :de).and_return([:one, :other])
|
68
|
-
allow(I18n).to receive(:t).with(:'i18n.plural.keys', locale: :ru).and_return([:one, :few, :many])
|
69
|
-
|
70
|
-
expect(described_class.locales_pluralizations).to eq([:one, :other, :few, :many, :zero])
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#translations" do
|
75
|
-
let(:another_translations_store){ Releaf::I18nDatabase::TranslationsStore.new }
|
76
|
-
|
77
|
-
context "when translations has been loaded and is not expired" do
|
78
|
-
it "returns assigned translations hash instance" do
|
79
|
-
subject.translations_cache = translations_store
|
80
|
-
allow(translations_store).to receive(:expired?).and_return(false)
|
81
|
-
expect(Releaf::I18nDatabase::TranslationsStore).to_not receive(:new)
|
82
|
-
expect(subject.translations).to eq(translations_store)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when translations has been loaded and is expired" do
|
87
|
-
it "initializes new `TranslationsStore`, cache and return it" do
|
88
|
-
subject.translations_cache = translations_store
|
89
|
-
allow(translations_store).to receive(:expired?).and_return(true)
|
90
|
-
expect(Releaf::I18nDatabase::TranslationsStore).to receive(:new).and_return(another_translations_store)
|
91
|
-
expect(subject.translations).to eq(another_translations_store)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "when translations has not been loaded" do
|
96
|
-
it "initializes new `TranslationsStore`, cache and return it" do
|
97
|
-
subject.translations_cache = nil
|
98
|
-
expect(Releaf::I18nDatabase::TranslationsStore).to receive(:new).and_return(another_translations_store)
|
99
|
-
expect(subject.translations).to eq(another_translations_store)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
describe "#store_translations" do
|
105
|
-
it "pass given translations to simple translation backend" do
|
106
|
-
simple_backend = I18n.backend.backends.last
|
107
|
-
expect(simple_backend).to receive(:store_translations).with(:lv, {a: "x"}, {c: "d"})
|
108
|
-
subject.store_translations(:lv, {a: "x"}, {c: "d"})
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
describe ".translations_updated_at" do
|
113
|
-
it "returns translations updated_at from cached settings" do
|
114
|
-
allow(Releaf::Settings).to receive(:[]).with(described_class::UPDATED_AT_KEY).and_return("x")
|
115
|
-
expect(described_class.translations_updated_at).to eq("x")
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
describe ".translations_updated_at=" do
|
120
|
-
it "stores translations updated_at to cached settings" do
|
121
|
-
expect(Releaf::Settings).to receive(:[]=).with(described_class::UPDATED_AT_KEY, "xx")
|
122
|
-
described_class.translations_updated_at = "xx"
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe "#lookup" do
|
127
|
-
before do
|
128
|
-
allow(subject).to receive(:translations).and_return(translations_store)
|
129
|
-
allow(subject).to receive(:normalize_flat_keys).with(:lv, "some.localization", "_scope_", ":")
|
130
|
-
.and_return("xx.s.loc")
|
131
|
-
end
|
132
|
-
|
133
|
-
it "flattens key before passing further" do
|
134
|
-
expect(translations_store).to receive(:missing?).with(:lv, "xx.s.loc")
|
135
|
-
expect(translations_store).to receive(:lookup).with(:lv, "xx.s.loc", separator: ":", a: "b")
|
136
|
-
expect(translations_store).to receive(:missing).with(:lv, "xx.s.loc", separator: ":", a: "b")
|
137
|
-
|
138
|
-
subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")
|
139
|
-
end
|
140
|
-
|
141
|
-
context "when translation is known as missing" do
|
142
|
-
it "does not make lookup in translation hash, does not mark it as missing and return nil" do
|
143
|
-
allow(translations_store).to receive(:missing?).with(:lv, "xx.s.loc").and_return(true)
|
144
|
-
expect(translations_store).to_not receive(:lookup)
|
145
|
-
expect(translations_store).to_not receive(:missing)
|
146
|
-
expect(subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")).to be nil
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context "when translation is not known as missing" do
|
151
|
-
before do
|
152
|
-
allow(translations_store).to receive(:missing?).with(:lv, "xx.s.loc").and_return(false)
|
153
|
-
end
|
154
|
-
|
155
|
-
context "when lookup result is not nil" do
|
156
|
-
before do
|
157
|
-
allow(translations_store).to receive(:lookup).with(:lv, "xx.s.loc", separator: ":", a: "b").and_return("x")
|
158
|
-
end
|
159
|
-
|
160
|
-
it "returns lookup result" do
|
161
|
-
expect(subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")).to eq("x")
|
162
|
-
end
|
163
|
-
|
164
|
-
it "does not mark translation as missing" do
|
165
|
-
expect(translations_store).to_not receive(:missing).with(:lv, "xx.s.loc", separator: ":", a: "b")
|
166
|
-
subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
context "when lookup result is nil" do
|
171
|
-
before do
|
172
|
-
allow(translations_store).to receive(:lookup).with(:lv, "xx.s.loc", separator: ":", a: "b").and_return(nil)
|
173
|
-
end
|
174
|
-
|
175
|
-
it "returns nil" do
|
176
|
-
expect(subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")).to be nil
|
177
|
-
end
|
178
|
-
|
179
|
-
it "marks translation as missing" do
|
180
|
-
expect(translations_store).to receive(:missing).with(:lv, "xx.s.loc", separator: ":", a: "b")
|
181
|
-
subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
context "when database doesn't exists" do
|
187
|
-
it "returns an empty array" do
|
188
|
-
allow(Releaf::I18nDatabase::I18nEntry).to receive(:pluck).and_raise(ActiveRecord::NoDatabaseError.new("xxx"))
|
189
|
-
expect(subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")).to be nil
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
context "when node table doesn't exist" do
|
194
|
-
it "returns an empty array" do
|
195
|
-
allow(Releaf::I18nDatabase::I18nEntry).to receive(:pluck).and_raise(ActiveRecord::StatementInvalid.new("xxx"))
|
196
|
-
expect(subject.lookup(:lv, "some.localization", "_scope_", separator: ":", a: "b")).to be nil
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|