diff options
author | Xavier Noria <fxn@hashref.com> | 2010-04-19 05:10:55 -0700 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-04-19 05:10:55 -0700 |
commit | 792910bb69078ff1d14a6384b50e51aba2aae2dd (patch) | |
tree | 705defb52d5ac6eb903e97334de718defc7ba4e3 /railties | |
parent | e00c72c9718e518eb99058781f6ee71fa46b38fe (diff) | |
parent | ad4615e97896428ca140411081442f1b5e7d6089 (diff) | |
download | rails-792910bb69078ff1d14a6384b50e51aba2aae2dd.tar.gz rails-792910bb69078ff1d14a6384b50e51aba2aae2dd.tar.bz2 rails-792910bb69078ff1d14a6384b50e51aba2aae2dd.zip |
Merge commit 'rails/master'
Diffstat (limited to 'railties')
3 files changed, 103 insertions, 0 deletions
diff --git a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt index f902120453..b9fb13b640 100644 --- a/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +++ b/railties/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt @@ -39,4 +39,8 @@ # Enable threaded mode # config.threadsafe! + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation can not be found) + config.i18n.fallbacks = true end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 762f84d579..6ea722e239 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -10,6 +10,19 @@ class MigrationGeneratorTest < Rails::Generators::TestCase assert_migration "db/migrate/#{migration}.rb", /class ChangeTitleBodyFromPosts < ActiveRecord::Migration/ end + def test_migrations_generated_simultaneously + migrations = ["change_title_body_from_posts", "change_email_from_comments"] + + first_migration_number, second_migration_number = migrations.collect do |migration| + run_generator [migration] + file_name = migration_file_name "db/migrate/#{migration}.rb" + + File.basename(file_name).split('_').first + end + + assert_not_equal first_migration_number, second_migration_number + end + def test_migration_with_class_name migration = "ChangeTitleBodyFromPosts" run_generator [migration] diff --git a/railties/test/railties/i18n_railtie_test.rb b/railties/test/railties/i18n_railtie_test.rb new file mode 100644 index 0000000000..51684aa838 --- /dev/null +++ b/railties/test/railties/i18n_railtie_test.rb @@ -0,0 +1,86 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class I18nRailtieTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + require "rails/all" + @old_path = I18n.load_path + end + + def teardown + I18n.load_path = @old_path || [] + I18n.backend = nil + end + + def load_app + require "#{app_path}/config/environment" + 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 + + test "config.i18n.load_path gets added to I18n.load_path" do + I18n.load_path = ['existing/path/to/locales'] + I18n::Railtie.config.i18n.load_path = ['new/path/to/locales'] + load_app + + assert I18n.load_path.include?('existing/path/to/locales') + assert I18n.load_path.include?('new/path/to/locales') + end + + test "not using config.i18n.fallbacks does not initialize I18n.fallbacks" do + I18n.backend = Class.new { include I18n::Backend::Base }.new # can't uninclude modules, so use a tmp backend class + 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_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 |