translation_test.rb 1021 字节
Newer Older
1 2 3 4 5
require 'abstract_unit'

# class TranslatingController < ActionController::Base
# end

6
class TranslationControllerTest < ActiveSupport::TestCase
7 8 9
  def setup
    @controller = ActionController::Base.new
  end
10

11
  def test_action_controller_base_responds_to_translate
12
    assert_respond_to @controller, :translate
13
  end
14

15
  def test_action_controller_base_responds_to_t
16
    assert_respond_to @controller, :t
17
  end
18

19
  def test_action_controller_base_responds_to_localize
20
    assert_respond_to @controller, :localize
21
  end
22

23
  def test_action_controller_base_responds_to_l
24
    assert_respond_to @controller, :l
25
  end
26 27 28 29 30 31 32 33 34 35 36 37 38

  def test_lazy_lookup
    expected = 'bar'
    @controller.stubs(:action_name => :index)
    I18n.stubs(:translate).with('action_controller.base.index.foo').returns(expected)
    assert_equal expected, @controller.t('.foo')
  end

  def test_default_translation
    key, expected = 'one.two' 'bar'
    I18n.stubs(:translate).with(key).returns(expected)
    assert_equal expected, @controller.t(key)
  end
39
end