~cytrogen/masto-fe

b84bc2de5df8ea0d3e67c574ca9142efed39715e — Matt Jankowski 2 years ago 2e1c6e9
Replace i18n view spec with helper spec (#24966)

1 files changed, 22 insertions(+), 24 deletions(-)

R spec/{views/shared/_error_messages.html.haml_spec => locales/i18n_spec}.rb
R spec/views/shared/_error_messages.html.haml_spec.rb => spec/locales/i18n_spec.rb +22 -24
@@ 2,36 2,34 @@

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
describe 'I18n' do
  describe 'Pluralizing locale translations' do
    subject { I18n.t('generic.validation_errors', count: 1) }

    context 'with the `en` locale which has `one` and `other` plural values' do
      around do |example|
        I18n.with_locale(:en) do
          example.run
        end
      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
      it 'translates to `en` correctly and without error' do
        expect { subject }.to_not raise_error
        expect(subject).to match(/the error below/)
      end
    end

    it 'renders the view with one error' do
      render partial: 'shared/error_messages', locals: { object: status }
    context 'with the `my` locale which has only `other` plural value' do
      around do |example|
        I18n.with_locale(:my) do
          example.run
        end
      end

      expect(rendered).to match(/is invalid/)
      it 'translates to `my` correctly and without error' do
        expect { subject }.to_not raise_error
        expect(subject).to match(/1/)
      end
    end
  end
end