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
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/i18n-0.6.4/test/api/override_test.rb
tnargav-1.2.3 vendor/bundle/ruby/1.9.1/gems/i18n-0.6.4/test/api/override_test.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/i18n-0.6.4/test/api/override_test.rb
swipe-rails-0.0.5 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
active_mailer-0.0.9 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.8 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.7 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.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/i18n-0.6.4/test/api/override_test.rb
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
font-awesome-rails-3.1.1.2 vendor/ruby/2.0.0/gems/i18n-0.6.4/test/api/override_test.rb
vagrant-shell-0.2.6 vendor/bundle/gems/i18n-0.6.4/test/api/override_test.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
font-awesome-rails-3.1.1.1 vendor/ruby/2.0.0/gems/i18n-0.6.4/test/api/override_test.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/i18n-0.6.4/test/api/override_test.rb
challah-1.0.0.beta3 vendor/bundle/gems/i18n-0.6.1/test/api/override_test.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb
vagrant-shell-0.2.5 vendor/bundle/gems/i18n-0.6.4/test/api/override_test.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/i18n-0.6.1/test/api/override_test.rb