aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/abstract_unit.rb8
-rw-r--r--railties/test/application/console_test.rb52
-rw-r--r--railties/test/application/generators_test.rb89
-rw-r--r--railties/test/application/initializer_test.rb194
-rw-r--r--railties/test/application/load_test.rb9
-rw-r--r--railties/test/application/plugins_test.rb101
-rw-r--r--railties/test/console_app_test.rb43
-rw-r--r--railties/test/fcgi_dispatcher_test.rb268
-rw-r--r--railties/test/generators/app_generator_test.rb12
-rw-r--r--railties/test/initializable_test.rb68
-rw-r--r--railties/test/initializer/initialize_i18n_test.rb51
-rw-r--r--railties/test/initializer/path_test.rb2
-rw-r--r--railties/test/initializer_test.rb482
-rw-r--r--railties/test/isolation/abstract_unit.rb13
-rw-r--r--railties/test/new_initializer_test.rb165
-rw-r--r--railties/test/plugin_loader_test.rb17
-rw-r--r--railties/test/plugin_locator_test.rb16
-rw-r--r--railties/test/plugin_test.rb15
18 files changed, 612 insertions, 993 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb
index 4510e6241c..6c6af0b2bf 100644
--- a/railties/test/abstract_unit.rb
+++ b/railties/test/abstract_unit.rb
@@ -25,11 +25,3 @@ if defined?(RAILS_ROOT)
else
RAILS_ROOT = File.dirname(__FILE__)
end
-
-def uses_gem(gem_name, test_name, version = '> 0')
- gem gem_name.to_s, version
- require gem_name.to_s
- yield
-rescue LoadError
- $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again."
-end
diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb
new file mode 100644
index 0000000000..e8a4a4e158
--- /dev/null
+++ b/railties/test/application/console_test.rb
@@ -0,0 +1,52 @@
+require 'isolation/abstract_unit'
+
+class ConsoleTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ build_app
+ boot_rails
+
+ # Load steps taken from rails/commands/console.rb
+ require "#{rails_root}/config/environment"
+ require 'rails/console_app'
+ require 'rails/console_with_helpers'
+ end
+
+ def test_app_method_should_return_integration_session
+ console_session = app
+ assert_not_nil console_session
+ assert_instance_of ActionController::Integration::Session, console_session
+ end
+
+ def test_new_session_should_return_integration_session
+ session = new_session
+ assert_not_nil session
+ assert_instance_of ActionController::Integration::Session, session
+ end
+
+ def test_reload_should_fire_preparation_callbacks
+ a = b = c = nil
+
+ # TODO: These should be defined on the initializer
+ ActionDispatch::Callbacks.to_prepare { a = b = c = 1 }
+ ActionDispatch::Callbacks.to_prepare { b = c = 2 }
+ ActionDispatch::Callbacks.to_prepare { c = 3 }
+
+ # Hide Reloading... output
+ silence_stream(STDOUT) do
+ reload!
+ end
+
+ assert_equal 1, a
+ assert_equal 2, b
+ assert_equal 3, c
+ end
+
+ def test_access_to_helpers
+ assert_not_nil helper
+ assert_instance_of ActionView::Base, helper
+ assert_equal 'Once upon a time in a world...',
+ helper.truncate('Once upon a time in a world far far away')
+ end
+end
diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb
new file mode 100644
index 0000000000..0d6eb4147a
--- /dev/null
+++ b/railties/test/application/generators_test.rb
@@ -0,0 +1,89 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ class GeneratorsTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def setup
+ require "rails/generators"
+ build_app
+ boot_rails
+ end
+
+ test "generators default values" do
+ Rails::Initializer.run do |c|
+ assert_equal(true, c.generators.colorize_logging)
+ assert_equal({}, c.generators.aliases)
+ assert_equal({}, c.generators.options)
+ end
+ end
+
+ test "generators set rails options" do
+ Rails::Initializer.run do |c|
+ c.generators.orm = :datamapper
+ c.generators.test_framework = :rspec
+ expected = { :rails => { :orm => :datamapper, :test_framework => :rspec } }
+ assert_equal(expected, c.generators.options)
+ end
+ end
+
+ test "generators set rails aliases" do
+ Rails::Initializer.run do |c|
+ c.generators.aliases = { :rails => { :test_framework => "-w" } }
+ expected = { :rails => { :test_framework => "-w" } }
+ assert_equal expected, c.generators.aliases
+ end
+ end
+
+ test "generators aliases and options on initialization" do
+ Rails::Initializer.run do |c|
+ c.generators.rails :aliases => { :test_framework => "-w" }
+ c.generators.orm :datamapper
+ c.generators.test_framework :rspec
+ end
+
+ assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
+ assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
+ end
+
+ test "generators no color on initialization" do
+ Rails::Initializer.run do |c|
+ c.generators.colorize_logging = false
+ end
+
+ assert_equal Thor::Base.shell, Thor::Shell::Basic
+ end
+
+ test "generators with hashes for options and aliases" do
+ Rails::Initializer.run do |c|
+ c.generators do |g|
+ g.orm :datamapper, :migration => false
+ g.plugin :aliases => { :generator => "-g" },
+ :generator => true
+ end
+
+ expected = {
+ :rails => { :orm => :datamapper },
+ :plugin => { :generator => true },
+ :datamapper => { :migration => false }
+ }
+
+ assert_equal expected, c.generators.options
+ assert_equal({ :plugin => { :generator => "-g" } }, c.generators.aliases)
+ end
+ end
+
+ test "generators with hashes are deep merged" do
+ Rails::Initializer.run do |c|
+ c.generators do |g|
+ g.orm :datamapper, :migration => false
+ g.plugin :aliases => { :generator => "-g" },
+ :generator => true
+ end
+ end
+
+ assert Rails::Generators.aliases.size >= 1
+ assert Rails::Generators.options.size >= 1
+ 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..f46bf2b656
--- /dev/null
+++ b/railties/test/application/initializer_test.rb
@@ -0,0 +1,194 @@
+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
+
+ test "adding an unknown framework raises an error" do
+ class MyApp < Rails::Application
+ config.frameworks << :action_foo
+ end
+
+ assert_raises RuntimeError do
+ MyApp.new
+ end
+ end
+
+ test "eager loading loads parent classes before children" do
+ app_file "lib/zoo.rb", <<-ZOO
+ class Zoo ; include ReptileHouse ; end
+ ZOO
+ app_file "lib/zoo/reptile_house.rb", <<-ZOO
+ module Zoo::ReptileHouse ; end
+ ZOO
+
+ Rails::Initializer.run do |config|
+ config.eager_load_paths = "#{app_path}/lib"
+ end
+
+ assert Zoo
+ end
+
+ 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 { }
+ assert_equal "success", $initialize_test_set_from_env
+ end
+
+ test "action_controller load paths set only if action controller in use" do
+ assert_nothing_raised NameError do
+ Rails::Initializer.run do |config|
+ config.frameworks = []
+ end
+ end
+ end
+
+ test "action_pack is added to the load path if action_controller is required" do
+ Rails::Initializer.run do |config|
+ config.frameworks = [:action_controller]
+ end
+
+ assert $:.include?("#{framework_path}/actionpack/lib")
+ end
+
+ test "action_pack is added to the load path if action_view is required" do
+ Rails::Initializer.run do |config|
+ config.frameworks = [:action_view]
+ end
+
+ assert $:.include?("#{framework_path}/actionpack/lib")
+ end
+
+ test "after_initialize block works correctly" do
+ Rails::Initializer.run do |config|
+ config.after_initialize { $test_after_initialize_block1 = "success" }
+ config.after_initialize { $test_after_initialize_block2 = "congratulations" }
+ end
+
+ assert_equal "success", $test_after_initialize_block1
+ assert_equal "congratulations", $test_after_initialize_block2
+ end
+
+ test "after_initialize block works correctly when no block is passed" do
+ Rails::Initializer.run do |config|
+ 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" }
+ end
+
+ assert_equal "success", $test_after_initialize_block1
+ assert_equal "congratulations", $test_after_initialize_block2
+ end
+
+ # i18n
+ test "setting another default locale" do
+ Rails::Initializer.run do |config|
+ config.i18n.default_locale = :de
+ end
+ 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"
+ Rails::Initializer.run do |c|
+ 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|
+ 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.i18n.load_path << "my/other/locale.yml"
+ end
+
+ assert_equal [
+ "#{app_path}/config/locales/en.yml", "my/other/locale.yml"
+ ], Rails.application.config.i18n.load_path
+ end
+
+ # DB middleware
+ test "database middleware doesn't initialize when session store is not active_record" do
+ Rails::Initializer.run do |config|
+ config.action_controller.session_store = :cookie_store
+ end
+
+ assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
+ end
+
+ test "database middleware doesn't initialize when activerecord is not in frameworks" do
+ Rails::Initializer.run do |c|
+ c.frameworks = []
+ end
+ assert_equal [], Rails.application.config.middleware
+ end
+
+ test "database middleware initializes when session store is active record" do
+ Rails::Initializer.run do |c|
+ c.action_controller.session_store = :active_record_store
+ end
+
+ expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore]
+ middleware = Rails.application.config.middleware.map { |m| m.klass }
+ assert_equal expects, middleware & expects
+ end
+
+ test "ensure database middleware doesn't use action_controller on initializing" do
+ Rails::Initializer.run do |c|
+ c.frameworks -= [:action_controller]
+ c.action_controller.session_store = :active_record_store
+ end
+
+ assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore)
+ end
+
+ # Pathview test
+ test "load view paths doesn't perform anything when action_view not in frameworks" do
+ Rails::Initializer.run do |c|
+ c.frameworks -= [:action_view]
+ end
+ assert_equal nil, ActionMailer::Base.template_root
+ 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
+ assert_instance_of Pathname, Rails.root
+ 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 5158abdbb4..5c3d35fb16 100644
--- a/railties/test/application/load_test.rb
+++ b/railties/test/application/load_test.rb
@@ -40,7 +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 < Rails::Application
end
test "the config object is available on the application object" do
diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb
new file mode 100644
index 0000000000..81e7f4d88c
--- /dev/null
+++ b/railties/test/application/plugins_test.rb
@@ -0,0 +1,101 @@
+require "isolation/abstract_unit"
+
+module ApplicationTests
+ class PluginTest < Test::Unit::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ def assert_plugins(list_of_names, array_of_plugins, message=nil)
+ assert_equal list_of_names.map { |n| n.to_s }, array_of_plugins.map { |p| p.name }, message
+ end
+
+ def setup
+ build_app
+ boot_rails
+ @failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
+ # Tmp hax to get tests working
+ FileUtils.cp_r "#{File.dirname(__FILE__)}/../fixtures/plugins", "#{app_path}/vendor"
+ end
+
+ test "all plugins are loaded when registered plugin list is untouched" do
+ Rails::Initializer.run { }
+ assert_plugins [
+ :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby
+ ], Rails.application.config.loaded_plugins, @failure_tip
+ end
+
+ test "no plugins are loaded if the configuration has an empty plugin list" do
+ Rails::Initializer.run { |c| c.plugins = [] }
+ assert_plugins [], Rails.application.config.loaded_plugins
+ end
+
+ test "only the specified plugins are located in the order listed" do
+ plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
+ Rails::Initializer.run { |c| c.plugins = plugin_names }
+ assert_plugins plugin_names, Rails.application.config.loaded_plugins
+ end
+
+ test "all plugins loaded after all" do
+ Rails::Initializer.run do |config|
+ config.plugins = [:stubby, :all, :acts_as_chunky_bacon]
+ end
+ assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], Rails.application.config.loaded_plugins, @failure_tip
+ end
+
+ test "plugin names may be strings" do
+ plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
+ Rails::Initializer.run do |config|
+ config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
+ end
+
+ assert_plugins plugin_names, Rails.application.config.loaded_plugins, @failure_tip
+ end
+
+ test "all plugins loaded when all is used" do
+ Rails::Initializer.run do |config|
+ config.plugins = [:stubby, :acts_as_chunky_bacon, :all]
+ end
+
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], Rails.application.config.loaded_plugins, @failure_tip
+ end
+
+ test "all loaded plugins are added to the load paths" do
+ Rails::Initializer.run do |config|
+ config.plugins = [:stubby, :acts_as_chunky_bacon]
+ end
+
+ assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/stubby/lib")
+ assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/acts/acts_as_chunky_bacon/lib")
+ end
+
+ test "registering a plugin name that does not exist raises a load error" do
+ assert_raise(LoadError) do
+ Rails::Initializer.run do |config|
+ config.plugins = [:stubby, :acts_as_a_non_existant_plugin]
+ end
+ end
+ end
+
+ test "load error messages mention missing plugins and no others" do
+ valid_plugins = [:stubby, :acts_as_chunky_bacon]
+ invalid_plugins = [:non_existant_plugin1, :non_existant_plugin2]
+
+ begin
+ Rails::Initializer.run do |config|
+ config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2]
+ end
+ flunk "Expected a LoadError but did not get one"
+ rescue LoadError => e
+ assert_plugins valid_plugins, Rails.application.config.loaded_plugins, @failure_tip
+
+ invalid_plugins.each do |plugin|
+ assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'")
+ end
+
+ valid_plugins.each do |plugin|
+ assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'")
+ end
+ end
+ end
+
+ end
+end \ No newline at end of file
diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb
deleted file mode 100644
index 1437e6d885..0000000000
--- a/railties/test/console_app_test.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-require 'abstract_unit'
-
-require 'action_controller' # console_app uses 'action_controller/integration'
-
-require 'rails/dispatcher'
-require 'rails/console_app'
-
-module Rails
- def self.application
- ActionController::Routing::Routes
- end
-end
-
-# console_app sets Test::Unit.run to work around the at_exit hook in test/unit, which kills IRB
-if Test::Unit.respond_to?(:run=)
- Test::Unit.run = false
-
- class ConsoleAppTest < Test::Unit::TestCase
- def test_app_method_should_return_integration_session
- assert_nothing_thrown do
- console_session = app
- assert_not_nil console_session
- assert_instance_of ActionController::Integration::Session,
- console_session
- end
- end
-
- def test_reload_should_fire_preparation_callbacks
- a = b = c = nil
-
- ActionDispatch::Callbacks.to_prepare { a = b = c = 1 }
- ActionDispatch::Callbacks.to_prepare { b = c = 2 }
- ActionDispatch::Callbacks.to_prepare { c = 3 }
- ActionController::Routing::Routes.expects(:reload)
-
- reload!
-
- assert_equal 1, a
- assert_equal 2, b
- assert_equal 3, c
- end
- end
-end
diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb
deleted file mode 100644
index 4d77a321a0..0000000000
--- a/railties/test/fcgi_dispatcher_test.rb
+++ /dev/null
@@ -1,268 +0,0 @@
-require 'abstract_unit'
-
-uses_gem "fcgi", "0.8.7" do
-
-require 'action_controller'
-require 'rails/fcgi_handler'
-
-module Rails
- def self.application
- ActionController::Routing::Routes
- end
-end
-
-class RailsFCGIHandlerTest < Test::Unit::TestCase
- def setup
- @log = StringIO.new
- @handler = RailsFCGIHandler.new(@log)
- end
-
- def test_process_restart
- request = mock
- FCGI.stubs(:each).yields(request)
-
- @handler.expects(:process_request).once
- @handler.expects(:dispatcher_error).never
-
- @handler.expects(:when_ready).returns(:restart)
- @handler.expects(:close_connection).with(request)
- @handler.expects(:reload!).never
- @handler.expects(:restart!)
-
- @handler.process!
- end
-
- def test_process_exit
- request = mock
- FCGI.stubs(:each).yields(request)
-
- @handler.expects(:process_request).once
- @handler.expects(:dispatcher_error).never
-
- @handler.expects(:when_ready).returns(:exit)
- @handler.expects(:close_connection).with(request)
- @handler.expects(:reload!).never
- @handler.expects(:restart!).never
-
- @handler.process!
- end
-
- def test_process_with_system_exit_exception
- request = mock
- FCGI.stubs(:each).yields(request)
-
- @handler.expects(:process_request).once.raises(SystemExit)
- @handler.stubs(:dispatcher_log)
- @handler.expects(:dispatcher_log).with(:info, regexp_matches(/^stopping/))
- @handler.expects(:dispatcher_error).never
-
- @handler.expects(:when_ready).never
- @handler.expects(:close_connection).never
- @handler.expects(:reload!).never
- @handler.expects(:restart!).never
-
- @handler.process!
- end
-
- def test_restart_handler_outside_request
- @handler.expects(:dispatcher_log).with(:info, "asked to restart ASAP")
- @handler.expects(:restart!).once
-
- @handler.send(:restart_handler, nil)
- assert_equal nil, @handler.when_ready
- end
-
- def test_install_signal_handler_should_log_on_bad_signal
- @handler.stubs(:trap).raises(ArgumentError)
-
- @handler.expects(:dispatcher_log).with(:warn, "Ignoring unsupported signal CHEESECAKE.")
- @handler.send(:install_signal_handler, "CHEESECAKE", nil)
- end
-
- def test_reload
- @handler.expects(:restore!)
- @handler.expects(:dispatcher_log).with(:info, "reloaded")
-
- @handler.send(:reload!)
- assert_nil @handler.when_ready
- end
-
-
- def test_reload_runs_gc_when_gc_request_period_set
- @handler.expects(:run_gc!)
- @handler.expects(:restore!)
- @handler.expects(:dispatcher_log).with(:info, "reloaded")
- @handler.gc_request_period = 10
- @handler.send(:reload!)
- end
-
- def test_reload_doesnt_run_gc_if_gc_request_period_isnt_set
- @handler.expects(:run_gc!).never
- @handler.expects(:restore!)
- @handler.expects(:dispatcher_log).with(:info, "reloaded")
- @handler.send(:reload!)
- end
-
- def test_restart!
- @handler.expects(:dispatcher_log).with(:info, "restarted")
- @handler.expects(:exec).returns('restarted')
- assert_equal 'restarted', @handler.send(:restart!)
- end
-
- def test_restore!
- $".expects(:replace)
- Dispatcher.expects(:reset_application!)
- ActionController::Routing::Routes.expects(:reload)
- @handler.send(:restore!)
- end
-
- def test_uninterrupted_processing
- request = mock
- FCGI.expects(:each).yields(request)
- @handler.expects(:process_request).with(request)
-
- @handler.process!
-
- assert_nil @handler.when_ready
- end
-end
-
-
-class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase
- class ::RailsFCGIHandler
- attr_accessor :signal
- alias_method :old_gc_countdown, :gc_countdown
- def gc_countdown
- signal ? Process.kill(signal, $$) : old_gc_countdown
- end
- end
-
- def setup
- @log = StringIO.new
- @handler = RailsFCGIHandler.new(@log)
- @dispatcher = mock
- Dispatcher.stubs(:new).returns(@dispatcher)
- end
-
- def test_interrupted_via_HUP_when_not_in_request
- request = mock
- FCGI.expects(:each).once.yields(request)
- @handler.expects(:signal).times(2).returns('HUP')
-
- @handler.expects(:reload!).once
- @handler.expects(:close_connection).never
- @handler.expects(:exit).never
-
- @handler.process!
- assert_equal :reload, @handler.when_ready
- end
-
- def test_interrupted_via_USR1_when_not_in_request
- request = mock
- FCGI.expects(:each).once.yields(request)
- @handler.expects(:signal).times(2).returns('USR1')
- @handler.expects(:exit_handler).never
-
- @handler.expects(:reload!).never
- @handler.expects(:close_connection).with(request).once
- @handler.expects(:exit).never
-
- @handler.process!
- assert_nil @handler.when_ready
- end
-
- def test_restart_via_USR2_when_in_request
- request = mock
- FCGI.expects(:each).once.yields(request)
- @handler.expects(:signal).times(2).returns('USR2')
- @handler.expects(:exit_handler).never
-
- @handler.expects(:reload!).never
- @handler.expects(:close_connection).with(request).once
- @handler.expects(:exit).never
- @handler.expects(:restart!).once
-
- @handler.process!
- assert_equal :restart, @handler.when_ready
- end
-
- def test_interrupted_via_TERM
- request = mock
- FCGI.expects(:each).once.yields(request)
- ::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM')
-
- @handler.expects(:reload!).never
- @handler.expects(:close_connection).never
-
- @handler.process!
- assert_nil @handler.when_ready
- end
-
- def test_runtime_exception_in_fcgi
- error = RuntimeError.new('foo')
- FCGI.expects(:each).times(2).raises(error)
- @handler.expects(:dispatcher_error).with(error, regexp_matches(/^retrying/))
- @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
- @handler.process!
- end
-
- def test_runtime_error_in_dispatcher
- request = mock
- error = RuntimeError.new('foo')
- FCGI.expects(:each).once.yields(request)
- ::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
- @handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/))
- @handler.process!
- end
-
- def test_signal_exception_in_fcgi
- error = SignalException.new('USR2')
- FCGI.expects(:each).once.raises(error)
- @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
- @handler.process!
- end
-
- def test_signal_exception_in_dispatcher
- request = mock
- error = SignalException.new('USR2')
- FCGI.expects(:each).once.yields(request)
- ::Rack::Handler::FastCGI.expects(:serve).once.raises(error)
- @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/))
- @handler.process!
- end
-end
-
-
-class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase
- def setup
- @log = StringIO.new
- end
-
- def teardown
- GC.enable
- end
-
- def test_normal_gc
- @handler = RailsFCGIHandler.new(@log)
- assert_nil @handler.gc_request_period
-
- # When GC is enabled, GC.disable disables and returns false.
- assert_equal false, GC.disable
- end
-
- def test_periodic_gc
- @handler = RailsFCGIHandler.new(@log, 10)
- assert_equal 10, @handler.gc_request_period
-
- request = mock
- FCGI.expects(:each).times(10).yields(request)
-
- @handler.expects(:run_gc!).never
- 9.times { @handler.process! }
- @handler.expects(:run_gc!).once
- @handler.process!
-
- assert_nil @handler.when_ready
- end
-end
-end # uses_gem "fcgi"
diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb
index afc0585fba..6e46c4ddc0 100644
--- a/railties/test/generators/app_generator_test.rb
+++ b/railties/test/generators/app_generator_test.rb
@@ -53,18 +53,6 @@ class AppGeneratorTest < GeneratorsTestCase
assert_match /Invalid value for \-\-database option/, content
end
- def test_dispatchers_are_not_added_by_default
- run_generator
- assert_no_file "public/dispatch.cgi"
- assert_no_file "public/dispatch.fcgi"
- end
-
- def test_dispatchers_are_added_if_required
- run_generator ["--with-dispatchers"]
- assert_file "public/dispatch.cgi"
- assert_file "public/dispatch.fcgi"
- end
-
def test_config_database_is_added_by_default
run_generator
assert_file "config/database.yml", /sqlite3/
diff --git a/railties/test/initializable_test.rb b/railties/test/initializable_test.rb
new file mode 100644
index 0000000000..7c8aed00c9
--- /dev/null
+++ b/railties/test/initializable_test.rb
@@ -0,0 +1,68 @@
+require 'abstract_unit'
+require 'rails/initializable'
+
+module InitializableTests
+
+ class Foo
+ extend Rails::Initializable
+
+ class << self
+ attr_accessor :foo, :bar
+ end
+
+ initializer :omg do
+ @foo ||= 0
+ @foo += 1
+ end
+ end
+
+ class Bar < Foo
+ initializer :bar do
+ @bar ||= 0
+ @bar += 1
+ end
+ end
+
+ module Word
+ extend Rails::Initializable
+
+ initializer :word do
+ $word = "bird"
+ end
+ end
+
+ class Basic < ActiveSupport::TestCase
+ include ActiveSupport::Testing::Isolation
+
+ test "initializers run" do
+ Foo.initializers.run
+ assert_equal 1, Foo.foo
+ end
+
+ test "initializers are inherited" do
+ Bar.initializers.run
+ assert_equal [1, 1], [Bar.foo, Bar.bar]
+ end
+
+ test "initializers only get run once" do
+ Foo.initializers.run
+ Foo.initializers.run
+ assert_equal 1, Foo.foo
+ end
+
+ test "running initializers on children does not effect the parent" do
+ Bar.initializers.run
+ assert_nil Foo.foo
+ assert_nil Foo.bar
+ end
+
+ test "inherited initializers are the same objects" do
+ assert Foo.initializers[:foo].eql?(Bar.initializers[:foo])
+ end
+
+ test "initializing with modules" do
+ Word.initializers.run
+ assert_equal "bird", $word
+ end
+ end
+end \ No newline at end of file
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/path_test.rb b/railties/test/initializer/path_test.rb
index a4264bc31c..72ff8d88e0 100644
--- a/railties/test/initializer/path_test.rb
+++ b/railties/test/initializer/path_test.rb
@@ -12,7 +12,7 @@ class PathsTest < Test::Unit::TestCase
ActionController::Base.session_store = nil
end
end
- @paths = Rails::Initializer.default.config.paths
+ @paths = Rails.application.config.paths
end
def root(*path)
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index b67db9c835..80e774b7b7 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -6,490 +6,8 @@ require 'action_view'
require 'action_mailer'
require 'active_record'
-# Mocks out the configuration
-module Rails
- def self.configuration
- Rails::Configuration.new
- end
-
- module Generators
- def self.clear_aliases!
- @aliases = nil
- end
-
- def self.clear_options!
- @@options = nil
- end
- end
-end
-
-
-class ConfigurationMock < Rails::Configuration
- attr_reader :environment_path
-
- def initialize(envpath)
- super()
- @environment_path = envpath
- end
-end
-
-class Initializer_load_environment_Test < Test::Unit::TestCase
- def test_load_environment_with_constant
- config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb")
- assert_nil $initialize_test_set_from_env
- Rails::Initializer.run(:load_environment, config)
- assert_equal "success", $initialize_test_set_from_env
- ensure
- $initialize_test_set_from_env = nil
- end
-end
-
-class Initializer_eager_loading_Test < Test::Unit::TestCase
- def setup
- @config = ConfigurationMock.new("")
- @config.cache_classes = true
- @config.load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")]
- @config.eager_load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")]
- @initializer = Rails::Initializer.default
- @initializer.config = @config
- @initializer.run(:set_load_path)
- @initializer.run(:set_autoload_paths)
- end
-
- def test_eager_loading_loads_parent_classes_before_children
- assert_nothing_raised do
- @initializer.run(:load_application_classes)
- end
- end
-end
-
-class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase
- def setup
- config = ConfigurationMock.new("")
- config.after_initialize do
- $test_after_initialize_block1 = "success"
- end
- config.after_initialize do
- $test_after_initialize_block2 = "congratulations"
- end
- assert_nil $test_after_initialize_block1
- assert_nil $test_after_initialize_block2
-
- config.expects(:gems_dependencies_loaded).returns(true)
- Rails::Initializer.run(:after_initialize, config)
- end
-
- def teardown
- $test_after_initialize_block1 = nil
- $test_after_initialize_block2 = nil
- end
-
- def test_should_have_called_the_first_after_initialize_block
- assert_equal "success", $test_after_initialize_block1
- end
-
- def test_should_have_called_the_second_after_initialize_block
- assert_equal "congratulations", $test_after_initialize_block2
- end
-end
-
-class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase
- def setup
- config = ConfigurationMock.new("")
- config.after_initialize do
- $test_after_initialize_block1 = "success"
- end
- config.after_initialize # don't pass a block, this is what we're testing!
- config.after_initialize do
- $test_after_initialize_block2 = "congratulations"
- end
- assert_nil $test_after_initialize_block1
-
- config.expects(:gems_dependencies_loaded).returns(true)
- Rails::Initializer.run(:after_initialize, config)
- end
-
- def teardown
- $test_after_initialize_block1 = nil
- $test_after_initialize_block2 = nil
- end
-
- def test_should_have_called_the_first_after_initialize_block
- assert_equal "success", $test_after_initialize_block1, "should still get set"
- end
-
- def test_should_have_called_the_second_after_initialize_block
- assert_equal "congratulations", $test_after_initialize_block2
- end
-end
-
-class ConfigurationFrameworkPathsTests < Test::Unit::TestCase
- def setup
- @config = Rails::Configuration.new
- @config.frameworks.clear
- @initializer = Rails::Initializer.default
- @initializer.config = @config
-
- File.stubs(:directory?).returns(true)
- Rails::Initializer.run(:set_root_path, @config)
- end
-
- def test_minimal
- expected = %w(railties railties/lib activesupport/lib)
- assert_equal expected.map {|e| "#{@config.framework_root_path}/#{e}"}, @config.framework_paths
- end
-
- def test_actioncontroller_or_actionview_add_actionpack
- @config.frameworks << :action_controller
- assert_framework_path "actionpack/lib"
-
- @config.frameworks = [:action_view]
- assert_framework_path 'actionpack/lib'
- end
-
- def test_paths_for_ar_ares_and_mailer
- [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
- @config.frameworks = [framework]
- assert_framework_path "#{framework.to_s.gsub('_', '')}/lib"
- end
- end
-
- def test_unknown_framework_raises_error
- @config.frameworks << :action_foo
-
- Class.any_instance.expects(:require).raises(LoadError)
-
- assert_raise RuntimeError do
- @initializer.run(:require_frameworks)
- end
- end
-
- def test_action_mailer_load_paths_set_only_if_action_mailer_in_use
- @config.frameworks = [:action_controller]
- @initializer.config = @config
- @initializer.run :require_frameworks
-
- assert_nothing_raised NameError do
- @initializer.run :load_view_paths
- end
- end
-
- def test_action_controller_load_paths_set_only_if_action_controller_in_use
- @config.frameworks = []
- @initializer.run :require_frameworks
-
- assert_nothing_raised NameError do
- @initializer.run :load_view_paths
- end
- end
-
- protected
- def assert_framework_path(path)
- assert @config.framework_paths.include?("#{@config.framework_root_path}/#{path}"),
- "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>"
- end
-end
-
require 'plugin_test_helper'
-class InitializerPluginLoadingTests < Test::Unit::TestCase
- def setup
- @configuration = Rails::Configuration.new
- @configuration.frameworks -= [:action_mailer]
- @configuration.plugin_paths << plugin_fixture_root_path
- @initializer = Rails::Initializer.default
- @initializer.config = @configuration
- @valid_plugin_path = plugin_fixture_path('default/stubby')
- @empty_plugin_path = plugin_fixture_path('default/empty')
- end
-
- def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
- only_load_the_following_plugins! []
- @initializer.run :load_plugins
- assert_equal [], @configuration.loaded_plugins
- end
-
- def test_only_the_specified_plugins_are_located_in_the_order_listed
- plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
- only_load_the_following_plugins! plugin_names
- load_plugins!
- assert_plugins plugin_names, @configuration.loaded_plugins
- end
-
- def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- load_plugins!
- assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @configuration.loaded_plugins, failure_tip
- end
-
- def test_all_plugins_loaded_when_all_is_used
- plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
- only_load_the_following_plugins! plugin_names
- load_plugins!
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @configuration.loaded_plugins, failure_tip
- end
-
- def test_all_plugins_loaded_after_all
- plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
- only_load_the_following_plugins! plugin_names
- load_plugins!
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @configuration.loaded_plugins, failure_tip
- end
-
- def test_plugin_names_may_be_strings
- plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
- only_load_the_following_plugins! plugin_names
- load_plugins!
- failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins plugin_names, @configuration.loaded_plugins, failure_tip
- end
-
- def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
- only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
- assert_raise(LoadError) do
- load_plugins!
- end
- end
-
- def test_load_error_messages_mention_missing_plugins_and_no_others
- valid_plugin_names = [:stubby, :acts_as_chunky_bacon]
- invalid_plugin_names = [:non_existant_plugin1, :non_existant_plugin2]
- only_load_the_following_plugins!( valid_plugin_names + invalid_plugin_names )
- begin
- load_plugins!
- flunk "Expected a LoadError but did not get one"
- rescue LoadError => e
- failure_tip = "It's likely someone renamed or deleted plugin fixtures without updating this test"
- assert_plugins valid_plugin_names, @configuration.loaded_plugins, failure_tip
- invalid_plugin_names.each do |plugin|
- assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'")
- end
- valid_plugin_names.each do |plugin|
- assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'")
- end
-
- end
- end
-
- def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
- only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
-
- @initializer.run(:add_plugin_load_paths)
-
- assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
- assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
- end
-
- private
-
- def load_plugins!
- @initializer.run(:add_plugin_load_paths)
- @initializer.run(:load_plugins)
- end
-end
-
-class InitializerGeneratorsTests < Test::Unit::TestCase
-
- def setup
- @configuration = Rails::Configuration.new
- @initializer = Rails::Initializer.default
- @initializer.config = @configuration
- end
-
- def test_generators_default_values
- assert_equal(true, @configuration.generators.colorize_logging)
- assert_equal({}, @configuration.generators.aliases)
- assert_equal({}, @configuration.generators.options)
- end
-
- def test_generators_set_rails_options
- @configuration.generators.orm = :datamapper
- @configuration.generators.test_framework = :rspec
- expected = { :rails => { :orm => :datamapper, :test_framework => :rspec } }
- assert_equal expected, @configuration.generators.options
- end
-
- def test_generators_set_rails_aliases
- @configuration.generators.aliases = { :rails => { :test_framework => "-w" } }
- expected = { :rails => { :test_framework => "-w" } }
- assert_equal expected, @configuration.generators.aliases
- end
-
- def test_generators_aliases_and_options_on_initialization
- @configuration.generators.rails :aliases => { :test_framework => "-w" }
- @configuration.generators.orm :datamapper
- @configuration.generators.test_framework :rspec
-
- @initializer.run(:initialize_generators)
-
- assert_equal :rspec, Rails::Generators.options[:rails][:test_framework]
- assert_equal "-w", Rails::Generators.aliases[:rails][:test_framework]
- end
-
- def test_generators_no_color_on_initialization
- @configuration.generators.colorize_logging = false
- @initializer.run(:initialize_generators)
- assert_equal Thor::Base.shell, Thor::Shell::Basic
- end
-
- def test_generators_with_hashes_for_options_and_aliases
- @configuration.generators do |g|
- g.orm :datamapper, :migration => false
- g.plugin :aliases => { :generator => "-g" },
- :generator => true
- end
-
- expected = {
- :rails => { :orm => :datamapper },
- :plugin => { :generator => true },
- :datamapper => { :migration => false }
- }
-
- assert_equal expected, @configuration.generators.options
- assert_equal({ :plugin => { :generator => "-g" } }, @configuration.generators.aliases)
- end
-
- def test_generators_with_hashes_are_deep_merged
- @configuration.generators do |g|
- g.orm :datamapper, :migration => false
- g.plugin :aliases => { :generator => "-g" },
- :generator => true
- end
- @initializer.run(:initialize_generators)
-
- assert Rails::Generators.aliases.size >= 1
- assert Rails::Generators.options.size >= 1
- end
-
- protected
-
- def teardown
- Rails::Generators.clear_aliases!
- Rails::Generators.clear_options!
- end
-end
-
-class InitializerSetupI18nTests < Test::Unit::TestCase
- def test_no_config_locales_dir_present_should_return_empty_load_path
- File.stubs(:exist?).returns(false)
- assert_equal [], Rails::Configuration.new.i18n.load_path
- end
-
- def test_config_locales_dir_present_should_be_added_to_load_path
- File.stubs(:exist?).returns(true)
- Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
- assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path
- end
-
- def test_config_defaults_should_be_added_with_config_settings
- File.stubs(:exist?).returns(true)
- Dir.stubs(:[]).returns([ "my/test/locale.yml" ])
-
- config = Rails::Configuration.new
- config.i18n.load_path << "my/other/locale.yml"
-
- 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
- Rails::Initializer.run(:initialize_i18n, config)
- assert_equal :de, I18n.default_locale
- end
-end
-
-class InitializerDatabaseMiddlewareTest < Test::Unit::TestCase
- def setup
- @config = Rails::Configuration.new
- @config.frameworks = [:active_record, :action_controller, :action_view]
- end
-
- def test_initialize_database_middleware_doesnt_perform_anything_when_active_record_not_in_frameworks
- @config.frameworks.clear
- @config.expects(:middleware).never
- Rails::Initializer.run(:initialize_database_middleware, @config)
- end
-
- def test_database_middleware_initializes_when_session_store_is_active_record
- store = ActionController::Base.session_store
- ActionController::Base.session_store = ActiveRecord::SessionStore
-
- @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement)
- @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::QueryCache)
-
- Rails::Initializer.run(:initialize_database_middleware, @config)
- ensure
- ActionController::Base.session_store = store
- end
-
- def test_database_middleware_doesnt_initialize_when_session_store_is_not_active_record
- store = ActionController::Base.session_store
- ActionController::Base.session_store = ActionDispatch::Session::CookieStore
-
- # Define the class, so we don't have to actually make it load
- eval("class ActiveRecord::ConnectionAdapters::ConnectionManagement; end")
-
- @config.middleware.expects(:use).with(ActiveRecord::ConnectionAdapters::ConnectionManagement)
- @config.middleware.expects(:use).with(ActiveRecord::QueryCache)
-
- Rails::Initializer.run(:initialize_database_middleware, @config)
- ensure
- ActionController::Base.session_store = store
- end
-
- def test_ensure_database_middleware_doesnt_use_action_controller_on_initializing
- @config.frameworks -= [:action_controller]
- store = ActionController::Base.session_store
- ActionController::Base.session_store = ActiveRecord::SessionStore
-
- @config.middleware.expects(:use).with(ActiveRecord::ConnectionAdapters::ConnectionManagement)
- @config.middleware.expects(:use).with(ActiveRecord::QueryCache)
-
- Rails::Initializer.run(:initialize_database_middleware, @config)
- ensure
- ActionController::Base.session_store = store
- @config.frameworks += [:action_controller]
- end
-end
-
-class InitializerViewPathsTest < Test::Unit::TestCase
- def setup
- @config = Rails::Configuration.new
- @config.frameworks = [:action_view, :action_controller, :action_mailer]
-
- ActionController::Base.stubs(:view_paths).returns(stub)
- ActionMailer::Base.stubs(:view_paths).returns(stub)
- end
-
- def test_load_view_paths_doesnt_perform_anything_when_action_view_not_in_frameworks
- @config.frameworks -= [:action_view]
- ActionController::Base.view_paths.expects(:load!).never
- ActionMailer::Base.view_paths.expects(:load!).never
- Rails::Initializer.run(:load_view_paths, @config)
- end
-end
-
class RailsRootTest < Test::Unit::TestCase
def test_rails_dot_root_equals_rails_root
assert_equal RAILS_ROOT, Rails.root.to_s
diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb
index 869e8429cf..f83e0151a4 100644
--- a/railties/test/isolation/abstract_unit.rb
+++ b/railties/test/isolation/abstract_unit.rb
@@ -7,6 +7,8 @@
# It is also good to know what is the bare minimum to get
# Rails booted up.
+require 'fileutils'
+
# TODO: Remove rubygems when possible
require 'rubygems'
require 'test/unit'
@@ -30,6 +32,14 @@ module TestHelpers
def app_path(*args)
tmp_path(*%w[app] + args)
end
+
+ def framework_path
+ RAILS_FRAMEWORK_ROOT
+ end
+
+ def rails_root
+ app_path
+ end
end
module Rack
@@ -87,7 +97,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
diff --git a/railties/test/new_initializer_test.rb b/railties/test/new_initializer_test.rb
deleted file mode 100644
index 67b66fb088..0000000000
--- a/railties/test/new_initializer_test.rb
+++ /dev/null
@@ -1,165 +0,0 @@
-require 'abstract_unit'
-require 'active_support/ruby/shim'
-require 'rails/initializer'
-
-class InitializerRunnerTest < ActiveSupport::TestCase
-
- def setup
- @runner = Rails::Initializer::Runner.new
- end
-
- test "A new runner can be created" do
- assert @runner
- end
-
- test "The initializers actually get run when the runner is run" do
- state = nil
-
- @runner.add :foo do
- run { state = true }
- end
-
- @runner.run
- assert state
- end
-
- test "By default, initializers get run in the order that they are added" do
- state = []
-
- @runner.add :first do
- run { state << :first }
- end
-
- @runner.add :second do
- run { state << :second }
- end
-
- @runner.run
- assert_equal [:first, :second], state
- end
-
- test "Raises an exception if :before or :after are specified, but don't exist" do
- assert_raise(Rails::Initializer::Error) do
- @runner.add(:fail, :before => :whale) { 1 }
- end
-
- assert_raise(Rails::Initializer::Error) do
- @runner.add(:fail, :after => :whale) { 1 }
- end
- end
-
- test "When adding an initializer, specifying :after allows you to move an initializer after another" do
- state = []
-
- @runner.add :first do
- run { state << :first }
- end
-
- @runner.add :second do
- run { state << :second }
- end
-
- @runner.add :third, :after => :first do
- run { state << :third }
- end
-
- @runner.run
- assert_equal [:first, :third, :second], state
- end
-
- test "An initializer can be deleted" do
- state = []
-
- @runner.add :first do
- run { state << :first }
- end
-
- @runner.add :second do
- run { state << :second }
- end
-
- @runner.delete(:second)
-
- @runner.run
- assert_equal [:first], state
- end
-
- test "A runner can be initialized with an existing runner, which it copies" do
- state = []
-
- @runner.add :first do
- run { state << :first }
- end
-
- @runner.add :second do
- run { state << :second }
- end
-
- Rails::Initializer::Runner.new(@runner).run
- assert_equal [:first, :second], state
- end
-
- test "A child runner can be still be modified without modifying the parent" do
- state = []
-
- @runner.add :first do
- run { state << :first }
- end
-
- @runner.add :second do
- run { state << :second }
- end
-
- new_runner = Rails::Initializer::Runner.new(@runner)
- new_runner.add :trois do
- run { state << :trois }
- end
- new_runner.delete(:second)
-
- new_runner.run
- assert_equal [:first, :trois], state
- state.clear
- @runner.run
- assert_equal [:first, :second], state
- end
-
- test "A child runner that is modified does not modify any other children of the same parent" do
- state = []
-
- @runner.add :first do
- run { state << :first }
- end
-
- @runner.add :second do
- run { state << :second }
- end
-
- child_one = Rails::Initializer::Runner.new(@runner)
- child_two = Rails::Initializer::Runner.new(@runner)
-
- child_one.delete(:second)
- child_two.run
-
- assert_equal [:first, :second], state
- end
-
- test "It does not run the initializer block immediately" do
- state = []
- @runner.add :first do
- state << :first
- end
-
- assert_equal [], state
- end
-
- test "It runs the block when the runner is run" do
- state = []
- @runner.add :first do
- state << :first
- end
-
- @runner.run
- assert_equal [:first], state
- end
-
-end \ No newline at end of file
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
index 99301347b6..0b43c49bb2 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -5,10 +5,13 @@ $:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib"
require 'action_controller'
require 'action_mailer'
-# Mocks out the configuration
-module Rails
- def self.configuration
- Rails::Configuration.new
+# TODO: Rewrite all these tests
+class FakeInitializerSlashApplication
+ attr_reader :config
+ alias configuration config
+
+ def initialize
+ @config = Rails::Configuration.new
end
end
@@ -18,10 +21,10 @@ class TestPluginLoader < Test::Unit::TestCase
def setup
reset_load_path!
- @configuration = Rails::Configuration.new
+ @initializer = FakeInitializerSlashApplication.new
+ @configuration = @initializer.config
+ Rails.application = @initializer
@configuration.plugin_paths << plugin_fixture_root_path
- @initializer = Rails::Initializer.default
- @initializer.config = @configuration
@valid_plugin_path = plugin_fixture_path('default/stubby')
@empty_plugin_path = plugin_fixture_path('default/empty')
diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb
index da1548dee1..ef57e7ed4c 100644
--- a/railties/test/plugin_locator_test.rb
+++ b/railties/test/plugin_locator_test.rb
@@ -1,5 +1,15 @@
require 'plugin_test_helper'
+# TODO: Rewrite all these tests
+class FakeInitializerSlashApplication
+ attr_reader :config
+ alias configuration config
+
+ def initialize
+ @config = Rails::Configuration.new
+ end
+end
+
class PluginLocatorTest < Test::Unit::TestCase
def test_should_require_subclasses_to_implement_the_plugins_method
assert_raise(RuntimeError) do
@@ -23,12 +33,12 @@ end
class PluginFileSystemLocatorTest < Test::Unit::TestCase
def setup
- @configuration = Rails::Configuration.new
+ @initializer = FakeInitializerSlashApplication.new
+ @configuration = @initializer.config
+ Rails.application = @initializer
# We need to add our testing plugin directory to the plugin paths so
# the locator knows where to look for our plugins
@configuration.plugin_paths << plugin_fixture_root_path
- @initializer = Rails::Initializer.default
- @initializer.config = @configuration
@locator = Rails::Plugin::FileSystemLocator.new(@initializer)
@valid_plugin_path = plugin_fixture_path('default/stubby')
@empty_plugin_path = plugin_fixture_path('default/empty')
diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb
index ae03ea4662..199adcfe39 100644
--- a/railties/test/plugin_test.rb
+++ b/railties/test/plugin_test.rb
@@ -1,9 +1,20 @@
require 'plugin_test_helper'
+# TODO: Rewrite all these tests
+class FakeInitializerSlashApplication
+ attr_reader :config
+ alias configuration config
+
+ def initialize
+ @config = Rails::Configuration.new
+ end
+end
+
class PluginTest < Test::Unit::TestCase
def setup
- @initializer = Rails::Initializer.default
- @initializer.config = Rails::Configuration.new
+ @initializer = FakeInitializerSlashApplication.new
+ @configuration = @initializer.config
+ Rails.application = @initializer
@valid_plugin_path = plugin_fixture_path('default/stubby')
@empty_plugin_path = plugin_fixture_path('default/empty')
@gemlike_plugin_path = plugin_fixture_path('default/gemlike')