diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/initializable_test.rb | 26 | ||||
-rw-r--r-- | railties/test/application/initializer_test.rb | 33 | ||||
-rw-r--r-- | railties/test/application/load_test.rb | 4 | ||||
-rw-r--r-- | railties/test/initializer/initialize_i18n_test.rb | 51 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 18 | ||||
-rw-r--r-- | railties/test/isolation/abstract_unit.rb | 3 |
6 files changed, 114 insertions, 21 deletions
diff --git a/railties/test/application/initializable_test.rb b/railties/test/application/initializable_test.rb new file mode 100644 index 0000000000..38eaec63c0 --- /dev/null +++ b/railties/test/application/initializable_test.rb @@ -0,0 +1,26 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class InitializerTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + test "initializers only ever run once" do + class MyApp < Rails::Application + initializer :counter do + $counter += 1 + end + end + + $counter = 0 + MyApp.initializers[:counter].run + MyApp.initializers[:counter].run + + assert_equal 1, $counter + end + end +end
\ No newline at end of file diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb new file mode 100644 index 0000000000..9583e1606c --- /dev/null +++ b/railties/test/application/initializer_test.rb @@ -0,0 +1,33 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class InitializerTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + test "initializing an application initializes rails" do + class MyApp < Rails::Application ; end + + if RUBY_VERSION < '1.9' + $KCODE = '' + MyApp.new + assert_equal 'UTF8', $KCODE + else + Encoding.default_external = Encoding::US_ASCII + MyApp.new + assert_equal Encoding::UTF_8, Encoding.default_external + end + end + + test "initializing an application adds the application paths to the load path" do + class MyApp < Rails::Application ; end + + MyApp.new + assert $:.include?("#{app_path}/app/models") + end + end +end
\ No newline at end of file diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb index 305cd7f273..5c3d35fb16 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/load_test.rb @@ -40,14 +40,14 @@ module ApplicationTests test "Rails.application is available after config.ru has been racked up" do rackup - assert Rails.application.new.is_a?(Rails::Application) + assert Rails.application.new < Rails::Application end # Passenger still uses AC::Dispatcher, so we need to # keep it working for now test "deprecated ActionController::Dispatcher still works" do rackup - assert ActionController::Dispatcher.new.is_a?(Rails::Application) + assert ActionController::Dispatcher.new < Rails::Application end test "the config object is available on the application object" do diff --git a/railties/test/initializer/initialize_i18n_test.rb b/railties/test/initializer/initialize_i18n_test.rb new file mode 100644 index 0000000000..e909688817 --- /dev/null +++ b/railties/test/initializer/initialize_i18n_test.rb @@ -0,0 +1,51 @@ +require "isolation/abstract_unit" + +module InitializerTests + class InitializeI18nTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + # test_config_defaults_and_settings_should_be_added_to_i18n_defaults + test "i18n config defaults and settings should be added to i18n defaults" do + Rails::Initializer.run do |c| + c.i18n.load_path << "my/other/locale.yml" + end + + #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml + assert_equal %W( + #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/railties/tmp/app/config/locales/en.yml + my/other/locale.yml + ), I18n.load_path + end + + test "i18n finds locale files in engines" do + app_file "vendor/plugins/engine/init.rb", "" + app_file "vendor/plugins/engine/app/models/hellos.rb", "class Hello ; end" + app_file "vendor/plugins/engine/lib/omg.rb", "puts 'omg'" + app_file "vendor/plugins/engine/config/locales/en.yml", "hello:" + + Rails::Initializer.run do |c| + c.i18n.load_path << "my/other/locale.yml" + end + + #{RAILS_FRAMEWORK_ROOT}/railties/test/fixtures/plugins/engines/engine/config/locales/en.yml + assert_equal %W( + #{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activemodel/lib/active_model/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/activerecord/lib/active_record/locale/en.yml + #{RAILS_FRAMEWORK_ROOT}/actionpack/lib/action_view/locale/en.yml + #{app_path}/config/locales/en.yml + my/other/locale.yml + #{app_path}/vendor/plugins/engine/config/locales/en.yml + ), I18n.load_path + end + end +end
\ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index b67db9c835..92383a74fd 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -393,24 +393,6 @@ class InitializerSetupI18nTests < Test::Unit::TestCase assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path end - def test_config_defaults_and_settings_should_be_added_to_i18n_defaults - File.stubs(:exist?).returns(true) - Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) - - config = Rails::Configuration.new - config.i18n.load_path << "my/other/locale.yml" - - Rails::Initializer.run(:initialize_i18n, config) - assert_equal [ - File.expand_path(File.dirname(__FILE__) + "/../../activesupport/lib/active_support/locale/en.yml"), - File.expand_path(File.dirname(__FILE__) + "/../../actionpack/lib/action_view/locale/en.yml"), - File.expand_path(File.dirname(__FILE__) + "/../../activemodel/lib/active_model/locale/en.yml"), - File.expand_path(File.dirname(__FILE__) + "/../../activerecord/lib/active_record/locale/en.yml"), - File.expand_path(File.dirname(__FILE__) + "/../../railties/test/fixtures/plugins/engines/engine/config/locales/en.yml"), - "my/test/locale.yml", - "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /\.\./ ? File.expand_path(path) : path } - end - def test_setting_another_default_locale config = Rails::Configuration.new config.i18n.default_locale = :de diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index a55ee6c01d..c452adaa52 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -91,7 +91,8 @@ module TestHelpers end def app_file(path, contents) - File.open(app_path(path), 'w') do |f| + FileUtils.mkdir_p File.dirname("#{app_path}/#{path}") + File.open("#{app_path}/#{path}", 'w') do |f| f.puts contents end end |