diff options
Diffstat (limited to 'railties/test/application/initializer_test.rb')
-rw-r--r-- | railties/test/application/initializer_test.rb | 45 |
1 files changed, 32 insertions, 13 deletions
diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 76486d8f2c..805ff8b6be 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -10,33 +10,38 @@ module ApplicationTests end test "initializing an application initializes rails" do - class MyApp < Rails::Application ; end + Rails::Initializer.run do |config| + config.root = app_path + end if RUBY_VERSION < '1.9' $KCODE = '' - MyApp.new + Rails.application.new assert_equal 'UTF8', $KCODE else Encoding.default_external = Encoding::US_ASCII - MyApp.new + Rails.application.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 + Rails::Initializer.run do |config| + config.root = app_path + end - MyApp.new + Rails.application.new assert $:.include?("#{app_path}/app/models") end test "adding an unknown framework raises an error" do - class MyApp < Rails::Application + Rails::Initializer.run do |config| + config.root = app_path config.frameworks << :action_foo end assert_raises RuntimeError do - MyApp.new + Rails.application.new end end @@ -49,6 +54,7 @@ module ApplicationTests ZOO Rails::Initializer.run do |config| + config.root = app_path config.eager_load_paths = "#{app_path}/lib" end @@ -60,7 +66,7 @@ module ApplicationTests test "load environment with global" do app_file "config/environments/development.rb", "$initialize_test_set_from_env = 'success'" assert_nil $initialize_test_set_from_env - Rails::Initializer.run { } + Rails::Initializer.run { |config| config.root = app_path } Rails.application.new assert_equal "success", $initialize_test_set_from_env end @@ -68,6 +74,7 @@ module ApplicationTests test "action_controller load paths set only if action controller in use" do assert_nothing_raised NameError do Rails::Initializer.run do |config| + config.root = app_path config.frameworks = [] end Rails.application.new @@ -76,6 +83,7 @@ module ApplicationTests test "action_pack is added to the load path if action_controller is required" do Rails::Initializer.run do |config| + config.root = app_path config.frameworks = [:action_controller] end Rails.application.new @@ -85,6 +93,7 @@ module ApplicationTests test "action_pack is added to the load path if action_view is required" do Rails::Initializer.run do |config| + config.root = app_path config.frameworks = [:action_view] end Rails.application.new @@ -94,6 +103,7 @@ module ApplicationTests test "after_initialize block works correctly" do Rails::Initializer.run do |config| + config.root = app_path config.after_initialize { $test_after_initialize_block1 = "success" } config.after_initialize { $test_after_initialize_block2 = "congratulations" } end @@ -105,6 +115,7 @@ module ApplicationTests test "after_initialize block works correctly when no block is passed" do Rails::Initializer.run do |config| + config.root = app_path config.after_initialize { $test_after_initialize_block1 = "success" } config.after_initialize # don't pass a block, this is what we're testing! config.after_initialize { $test_after_initialize_block2 = "congratulations" } @@ -118,6 +129,7 @@ module ApplicationTests # i18n test "setting another default locale" do Rails::Initializer.run do |config| + config.root = app_path config.i18n.default_locale = :de end Rails.application.new @@ -128,18 +140,21 @@ module ApplicationTests test "no config locales dir present should return empty load path" do FileUtils.rm_rf "#{app_path}/config/locales" Rails::Initializer.run do |c| + c.root = app_path assert_equal [], c.i18n.load_path end end test "config locales dir present should be added to load path" do Rails::Initializer.run do |c| + c.root = app_path assert_equal ["#{app_path}/config/locales/en.yml"], c.i18n.load_path end end test "config defaults should be added with config settings" do Rails::Initializer.run do |c| + c.root = app_path c.i18n.load_path << "my/other/locale.yml" end @@ -151,6 +166,7 @@ module ApplicationTests # DB middleware test "database middleware doesn't initialize when session store is not active_record" do Rails::Initializer.run do |config| + config.root = app_path config.action_controller.session_store = :cookie_store end Rails.application.new @@ -160,6 +176,7 @@ module ApplicationTests test "database middleware doesn't initialize when activerecord is not in frameworks" do Rails::Initializer.run do |c| + c.root = app_path c.frameworks = [] end assert_equal [], Rails.application.config.middleware @@ -167,6 +184,7 @@ module ApplicationTests test "database middleware initializes when session store is active record" do Rails::Initializer.run do |c| + c.root = app_path c.action_controller.session_store = :active_record_store end Rails.application.new @@ -178,6 +196,7 @@ module ApplicationTests test "ensure database middleware doesn't use action_controller on initializing" do Rails::Initializer.run do |c| + c.root = app_path c.frameworks -= [:action_controller] c.action_controller.session_store = :active_record_store end @@ -189,6 +208,7 @@ module ApplicationTests # Pathview test test "load view paths doesn't perform anything when action_view not in frameworks" do Rails::Initializer.run do |c| + c.root = app_path c.frameworks -= [:action_view] end Rails.application.new @@ -197,12 +217,11 @@ module ApplicationTests assert_equal [], ActionController::Base.view_paths end - # Rails root test - test "Rails.root == RAILS_ROOT" do - assert_equal RAILS_ROOT, Rails.root.to_s - end - test "Rails.root should be a Pathname" do + Rails::Initializer.run do |c| + c.root = app_path + end + Rails.application.new assert_instance_of Pathname, Rails.root end end |