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
challah-1.0.0.beta2 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
challah-1.0.0.beta vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
vagrant-actionio-0.0.9 vendor/bundle/gems/i18n-0.6.4/test/api/override_test.rb
i18n-0.6.4 test/api/override_test.rb
i18n-0.6.3 test/api/override_test.rb
i18n-0.6.2 test/api/override_test.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
graphael-on-rails-0.5.1 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
graphael-on-rails-0.0.1 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
challah-0.9.1.beta.3 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
devise_sociable-0.1.0 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
backbone-queryparams-rails-0.0.1 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
railscast-assets-0.0.2 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
railscast-assets-0.0.2 vendor/bundle/gems/backbone-forms-on-rails-0.10.0/vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
backbone-forms-on-rails-0.10.0 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb