Sha256: 610899fa91fd4abf10367bb5cdeaf1b33a4c4eef664384a729f4486e9bcb236b

Contents?: true

Size: 1.93 KB

Versions: 8

Compression:

Stored size: 1.93 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe 'i18n fallbacks' do
  with_i18n_fallbacks

  context 'when fallbacks are enabled with a locale list' do
    before do
      I18n.default_locale = :en
      I18n.fallbacks[:de] = [ :en ]
    end

    context 'when translation is present in active locale' do
      it 'uses active locale' do
        product = Product.new
        I18n.locale = :de
        product.description = "Marvelous in German"
        I18n.locale = :en
        product.description = "Marvelous!"
        I18n.locale = :de
        product.description.should == 'Marvelous in German'
      end
    end

    context 'when translation is missing in active locale and present in fallback locale' do
      it 'falls back on default locale' do
        product = Product.new
        I18n.locale = :en
        product.description = "Marvelous!"
        I18n.locale = :de
        product.description.should == 'Marvelous!'
      end
    end

    context 'when translation is missing in all locales' do

      context 'i18n >= 1.1' do

        before(:all) do
          unless Gem::Version.new(I18n::VERSION) >= Gem::Version.new('1.1')
            skip "Test requires i18n >= 1.1, we have #{I18n::VERSION}"
          end
        end

        it 'returns nil' do
          product = Product.new
          I18n.locale = :en
          product.description = "Marvelous!"
          I18n.locale = :ru
          product.description.should be nil
        end
      end

      context 'i18n 1.0' do

        before(:all) do
          unless Gem::Version.new(I18n::VERSION) < Gem::Version.new('1.1')
            skip "Test requires i18n < 1.1, we have #{I18n::VERSION}"
          end
        end

        it 'falls back on default locale' do
          product = Product.new
          I18n.locale = :en
          product.description = "Marvelous!"
          I18n.locale = :ru
          product.description.should == 'Marvelous!'
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mongoid-8.0.10 spec/integration/i18n_fallbacks_spec.rb
mongoid-8.0.9 spec/integration/i18n_fallbacks_spec.rb
mongoid-8.0.8 spec/integration/i18n_fallbacks_spec.rb
mongoid-8.0.7 spec/integration/i18n_fallbacks_spec.rb
mongoid-8.0.6 spec/integration/i18n_fallbacks_spec.rb
mongoid-8.0.5 spec/integration/i18n_fallbacks_spec.rb
mongoid-8.0.4 spec/integration/i18n_fallbacks_spec.rb
mongoid-8.0.3 spec/integration/i18n_fallbacks_spec.rb