From 679aca46da56228a3219d1c6f0c942adcfb8fdb1 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Fri, 12 May 2023 12:53:30 -0400 Subject: [PATCH] I18n pluralization errors (#24963) --- Gemfile.lock | 2 +- .../shared/_error_messages.html.haml_spec.rb | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 spec/views/shared/_error_messages.html.haml_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 594713c00e..a062ec88b2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -329,7 +329,7 @@ GEM httplog (1.6.2) rack (>= 2.0) rainbow (>= 2.0.0) - i18n (1.12.0) + i18n (1.13.0) concurrent-ruby (~> 1.0) i18n-tasks (1.0.12) activesupport (>= 4.0.2) diff --git a/spec/views/shared/_error_messages.html.haml_spec.rb b/spec/views/shared/_error_messages.html.haml_spec.rb new file mode 100644 index 0000000000..e7631345f1 --- /dev/null +++ b/spec/views/shared/_error_messages.html.haml_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'rails_helper' + +describe 'shared/_error_messages.html.haml' do + let(:status) { Status.new } + + before { status.errors.add :base, :invalid } + + context 'with a locale that has `one` and `other` plural values' do + around do |example| + I18n.with_locale(:en) do + example.run + end + end + + it 'renders the view with one error' do + render partial: 'shared/error_messages', locals: { object: status } + + expect(rendered).to match(/is invalid/) + end + end + + context 'with a locale that has only `other` plural value' do + around do |example| + I18n.with_locale(:my) do + example.run + end + end + + it 'renders the view with one error' do + render partial: 'shared/error_messages', locals: { object: status } + + expect(rendered).to match(/is invalid/) + end + end +end