Sha256: 5ccf041533f7c83e14657ff9194cc5392a955da3975ef0588a740fe5d23645a6

Contents?: true

Size: 1.22 KB

Versions: 141

Compression:

Stored size: 1.22 KB

Contents

require 'test_helper'

class I18nOverrideTest < Test::Unit::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

141 entries across 120 versions & 41 rubygems

Version Path
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-csharp-0.1.0 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-htmlentities-0.1.0 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-output-icinga-1.0.0 vendor/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-zabbix-0.1.2 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-zabbix-0.1.1 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-input-fifo-0.9.1 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-input-fifo-0.9.0 vendor/bundle/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
logstash-input-salesforce-3.0.0 vendor/jruby/1.9/gems/i18n-0.6.9/test/api/override_test.rb
ivanvc-logstash-input-s3-3.1.1.4 vendor/local/gems/i18n-0.6.9/test/api/override_test.rb
ivanvc-logstash-input-s3-3.1.1.3 vendor/local/gems/i18n-0.6.9/test/api/override_test.rb
ivanvc-logstash-input-s3-3.1.1.2 vendor/local/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-delta-1.1.0 vendor/bundle/jruby/2.2.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-delta-1.0.1 vendor/bundle/jruby/2.2.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-base64-1.0.4 vendor/bundle/jruby/2.2.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-base64-1.0.3 vendor/bundle/jruby/2.2.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-delta-1.0.0 vendor/bundle/jruby/2.2.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-base64-1.0.2 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-base64-1.0.1 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/api/override_test.rb
logstash-filter-base64-1.0.0 vendor/bundle/jruby/2.3.0/gems/i18n-0.6.9/test/api/override_test.rb