~ubuntu-branches/ubuntu/vivid/ruby-i18n/vivid

« back to all changes in this revision

Viewing changes to test/api/override_test.rb

  • Committer: Package Import Robot
  • Author(s): Praveen Arimbrathodiyil
  • Date: 2013-06-03 19:20:31 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20130603192031-qk11as87x3cotd1n
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'test_helper'
 
2
 
 
3
class I18nOverrideTest < Test::Unit::TestCase
 
4
  module OverrideInverse
 
5
 
 
6
    def translate(*args)
 
7
      super(*args).reverse
 
8
    end
 
9
    alias :t :translate
 
10
 
 
11
  end
 
12
 
 
13
  module OverrideSignature
 
14
 
 
15
    def translate(*args)
 
16
      args.first + args[1]
 
17
    end
 
18
    alias :t :translate
 
19
 
 
20
  end
 
21
 
 
22
  def setup
 
23
    @I18n = I18n.dup
 
24
    @I18n.backend = I18n::Backend::Simple.new
 
25
    super
 
26
  end
 
27
 
 
28
  test "make sure modules can overwrite I18n methods" do
 
29
    @I18n.extend OverrideInverse
 
30
    @I18n.backend.store_translations('en', :foo => 'bar')
 
31
 
 
32
    assert_equal 'rab', @I18n.translate(:foo, :locale => 'en')
 
33
    # FIXME: this fails under 1.8.7
 
34
    # assert_equal 'rab', @I18n.t(:foo, :locale => 'en')
 
35
    assert_equal 'rab', @I18n.translate!(:foo, :locale => 'en')
 
36
    assert_equal 'rab', @I18n.t!(:foo, :locale => 'en')
 
37
  end
 
38
 
 
39
  test "make sure modules can overwrite I18n signature" do
 
40
    exception = catch(:exception) do
 
41
      @I18n.t('Hello', 'Welcome message on home page', :tokenize => true, :throw => true)
 
42
    end
 
43
    assert exception.message
 
44
    @I18n.extend OverrideSignature
 
45
    assert_equal 'HelloWelcome message on home page', @I18n.translate('Hello', 'Welcome message on home page', :tokenize => true) # tr8n example
 
46
  end
 
47
 
 
48
end