diff options
Diffstat (limited to 'spec/lib/gitlab/i18n')
-rw-r--r-- | spec/lib/gitlab/i18n/po_linter_spec.rb | 55 | ||||
-rw-r--r-- | spec/lib/gitlab/i18n/translation_entry_spec.rb | 112 |
2 files changed, 22 insertions, 145 deletions
diff --git a/spec/lib/gitlab/i18n/po_linter_spec.rb b/spec/lib/gitlab/i18n/po_linter_spec.rb index e04c0b49480..f2ee6bb72d9 100644 --- a/spec/lib/gitlab/i18n/po_linter_spec.rb +++ b/spec/lib/gitlab/i18n/po_linter_spec.rb @@ -6,7 +6,7 @@ require 'simple_po_parser' # Disabling this cop to allow for multi-language examples in comments # rubocop:disable Style/AsciiComments RSpec.describe Gitlab::I18n::PoLinter do - let(:linter) { described_class.new(po_path: po_path, html_todolist: {}) } + let(:linter) { described_class.new(po_path: po_path) } let(:po_path) { 'spec/fixtures/valid.po' } def fake_translation(msgid:, translation:, plural_id: nil, plurals: []) @@ -24,8 +24,7 @@ RSpec.describe Gitlab::I18n::PoLinter do Gitlab::I18n::TranslationEntry.new( entry_data: data, - nplurals: plurals.size + 1, - html_allowed: nil + nplurals: plurals.size + 1 ) end @@ -160,53 +159,6 @@ RSpec.describe Gitlab::I18n::PoLinter do ] end end - - context 'when an entry contains html on the todolist' do - subject(:linter) { described_class.new(po_path: po_path, html_todolist: todolist) } - - let(:po_path) { 'spec/fixtures/potential_html.po' } - let(:todolist) do - { - 'String with a legitimate < use' => { - 'plural_id' => 'String with lots of < > uses', - 'translations' => [ - 'Translated string with a legitimate < use', - 'Translated string with lots of < > uses' - ] - } - } - end - - it 'does not present an error' do - message_id = 'String with a legitimate < use' - - expect(errors[message_id]).to be_nil - end - end - - context 'when an entry on the html todolist has changed' do - subject(:linter) { described_class.new(po_path: po_path, html_todolist: todolist) } - - let(:po_path) { 'spec/fixtures/potential_html.po' } - let(:todolist) do - { - 'String with a legitimate < use' => { - 'plural_id' => 'String with lots of < > uses', - 'translations' => [ - 'Translated string with a different legitimate < use', - 'Translated string with lots of < > uses' - ] - } - } - end - - it 'presents an error for the changed component' do - message_id = 'String with a legitimate < use' - - expect(errors[message_id]) - .to include a_string_starting_with('translation contains < or >.') - end - end end describe '#parse_po' do @@ -276,8 +228,7 @@ RSpec.describe Gitlab::I18n::PoLinter do fake_entry = Gitlab::I18n::TranslationEntry.new( entry_data: { msgid: 'the singular', msgid_plural: 'the plural', 'msgstr[0]' => 'the singular' }, - nplurals: 2, - html_allowed: nil + nplurals: 2 ) errors = [] diff --git a/spec/lib/gitlab/i18n/translation_entry_spec.rb b/spec/lib/gitlab/i18n/translation_entry_spec.rb index 2c95b0b0124..f05346d07d3 100644 --- a/spec/lib/gitlab/i18n/translation_entry_spec.rb +++ b/spec/lib/gitlab/i18n/translation_entry_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry 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(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry.singular_translation).to eq('Bonjour monde') end @@ -18,7 +18,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do 'msgstr[0]' => 'Bonjour monde', 'msgstr[1]' => 'Bonjour mondes' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry.singular_translation).to eq('Bonjour monde') end @@ -27,7 +27,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#all_translations' do it 'returns all translations for singular translations' do data = { msgid: 'Hello world', msgstr: 'Bonjour monde' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry.all_translations).to eq(['Bonjour monde']) end @@ -39,7 +39,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do 'msgstr[0]' => 'Bonjour monde', 'msgstr[1]' => 'Bonjour mondes' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry.all_translations).to eq(['Bonjour monde', 'Bonjour mondes']) end @@ -52,7 +52,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do msgid_plural: 'Hello worlds', 'msgstr[0]' => 'Bonjour monde' } - entry = described_class.new(entry_data: data, nplurals: 1, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 1) expect(entry.plural_translations).to eq(['Bonjour monde']) end @@ -65,7 +65,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do 'msgstr[1]' => 'Bonjour mondes', 'msgstr[2]' => 'Bonjour tous les mondes' } - entry = described_class.new(entry_data: data, nplurals: 3, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 3) expect(entry.plural_translations).to eq(['Bonjour mondes', 'Bonjour tous les mondes']) end @@ -77,7 +77,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do msgid: 'hello world', msgstr: 'hello' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry).to have_singular_translation end @@ -89,7 +89,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do "msgstr[0]" => 'hello world', "msgstr[1]" => 'hello worlds' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry).to have_singular_translation end @@ -100,7 +100,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do msgid_plural: 'hello worlds', "msgstr[0]" => 'hello worlds' } - entry = described_class.new(entry_data: data, nplurals: 1, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 1) expect(entry).not_to have_singular_translation end @@ -109,7 +109,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#msgid_contains_newlines' do it 'is true when the msgid is an array' do data = { msgid: %w(hello world) } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry.msgid_has_multiple_lines?).to be_truthy end @@ -118,7 +118,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#plural_id_contains_newlines' do it 'is true when the msgid is an array' do data = { msgid_plural: %w(hello world) } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry.plural_id_has_multiple_lines?).to be_truthy end @@ -127,7 +127,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#translations_contain_newlines' do it 'is true when the msgid is an array' do data = { msgstr: %w(hello world) } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry.translations_have_multiple_lines?).to be_truthy end @@ -135,7 +135,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#contains_unescaped_chars' do let(:data) { { msgid: '' } } - let(:entry) { described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) } + let(:entry) { described_class.new(entry_data: data, nplurals: 2) } it 'is true when the msgid is an array' do string = '「100%確定」' @@ -177,7 +177,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#msgid_contains_unescaped_chars' do it 'is true when the msgid contains a `%`' do data = { msgid: '「100%確定」' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry).to receive(:contains_unescaped_chars?).and_call_original expect(entry.msgid_contains_unescaped_chars?).to be_truthy @@ -187,7 +187,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#plural_id_contains_unescaped_chars' do it 'is true when the plural msgid contains a `%`' do data = { msgid_plural: '「100%確定」' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry).to receive(:contains_unescaped_chars?).and_call_original expect(entry.plural_id_contains_unescaped_chars?).to be_truthy @@ -197,7 +197,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do describe '#translations_contain_unescaped_chars' do it 'is true when the translation contains a `%`' do data = { msgstr: '「100%確定」' } - entry = described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) + entry = described_class.new(entry_data: data, nplurals: 2) expect(entry).to receive(:contains_unescaped_chars?).and_call_original expect(entry.translations_contain_unescaped_chars?).to be_truthy @@ -205,7 +205,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do end describe '#msgid_contains_potential_html?' do - subject(:entry) { described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) } + subject(:entry) { described_class.new(entry_data: data, nplurals: 2) } context 'when there are no angle brackets in the msgid' do let(:data) { { msgid: 'String with no brackets' } } @@ -225,7 +225,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do end describe '#plural_id_contains_potential_html?' do - subject(:entry) { described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) } + subject(:entry) { described_class.new(entry_data: data, nplurals: 2) } context 'when there are no angle brackets in the plural_id' do let(:data) { { msgid_plural: 'String with no brackets' } } @@ -245,7 +245,7 @@ RSpec.describe Gitlab::I18n::TranslationEntry do end describe '#translations_contain_potential_html?' do - subject(:entry) { described_class.new(entry_data: data, nplurals: 2, html_allowed: nil) } + subject(:entry) { described_class.new(entry_data: data, nplurals: 2) } context 'when there are no angle brackets in the translations' do let(:data) { { msgstr: 'This string has no angle brackets' } } @@ -263,78 +263,4 @@ RSpec.describe Gitlab::I18n::TranslationEntry do end end end - - describe '#msgid_html_allowed?' do - subject(:entry) do - described_class.new(entry_data: { msgid: 'String with a <strong>' }, nplurals: 2, html_allowed: html_todo) - end - - context 'when the html in the string is in the todolist' do - let(:html_todo) { { 'plural_id' => nil, 'translations' => [] } } - - it 'returns true' do - expect(entry.msgid_html_allowed?).to be true - end - end - - context 'when the html in the string is not in the todolist' do - let(:html_todo) { nil } - - it 'returns false' do - expect(entry.msgid_html_allowed?).to be false - end - end - end - - describe '#plural_id_html_allowed?' do - subject(:entry) do - described_class.new(entry_data: { msgid_plural: 'String with many <strong>' }, nplurals: 2, html_allowed: html_todo) - end - - context 'when the html in the string is in the todolist' do - let(:html_todo) { { 'plural_id' => 'String with many <strong>', 'translations' => [] } } - - it 'returns true' do - expect(entry.plural_id_html_allowed?).to be true - end - end - - context 'when the html in the string is not in the todolist' do - let(:html_todo) { { 'plural_id' => 'String with some <strong>', 'translations' => [] } } - - it 'returns false' do - expect(entry.plural_id_html_allowed?).to be false - end - end - end - - describe '#translations_html_allowed?' do - subject(:entry) do - described_class.new(entry_data: { msgstr: 'String with a <strong>' }, nplurals: 2, html_allowed: html_todo) - end - - context 'when the html in the string is in the todolist' do - let(:html_todo) { { 'plural_id' => nil, 'translations' => ['String with a <strong>'] } } - - it 'returns true' do - expect(entry.translations_html_allowed?).to be true - end - end - - context 'when the html in the string is not in the todolist' do - let(:html_todo) { { 'plural_id' => nil, 'translations' => ['String with a different <strong>'] } } - - it 'returns false' do - expect(entry.translations_html_allowed?).to be false - end - end - - context 'when the todolist only has the msgid' do - let(:html_todo) { { 'plural_id' => nil, 'translations' => nil } } - - it 'returns false' do - expect(entry.translations_html_allowed?).to be false - end - end - end end |