Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-08-25 12:23:48 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2017-08-31 22:13:01 +0300
commitcdaf1072daecd628a89f019b701bc0a2fa27c20e (patch)
tree827e95260bb018b40fdd2537321fc8c31c9ea035 /spec/lib/gitlab/i18n
parent0fa0ed7d854761c5f055e421464adb0ff3522411 (diff)
Move detailed information of an entry into a separate class
Diffstat (limited to 'spec/lib/gitlab/i18n')
-rw-r--r--spec/lib/gitlab/i18n/po_entry_spec.rb71
-rw-r--r--spec/lib/gitlab/i18n/po_linter_spec.rb10
2 files changed, 76 insertions, 5 deletions
diff --git a/spec/lib/gitlab/i18n/po_entry_spec.rb b/spec/lib/gitlab/i18n/po_entry_spec.rb
new file mode 100644
index 00000000000..0317caedbff
--- /dev/null
+++ b/spec/lib/gitlab/i18n/po_entry_spec.rb
@@ -0,0 +1,71 @@
+require 'spec_helper'
+
+describe Gitlab::I18n::PoEntry do
+ describe '#singular_translation' do
+ it 'returns the normal `msgstr` for translations without plural' do
+ data = { msgid: 'Hello world', msgstr: 'Bonjour monde' }
+ entry = described_class.new(data)
+
+ expect(entry.singular_translation).to eq('Bonjour monde')
+ end
+
+ it 'returns the first string for entries with plurals' do
+ data = {
+ msgid: 'Hello world',
+ msgid_plural: 'Hello worlds',
+ 'msgstr[0]' => 'Bonjour monde',
+ 'msgstr[1]' => 'Bonjour mondes'
+ }
+ entry = described_class.new(data)
+
+ expect(entry.singular_translation).to eq('Bonjour monde')
+ end
+ end
+
+ describe '#all_translations' do
+ it 'returns all translations for singular translations' do
+ data = { msgid: 'Hello world', msgstr: 'Bonjour monde' }
+ entry = described_class.new(data)
+
+ expect(entry.all_translations).to eq(['Bonjour monde'])
+ end
+
+ it 'returns all translations when including plural translations' do
+ data = {
+ msgid: 'Hello world',
+ msgid_plural: 'Hello worlds',
+ 'msgstr[0]' => 'Bonjour monde',
+ 'msgstr[1]' => 'Bonjour mondes'
+ }
+ entry = described_class.new(data)
+
+ expect(entry.all_translations).to eq(['Bonjour monde', 'Bonjour mondes'])
+ end
+ end
+
+ describe '#plural_translations' do
+ it 'returns all translations if there is only one plural' do
+ data = {
+ msgid: 'Hello world',
+ msgid_plural: 'Hello worlds',
+ 'msgstr[0]' => 'Bonjour monde'
+ }
+ entry = described_class.new(data)
+
+ expect(entry.plural_translations).to eq(['Bonjour monde'])
+ end
+
+ it 'returns all translations except for the first one if there are multiple' do
+ data = {
+ msgid: 'Hello world',
+ msgid_plural: 'Hello worlds',
+ 'msgstr[0]' => 'Bonjour monde',
+ 'msgstr[1]' => 'Bonjour mondes',
+ 'msgstr[2]' => 'Bonjour tous les mondes'
+ }
+ entry = described_class.new(data)
+
+ expect(entry.plural_translations).to eq(['Bonjour mondes', 'Bonjour tous les mondes'])
+ end
+ end
+end
diff --git a/spec/lib/gitlab/i18n/po_linter_spec.rb b/spec/lib/gitlab/i18n/po_linter_spec.rb
index a8e9e4377b6..2e155511076 100644
--- a/spec/lib/gitlab/i18n/po_linter_spec.rb
+++ b/spec/lib/gitlab/i18n/po_linter_spec.rb
@@ -127,13 +127,13 @@ describe Gitlab::I18n::PoLinter do
describe '#validate_entries' do
it 'skips entries without a `msgid`' do
- allow(linter).to receive(:entries) { [{ msgid: "" }] }
+ allow(linter).to receive(:entries) { [Gitlab::I18n::PoEntry.new({ msgid: "" })] }
expect(linter.validate_entries).to be_empty
end
it 'keeps track of errors for entries' do
- fake_invalid_entry = { msgid: "Hello %{world}", msgstr: "Bonjour %{monde}" }
+ fake_invalid_entry = Gitlab::I18n::PoEntry.new({ msgid: "Hello %{world}", msgstr: "Bonjour %{monde}" })
allow(linter).to receive(:entries) { [fake_invalid_entry] }
expect(linter).to receive(:validate_entry)
@@ -158,12 +158,12 @@ describe Gitlab::I18n::PoLinter do
describe '#validate_variables' do
it 'validates both signular and plural in a pluralized string' do
- pluralized_entry = {
+ pluralized_entry = Gitlab::I18n::PoEntry.new({
msgid: 'Hello %{world}',
msgid_plural: 'Hello all %{world}',
'msgstr[0]' => 'Bonjour %{world}',
'msgstr[1]' => 'Bonjour tous %{world}'
- }
+ })
expect(linter).to receive(:validate_variables_in_message)
.with([], 'Hello %{world}', 'Bonjour %{world}')
@@ -174,7 +174,7 @@ describe Gitlab::I18n::PoLinter do
end
it 'validates the message variables' do
- entry = { msgid: 'Hello', msgstr: 'Bonjour' }
+ entry = Gitlab::I18n::PoEntry.new({ msgid: 'Hello', msgstr: 'Bonjour' })
expect(linter).to receive(:validate_variables_in_message)
.with([], 'Hello', 'Bonjour')