diff options
author | Xavier Noria <fxn@hashref.com> | 2010-06-20 23:13:19 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-20 23:13:19 +0200 |
commit | 207fa59675cb624dde0e01c1d57597f752cdf095 (patch) | |
tree | 472d03af5bc3e2df1b759717f723ca914f2a77aa /railties/test/application/initializers | |
parent | 31cadc730a40281950a265ff6982dd76cc326828 (diff) | |
parent | 50d37a76064239a731f81a4ba68b80946c4dfae2 (diff) | |
download | rails-207fa59675cb624dde0e01c1d57597f752cdf095.tar.gz rails-207fa59675cb624dde0e01c1d57597f752cdf095.tar.bz2 rails-207fa59675cb624dde0e01c1d57597f752cdf095.zip |
Merge remote branch 'rails/master'
Conflicts:
actionpack/lib/abstract_controller/base.rb
Diffstat (limited to 'railties/test/application/initializers')
-rw-r--r-- | railties/test/application/initializers/i18n_test.rb | 133 | ||||
-rw-r--r-- | railties/test/application/initializers/load_path_test.rb | 2 |
2 files changed, 115 insertions, 20 deletions
diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb index 99b2d86013..a1fcba3310 100644 --- a/railties/test/application/initializers/i18n_test.rb +++ b/railties/test/application/initializers/i18n_test.rb @@ -8,48 +8,143 @@ module ApplicationTests build_app boot_rails FileUtils.rm_rf "#{app_path}/config/environments" + require "rails/all" end - # i18n + def load_app + require "#{app_path}/config/environment" + end + + def app + @app ||= Rails::Application + end + + def assert_fallbacks(fallbacks) + fallbacks.each do |locale, expected| + actual = I18n.fallbacks[locale] + assert_equal expected, actual, "expected fallbacks for #{locale.inspect} to be #{expected.inspect}, but were #{actual.inspect}" + end + end + + def assert_no_fallbacks + assert !I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks) + end + + # Locales 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" + load_app assert_equal :de, I18n.default_locale end + # Load paths 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" - + load_app assert_equal [], Rails.application.config.i18n.load_path end - test "config locales dir present should be added to load path" do + test "locale files should be added to the load path" do + app_file "config/another_locale.yml", "" + add_to_config <<-RUBY - config.root = "#{app_path}" + config.i18n.load_path << config.root.join("config/another_locale.yml").to_s RUBY - require "#{app_path}/config/environment" - assert_equal ["#{app_path}/config/locales/en.yml"], Rails.application.config.i18n.load_path + load_app + assert_equal [ + "#{app_path}/config/locales/en.yml", "#{app_path}/config/another_locale.yml" + ], Rails.application.config.i18n.load_path + + assert I18n.load_path.include?("#{app_path}/config/locales/en.yml") + assert I18n.load_path.include?("#{app_path}/config/another_locale.yml") end - test "config defaults should be added with config settings" do + test "locales are reloaded if they change between requests" do add_to_config <<-RUBY - config.root = "#{app_path}" - config.i18n.load_path << "my/other/locale.yml" + config.cache_classes = false RUBY - require "#{app_path}/config/environment" - assert_equal [ - "#{app_path}/config/locales/en.yml", "my/other/locale.yml" - ], Rails.application.config.i18n.load_path + app_file "config/locales/en.yml", <<-YAML +en: + foo: "1" + YAML + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do |map| + match '/i18n', :to => lambda { |env| [200, {}, [I18n.t(:foo)]] } + end + RUBY + + require 'rack/test' + extend Rack::Test::Methods + load_app + + get "/i18n" + assert_equal "1", last_response.body + + app_file "config/locales/en.yml", <<-YAML +en: + foo: "2" + YAML + + get "/i18n" + assert_equal "2", last_response.body + end + + # Fallbacks + test "not using config.i18n.fallbacks does not initialize I18n.fallbacks" do + I18n.backend = Class.new { include I18n::Backend::Base }.new + load_app + assert_no_fallbacks + end + + test "config.i18n.fallbacks = true initializes I18n.fallbacks with default settings" do + I18n::Railtie.config.i18n.fallbacks = true + load_app + assert I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks) + assert_fallbacks :de => [:de, :en] + end + + test "config.i18n.fallbacks = true initializes I18n.fallbacks with default settings even when backend changes" do + I18n::Railtie.config.i18n.fallbacks = true + I18n::Railtie.config.i18n.backend = Class.new { include I18n::Backend::Base }.new + load_app + assert I18n.backend.class.included_modules.include?(I18n::Backend::Fallbacks) + assert_fallbacks :de => [:de, :en] + end + + test "config.i18n.fallbacks.defaults = [:'en-US'] initializes fallbacks with en-US as a fallback default" do + I18n::Railtie.config.i18n.fallbacks.defaults = [:'en-US'] + load_app + assert_fallbacks :de => [:de, :'en-US', :en] + end + + test "config.i18n.fallbacks.map = { :ca => :'es-ES' } initializes fallbacks with a mapping ca => es-ES" do + I18n::Railtie.config.i18n.fallbacks.map = { :ca => :'es-ES' } + load_app + assert_fallbacks :ca => [:ca, :"es-ES", :es, :en] + end + + test "[shortcut] config.i18n.fallbacks = [:'en-US'] initializes fallbacks with en-US as a fallback default" do + I18n::Railtie.config.i18n.fallbacks = [:'en-US'] + load_app + assert_fallbacks :de => [:de, :'en-US', :en] + end + + test "[shortcut] config.i18n.fallbacks = [{ :ca => :'es-ES' }] initializes fallbacks with a mapping de-AT => de-DE" do + I18n::Railtie.config.i18n.fallbacks.map = { :ca => :'es-ES' } + load_app + assert_fallbacks :ca => [:ca, :"es-ES", :es, :en] + end + + test "[shortcut] config.i18n.fallbacks = [:'en-US', { :ca => :'es-ES' }] initializes fallbacks with the given arguments" do + I18n::Railtie.config.i18n.fallbacks = [:'en-US', { :ca => :'es-ES' }] + load_app + assert_fallbacks :ca => [:ca, :"es-ES", :es, :'en-US', :en] end end end
\ No newline at end of file diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb index d31915e129..714d62311d 100644 --- a/railties/test/application/initializers/load_path_test.rb +++ b/railties/test/application/initializers/load_path_test.rb @@ -19,7 +19,7 @@ module ApplicationTests assert $:.include?("#{app_path}/app/models") end - test "initializing an application adds lib path on inheritance hook" do + test "initializing an application allows to load code on lib path inside application class definitation" do app_file "lib/foo.rb", <<-RUBY module Foo; end RUBY |