Sha256: 53416d29d9b48cafe1fa5b5757062d6cb2d6455a0d5d71586d1b46de1b7661b6

Contents?: true

Size: 1.21 KB

Versions: 9

Compression:

Stored size: 1.21 KB

Contents

require 'test_helper'

class I18nOverrideTest < I18n::TestCase
  module OverrideInverse
    def translate(*args)
      super(*args).reverse
    end
    alias :t :translate
  end

  module OverrideSignature
    def translate(*args)
      args.first + args[1]
    end
    alias :t :translate
  end

  def setup
    @I18n = I18n.dup
    @I18n.backend = I18n::Backend::Simple.new
    super
  end

  test "make sure modules can overwrite I18n methods" do
    @I18n.extend OverrideInverse
    @I18n.backend.store_translations('en', :foo => 'bar')

    assert_equal 'rab', @I18n.translate(:foo, :locale => 'en')
    # FIXME: this fails under 1.8.7
    # assert_equal 'rab', @I18n.t(:foo, :locale => 'en')
    assert_equal 'rab', @I18n.translate!(:foo, :locale => 'en')
    assert_equal 'rab', @I18n.t!(:foo, :locale => 'en')
  end

  test "make sure modules can overwrite I18n signature" do
    exception = catch(:exception) do
      @I18n.t('Hello', 'Welcome message on home page', :tokenize => true, :throw => true)
    end
    assert exception.message
    @I18n.extend OverrideSignature
    assert_equal 'HelloWelcome message on home page', @I18n.translate('Hello', 'Welcome message on home page', :tokenize => true) # tr8n example
  end
end

Version data entries

9 entries across 4 versions & 4 rubygems

Version Path
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/i18n-0.6.11/test/api/override_test.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/i18n-0.6.11/test/api/override_test.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/i18n-0.6.11/test/api/override_test.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/i18n-0.6.11/test/api/override_test.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/i18n-0.6.11/test/api/override_test.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/i18n-0.6.11/test/api/override_test.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/i18n-0.6.11/test/api/override_test.rb
nanumfont-rails-0.1 vendor/bundle/ruby/2.1.0/gems/i18n-0.6.11/test/api/override_test.rb
i18n-0.6.11 test/api/override_test.rb