Sha256: d96cc154678b88d6c61d84a5ddcd558f594594dad8504bd71135ba1b6d0ff739

Contents?: true

Size: 1.92 KB

Versions: 91

Compression:

Stored size: 1.92 KB

Contents

# encoding: utf-8

module I18n
  module Tests
    module Defaults
      def setup
        super
        I18n.backend.store_translations(:en, :foo => { :bar => 'bar', :baz => 'baz' })
      end

      test "defaults: given nil as a key it returns the given default" do
        assert_equal 'default', I18n.t(nil, :default => 'default')
      end

      test "defaults: given a symbol as a default it translates the symbol" do
        assert_equal 'bar', I18n.t(nil, :default => :'foo.bar')
      end

      test "defaults: given a symbol as a default and a scope it stays inside the scope when looking up the symbol" do
        assert_equal 'bar', I18n.t(:missing, :default => :bar, :scope => :foo)
      end

      test "defaults: given an array as a default it returns the first match" do
        assert_equal 'bar', I18n.t(:does_not_exist, :default => [:does_not_exist_2, :'foo.bar'])
      end

      test "defaults: given an array as a default with false it returns false" do
        assert_equal false, I18n.t(:does_not_exist, :default => [false])
      end

      test "defaults: given false it returns false" do
        assert_equal false, I18n.t(:does_not_exist, :default => false)
      end

      test "defaults: given nil it returns nil" do
        assert_nil I18n.t(:does_not_exist, :default => nil)
      end

      test "defaults: given an array of missing keys it raises a MissingTranslationData exception" do
        assert_raise I18n::MissingTranslationData do
          I18n.t(:does_not_exist, :default => [:does_not_exist_2, :does_not_exist_3], :raise => true)
        end
      end

      test "defaults: using a custom scope separator" do
        # data must have been stored using the custom separator when using the ActiveRecord backend
        I18n.backend.store_translations(:en, { :foo => { :bar => 'bar' } }, { :separator => '|' })
        assert_equal 'bar', I18n.t(nil, :default => :'foo|bar', :separator => '|')
      end
    end
  end
end

Version data entries

91 entries across 81 versions & 19 rubygems

Version Path
mumukit-content-type-1.12.1 vendor/bundle/ruby/2.7.0/gems/i18n-0.9.5/lib/i18n/tests/defaults.rb
mumukit-content-type-1.12.0 vendor/bundle/ruby/2.7.0/gems/i18n-0.9.5/lib/i18n/tests/defaults.rb
ric-0.14.2 vendor/bundle/ruby/2.7.0/gems/i18n-1.8.11/lib/i18n/tests/defaults.rb
ric-0.14.1 vendor/bundle/ruby/2.7.0/gems/i18n-1.8.11/lib/i18n/tests/defaults.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/i18n-1.8.11/lib/i18n/tests/defaults.rb
ric-0.14.0 vendor/bundle/ruby/2.7.0/gems/i18n-1.8.11/lib/i18n/tests/defaults.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/i18n-1.8.10/lib/i18n/tests/defaults.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/i18n-1.8.11/lib/i18n/tests/defaults.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/i18n-1.8.11/lib/i18n/tests/defaults.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/i18n-1.8.11/lib/i18n/tests/defaults.rb
i18n-1.8.11 lib/i18n/tests/defaults.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/i18n-1.8.10/lib/i18n/tests/defaults.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/i18n-1.8.10/lib/i18n/tests/defaults.rb
mumukit-content-type-1.11.1 vendor/bundle/ruby/2.6.0/gems/i18n-0.9.5/lib/i18n/tests/defaults.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/i18n-1.8.10/lib/i18n/tests/defaults.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/i18n-1.8.5/lib/i18n/tests/defaults.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/i18n-1.8.10/lib/i18n/tests/defaults.rb
i18n-1.8.10 lib/i18n/tests/defaults.rb
i18n-1.8.9 lib/i18n/tests/defaults.rb
i18n-1.8.8 lib/i18n/tests/defaults.rb