aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/initializers/i18n_test.rb
blob: 99b2d860138800b77ea23f404908e05f08a10ea8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require "isolation/abstract_unit"

module ApplicationTests
  class I18nTest < Test::Unit::TestCase
    include ActiveSupport::Testing::Isolation

    def setup
      build_app
      boot_rails
      FileUtils.rm_rf "#{app_path}/config/environments"
    end

    # i18n
    test "setting another default locale" do
      add_to_config <<-RUBY
        config.root = "#{app_path}"
        config.i18n.default_locale = :de
      RUBY
      require "#{app_path}/config/environment"

      assert_equal :de, I18n.default_locale
    end

    test "no config locales dir present should return empty load path" do
      FileUtils.rm_rf "#{app_path}/config/locales"
      add_to_config <<-RUBY
        config.root = "#{app_path}"
      RUBY
      require "#{app_path}/config/environment"

      assert_equal [], Rails.application.config.i18n.load_path
    end

    test "config locales dir present should be added to load path" do
      add_to_config <<-RUBY
        config.root = "#{app_path}"
      RUBY

      require "#{app_path}/config/environment"
      assert_equal ["#{app_path}/config/locales/en.yml"],  Rails.application.config.i18n.load_path
    end

    test "config defaults should be added with config settings" do
      add_to_config <<-RUBY
        config.root = "#{app_path}"
        config.i18n.load_path << "my/other/locale.yml"
      RUBY
      require "#{app_path}/config/environment"

      assert_equal [
        "#{app_path}/config/locales/en.yml", "my/other/locale.yml"
      ], Rails.application.config.i18n.load_path
    end
  end
end