diff options
Diffstat (limited to 'railties/test')
57 files changed, 282 insertions, 271 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index ea6ed01c7d..4510e6241c 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -2,7 +2,7 @@ ORIG_ARGV = ARGV.dup require 'rubygems' gem 'rack', '~> 1.0.0' -gem 'rack-test', '~> 0.4.2' +gem 'rack-test', '~> 0.5.0' $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" $:.unshift File.dirname(__FILE__) + "/../../activerecord/lib" @@ -18,6 +18,8 @@ require 'test/unit' require 'active_support' require 'active_support/test_case' +require 'action_controller' + if defined?(RAILS_ROOT) RAILS_ROOT.replace File.dirname(__FILE__) else diff --git a/railties/test/application/load_test.rb b/railties/test/application/load_test.rb new file mode 100644 index 0000000000..5158abdbb4 --- /dev/null +++ b/railties/test/application/load_test.rb @@ -0,0 +1,51 @@ +require "isolation/abstract_unit" +# require "rails" +# require 'action_dispatch' + +module ApplicationTests + class LoadTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def rackup + config = "#{app_path}/config.ru" + # Copied from ActionDispatch::Utils.parse_config + # ActionDispatch is not necessarily available at this point. + require 'rack' + if config =~ /\.ru$/ + cfgfile = ::File.read(config) + if cfgfile[/^#\\(.*)/] + opts.parse! $1.split(/\s+/) + end + inner_app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", + nil, config + else + require config + inner_app = Object.const_get(::File.basename(config, '.rb').capitalize) + end + end + + def setup + build_app + boot_rails + end + + test "rails app is present" do + assert File.exist?(app_path("config")) + end + + test "config.ru can be racked up" do + @app = rackup + assert_welcome get("/") + end + + test "Rails.application is available after config.ru has been racked up" do + rackup + assert Rails.application.new.is_a?(Rails::Application) + end + + test "the config object is available on the application object" do + rackup + assert_equal 'UTC', Rails.application.config.time_zone + end + end +end diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 7a1b361440..c3e4f970fe 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -require 'initializer' +require 'rails/initializer' require 'rails/backtrace_cleaner' if defined? Test::Unit::Util::BacktraceFilter @@ -14,13 +14,13 @@ if defined? Test::Unit::Util::BacktraceFilter @test = TestWithBacktrace.new @backtrace = [ './test/rails/benchmark_test.rb', './test/rails/dependencies.rb', '/opt/local/lib/ruby/kernel.rb' ] end - + test "test with backtrace should use the rails backtrace cleaner to clean" do Rails.stubs(:backtrace_cleaner).returns(stub(:clean)) Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil) @test.filter_backtrace(@backtrace) end - + test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do assert_nothing_raised do @test.filter_backtrace(@backtrace, '/opt/local/lib') diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb index 7bf420d4f2..1280d27ffe 100644 --- a/railties/test/boot_test.rb +++ b/railties/test/boot_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -require 'initializer' -require "#{File.dirname(__FILE__)}/../lib/generators/rails/app/templates/config/boot" +require 'rails/initializer' +require "#{File.dirname(__FILE__)}/../lib/rails/generators/rails/app/templates/config/boot" require 'rails/gem_dependency' class BootTest < Test::Unit::TestCase @@ -48,13 +48,6 @@ class BootTest < Test::Unit::TestCase Rails::GemBoot.any_instance.expects(:run).returns('result') assert_equal 'result', Rails.boot! end - - def test_run_loads_initializer_and_sets_load_path - boot = Rails::Boot.new - boot.expects(:load_initializer) - Rails::Initializer.expects(:run).with(:set_load_path) - boot.run - end end class VendorBootTest < Test::Unit::TestCase @@ -62,8 +55,8 @@ class VendorBootTest < Test::Unit::TestCase def test_load_initializer_requires_from_vendor_rails boot = VendorBoot.new - boot.expects(:require).with("#{RAILS_ROOT}/vendor/rails/railties/lib/initializer") - Rails::Initializer.expects(:run).with(:install_gem_spec_stubs) + boot.expects(:require).with("rails") + boot.expects(:install_gem_spec_stubs) Rails::GemDependency.expects(:add_frozen_gem_path) boot.load_initializer end @@ -76,7 +69,7 @@ class GemBootTest < Test::Unit::TestCase boot = GemBoot.new GemBoot.expects(:load_rubygems) boot.expects(:load_rails_gem) - boot.expects(:require).with('initializer') + boot.expects(:require).with('rails') boot.load_initializer end diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb index f11de087e3..1437e6d885 100644 --- a/railties/test/console_app_test.rb +++ b/railties/test/console_app_test.rb @@ -2,13 +2,14 @@ require 'abstract_unit' require 'action_controller' # console_app uses 'action_controller/integration' -unless defined? ApplicationController - class ApplicationController < ActionController::Base; end - ActionController::Base.session_store = nil -end +require 'rails/dispatcher' +require 'rails/console_app' -require 'dispatcher' -require '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=) @@ -27,9 +28,9 @@ if Test::Unit.respond_to?(:run=) def test_reload_should_fire_preparation_callbacks a = b = c = nil - Dispatcher.to_prepare { a = b = c = 1 } - Dispatcher.to_prepare { b = c = 2 } - Dispatcher.to_prepare { c = 3 } + 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! diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb index c7a7f77118..4d77a321a0 100644 --- a/railties/test/fcgi_dispatcher_test.rb +++ b/railties/test/fcgi_dispatcher_test.rb @@ -3,9 +3,13 @@ require 'abstract_unit' uses_gem "fcgi", "0.8.7" do require 'action_controller' -require 'fcgi_handler' +require 'rails/fcgi_handler' -Dispatcher.middleware.clear +module Rails + def self.application + ActionController::Routing::Routes + end +end class RailsFCGIHandlerTest < Test::Unit::TestCase def setup diff --git a/railties/test/fixtures/lib/generators/active_record/fixjour/fixjour_generator.rb b/railties/test/fixtures/lib/generators/active_record/fixjour/fixjour_generator.rb index 7a4edb8bcb..a7d079a1bc 100644 --- a/railties/test/fixtures/lib/generators/active_record/fixjour/fixjour_generator.rb +++ b/railties/test/fixtures/lib/generators/active_record/fixjour/fixjour_generator.rb @@ -1,4 +1,4 @@ -require 'generators/active_record' +require 'rails/generators/active_record' module ActiveRecord module Generators diff --git a/railties/test/fixtures/public/foo/bar.html b/railties/test/fixtures/public/foo/bar.html deleted file mode 100644 index 9a35646205..0000000000 --- a/railties/test/fixtures/public/foo/bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/bar.html
\ No newline at end of file diff --git a/railties/test/fixtures/public/foo/index.html b/railties/test/fixtures/public/foo/index.html deleted file mode 100644 index 497a2e898f..0000000000 --- a/railties/test/fixtures/public/foo/index.html +++ /dev/null @@ -1 +0,0 @@ -/foo/index.html
\ No newline at end of file diff --git a/railties/test/fixtures/public/index.html b/railties/test/fixtures/public/index.html deleted file mode 100644 index 525950ba6b..0000000000 --- a/railties/test/fixtures/public/index.html +++ /dev/null @@ -1 +0,0 @@ -/index.html
\ No newline at end of file diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index fdaef6d9cb..f226e184d1 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/app/app_generator' +require 'rails/generators/rails/app/app_generator' class ActionsTest < GeneratorsTestCase def setup diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 19e41c15c8..afc0585fba 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/app/app_generator' +require 'rails/generators/rails/app/app_generator' class AppGeneratorTest < GeneratorsTestCase @@ -55,14 +55,12 @@ class AppGeneratorTest < GeneratorsTestCase def test_dispatchers_are_not_added_by_default run_generator - assert_no_file "config.ru" 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 "config.ru" assert_file "public/dispatch.cgi" assert_file "public/dispatch.fcgi" end diff --git a/railties/test/generators/controller_generator_test.rb b/railties/test/generators/controller_generator_test.rb index 850b9e632d..56bc688ad0 100644 --- a/railties/test/generators/controller_generator_test.rb +++ b/railties/test/generators/controller_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/controller/controller_generator' +require 'rails/generators/rails/controller/controller_generator' class ControllerGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/generator_generator_test.rb b/railties/test/generators/generator_generator_test.rb index b1ebe5f1b5..aea3f4da51 100644 --- a/railties/test/generators/generator_generator_test.rb +++ b/railties/test/generators/generator_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/generator/generator_generator' +require 'rails/generators/rails/generator/generator_generator' class GeneratorGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/generators_test_helper.rb b/railties/test/generators/generators_test_helper.rb index 2a9d680c6a..d917812383 100644 --- a/railties/test/generators/generators_test_helper.rb +++ b/railties/test/generators/generators_test_helper.rb @@ -9,7 +9,7 @@ else end $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../lib" -require 'generators' +require 'rails/generators' require 'rubygems' $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../../../activerecord/lib" diff --git a/railties/test/generators/helper_generator_test.rb b/railties/test/generators/helper_generator_test.rb index 3d655016f1..f8bfc517a2 100644 --- a/railties/test/generators/helper_generator_test.rb +++ b/railties/test/generators/helper_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/helper/helper_generator' +require 'rails/generators/rails/helper/helper_generator' ObjectHelper = Class.new AnotherObjectHelperTest = Class.new diff --git a/railties/test/generators/integration_test_generator_test.rb b/railties/test/generators/integration_test_generator_test.rb index 190b28012c..6a504ceea2 100644 --- a/railties/test/generators/integration_test_generator_test.rb +++ b/railties/test/generators/integration_test_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/integration_test/integration_test_generator' +require 'rails/generators/rails/integration_test/integration_test_generator' class IntegrationTestGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/mailer_generator_test.rb b/railties/test/generators/mailer_generator_test.rb index 9e74859c3a..251474ad16 100644 --- a/railties/test/generators/mailer_generator_test.rb +++ b/railties/test/generators/mailer_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/mailer/mailer_generator' +require 'rails/generators/rails/mailer/mailer_generator' class MailerGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/metal_generator_test.rb b/railties/test/generators/metal_generator_test.rb index 97e892cefb..80bf342892 100644 --- a/railties/test/generators/metal_generator_test.rb +++ b/railties/test/generators/metal_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/metal/metal_generator' +require 'rails/generators/rails/metal/metal_generator' class MetalGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index a4335068e6..35172a8be4 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/migration/migration_generator' +require 'rails/generators/rails/migration/migration_generator' class MigrationGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 501c7d10c6..e073b11e1e 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/model/model_generator' +require 'rails/generators/rails/model/model_generator' class ModelGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/named_base_test.rb b/railties/test/generators/named_base_test.rb index 3a5c58ab32..98cbf9b8f6 100644 --- a/railties/test/generators/named_base_test.rb +++ b/railties/test/generators/named_base_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/scaffold_controller/scaffold_controller_generator' +require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' # Mock out what we need from AR::Base. module ActiveRecord diff --git a/railties/test/generators/observer_generator_test.rb b/railties/test/generators/observer_generator_test.rb index a556731e16..6fed2998dd 100644 --- a/railties/test/generators/observer_generator_test.rb +++ b/railties/test/generators/observer_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/observer/observer_generator' +require 'rails/generators/rails/observer/observer_generator' class ObserverGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/performance_test_generator_test.rb b/railties/test/generators/performance_test_generator_test.rb index 74c9c20c4c..d19128f79a 100644 --- a/railties/test/generators/performance_test_generator_test.rb +++ b/railties/test/generators/performance_test_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/performance_test/performance_test_generator' +require 'rails/generators/rails/performance_test/performance_test_generator' class PerformanceTestGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/plugin_generator_test.rb b/railties/test/generators/plugin_generator_test.rb index 3982586bc3..f5b8b6ffb6 100644 --- a/railties/test/generators/plugin_generator_test.rb +++ b/railties/test/generators/plugin_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/plugin/plugin_generator' +require 'rails/generators/rails/plugin/plugin_generator' class PluginGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 876ddbf84e..dcae81c204 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/resource/resource_generator' +require 'rails/generators/rails/resource/resource_generator' class ResourceGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index 834e43e776..f555725eb8 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/scaffold_controller/scaffold_controller_generator' +require 'rails/generators/rails/scaffold_controller/scaffold_controller_generator' class ScaffoldControllerGeneratorTest < GeneratorsTestCase @@ -100,7 +100,7 @@ class ScaffoldControllerGeneratorTest < GeneratorsTestCase def test_error_is_shown_if_orm_does_not_provide_interface error = capture(:stderr){ run_generator ["User", "--orm=unknown"] } assert_equal "Could not load Unknown::Generators::ActiveModel, skipping controller. " << - "Error: no such file to load -- generators/unknown.\n", error + "Error: no such file to load -- rails/generators/unknown.\n", error end protected diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index 63559a8a01..c0652c034f 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/scaffold/scaffold_generator' +require 'rails/generators/rails/scaffold/scaffold_generator' class ScaffoldGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/session_migration_generator_test.rb b/railties/test/generators/session_migration_generator_test.rb index 293b903b87..34fb996b7f 100644 --- a/railties/test/generators/session_migration_generator_test.rb +++ b/railties/test/generators/session_migration_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/session_migration/session_migration_generator' +require 'rails/generators/rails/session_migration/session_migration_generator' class SessionMigrationGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators/stylesheets_generator_test.rb b/railties/test/generators/stylesheets_generator_test.rb index 02082d5cc8..15263d4bb8 100644 --- a/railties/test/generators/stylesheets_generator_test.rb +++ b/railties/test/generators/stylesheets_generator_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'generators/generators_test_helper' -require 'generators/rails/stylesheets/stylesheets_generator' +require 'rails/generators/rails/stylesheets/stylesheets_generator' class StylesheetsGeneratorTest < GeneratorsTestCase diff --git a/railties/test/generators_test.rb b/railties/test/generators_test.rb index 4cc0b33521..7e6b7b183c 100644 --- a/railties/test/generators_test.rb +++ b/railties/test/generators_test.rb @@ -1,6 +1,6 @@ require File.join(File.dirname(__FILE__), 'generators', 'generators_test_helper') -require 'generators/rails/model/model_generator' -require 'generators/test_unit/model/model_generator' +require 'rails/generators/rails/model/model_generator' +require 'rails/generators/test_unit/model/model_generator' require 'mocha' class GeneratorsTest < GeneratorsTestCase diff --git a/railties/test/initializer/boot_test.rb b/railties/test/initializer/boot_test.rb new file mode 100644 index 0000000000..5ee3c45b21 --- /dev/null +++ b/railties/test/initializer/boot_test.rb @@ -0,0 +1,16 @@ +require "isolation/abstract_unit" + +module BootTests + class GemBooting < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + # build_app + # boot_rails + end + + test "booting rails sets the load paths correctly" do + # This test is pending reworking the boot process + end + end +end
\ No newline at end of file diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 68feba058e..1852fea4df 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -1,9 +1,14 @@ -require "initializer/test_helper" +require "isolation/abstract_unit" module InitializerTests class PathsTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation + def setup + build_app + boot_rails + end + test "rails does not initialize with ruby version 1.8.1" do assert_rails_does_not_boot "1.8.1" end diff --git a/railties/test/initializer/install_gem_spec_stubs_test.rb b/railties/test/initializer/install_gem_spec_stubs_test.rb deleted file mode 100644 index cfb12d7405..0000000000 --- a/railties/test/initializer/install_gem_spec_stubs_test.rb +++ /dev/null @@ -1,86 +0,0 @@ -require "initializer/test_helper" - -module InitializerTests - class GemSpecStubsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - $stderr = StringIO.new - end - - test "user has an old boot.rb (defined by having no Rails.vendor_rails?)" do - class << Rails - undef vendor_rails? - end - - assert_stderr(/outdated/) do - assert_raises(SystemExit) do - Rails::Initializer.run { |c| c.frameworks = [] } - end - end - end - - test "requires rubygems" do - Kernel.module_eval do - alias old_require require - def require(name) - $rubygems_required = true if name == "rubygems" - old_require(name) - end - end - - Rails.vendor_rails = true - Rails::Initializer.run { |c| c.frameworks = [] } - assert $rubygems_required - end - - # Pending until we're further along - # test "does not fail if rubygems does not exist" do - # Kernel.module_eval do - # alias old_require require - # def require(name) - # raise LoadError if name == "rubygems" - # old_require(name) - # end - # end - # - # assert_nothing_raised do - # Rails::Initializer.run { |c| c.frameworks = [] } - # end - # end - - test "adds fake Rubygems stubs if a framework is not loaded in Rubygems and we've vendored" do - Rails.vendor_rails = true - - Rails::Initializer.run { |c| c.frameworks = [] } - - %w(rails activesupport activerecord actionpack actionmailer activeresource).each do |stub| - gem_spec = Gem.loaded_specs[stub] - assert_equal Gem::Version.new(Rails::VERSION::STRING), gem_spec.version - assert_equal stub, gem_spec.name - assert_equal "", gem_spec.loaded_from - end - end - - test "doesn't replace gem specs that are already loaded" do - Rails.vendor_rails = true - - Gem.loaded_specs["rails"] = Gem::Specification.new do |s| - s.name = "rails" - s.version = Rails::VERSION::STRING - s.loaded_from = "/foo/bar/baz" - end - - Rails::Initializer.run { |c| c.frameworks = [] } - - assert_equal "/foo/bar/baz", Gem.loaded_specs["rails"].loaded_from - - %w(activesupport activerecord actionpack actionmailer activeresource).each do |stub| - gem_spec = Gem.loaded_specs[stub] - assert_equal Gem::Version.new(Rails::VERSION::STRING), gem_spec.version - assert_equal stub, gem_spec.name - assert_equal "", gem_spec.loaded_from - end - 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 8de3161546..a4264bc31c 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -1,26 +1,36 @@ -require "initializer/test_helper" +require "isolation/abstract_unit" class PathsTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation - def self.setup + def setup + build_app + boot_rails Rails::Initializer.run do |config| config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] + config.after_initialize do + ActionController::Base.session_store = nil + end end - end - - def setup @paths = Rails::Initializer.default.config.paths end def root(*path) - File.expand_path(File.join(File.dirname(__FILE__), "root", *path)) + app_path(*path).to_s end def assert_path(paths, *dir) assert_equal [root(*dir)], paths.paths end + def assert_in_load_path(*path) + assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + + def assert_not_in_load_path(*path) + assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + test "booting up Rails yields a valid paths object" do assert_path @paths.app, "app" assert_path @paths.app.metals, "app", "metal" @@ -36,8 +46,7 @@ class PathsTest < Test::Unit::TestCase assert_path @paths.config.locales, "config", "locales" assert_path @paths.config.environments, "config", "environments" - assert_equal Pathname.new(File.dirname(__FILE__)).join("root", "app", "controllers").expand_path, - Pathname.new(@paths.app.controllers.to_a.first).expand_path + assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, Pathname.new(@paths.app.controllers.to_a[1]).expand_path end @@ -53,24 +62,16 @@ class PathsTest < Test::Unit::TestCase assert_equal "#{RAILS_ENV}.rb", @paths.config.environments.glob end - def assert_in_load_path(*path) - assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" - end - - def assert_not_in_load_path(*path) - assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" - end - test "load path includes each of the paths in config.paths as long as the directories exist" do assert_in_load_path "app" assert_in_load_path "app", "controllers" - assert_in_load_path "app", "metal" assert_in_load_path "app", "models" assert_in_load_path "app", "helpers" assert_in_load_path "lib" assert_in_load_path "vendor" assert_not_in_load_path "app", "views" + assert_not_in_load_path "app", "metal" assert_not_in_load_path "app", "services" assert_not_in_load_path "config" assert_not_in_load_path "config", "locales" diff --git a/railties/test/initializer/root/app/controllers/.keep b/railties/test/initializer/root/app/controllers/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/app/controllers/.keep +++ /dev/null diff --git a/railties/test/initializer/root/app/helpers/.keep b/railties/test/initializer/root/app/helpers/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/app/helpers/.keep +++ /dev/null diff --git a/railties/test/initializer/root/app/metal/.keep b/railties/test/initializer/root/app/metal/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/app/metal/.keep +++ /dev/null diff --git a/railties/test/initializer/root/app/models/.keep b/railties/test/initializer/root/app/models/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/app/models/.keep +++ /dev/null diff --git a/railties/test/initializer/root/app/views/.keep b/railties/test/initializer/root/app/views/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/app/views/.keep +++ /dev/null diff --git a/railties/test/initializer/root/config/database.yml b/railties/test/initializer/root/config/database.yml deleted file mode 100644 index ce3356be0c..0000000000 --- a/railties/test/initializer/root/config/database.yml +++ /dev/null @@ -1,4 +0,0 @@ -development: - adapter: sqlite3 - database: db/railties.db - timeout: 5000
\ No newline at end of file diff --git a/railties/test/initializer/root/config/environments/.keep b/railties/test/initializer/root/config/environments/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/config/environments/.keep +++ /dev/null diff --git a/railties/test/initializer/root/config/locales/.keep b/railties/test/initializer/root/config/locales/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/config/locales/.keep +++ /dev/null diff --git a/railties/test/initializer/root/config/routes.rb b/railties/test/initializer/root/config/routes.rb deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/config/routes.rb +++ /dev/null diff --git a/railties/test/initializer/root/lib/.keep b/railties/test/initializer/root/lib/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/lib/.keep +++ /dev/null diff --git a/railties/test/initializer/root/tmp/.keep b/railties/test/initializer/root/tmp/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/tmp/.keep +++ /dev/null diff --git a/railties/test/initializer/root/tmp/cache/.keep b/railties/test/initializer/root/tmp/cache/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/tmp/cache/.keep +++ /dev/null diff --git a/railties/test/initializer/root/vendor/.keep b/railties/test/initializer/root/vendor/.keep deleted file mode 100644 index e69de29bb2..0000000000 --- a/railties/test/initializer/root/vendor/.keep +++ /dev/null diff --git a/railties/test/initializer/test_helper.rb b/railties/test/initializer/test_helper.rb deleted file mode 100644 index f6a2547efc..0000000000 --- a/railties/test/initializer/test_helper.rb +++ /dev/null @@ -1,51 +0,0 @@ -# This is a test helper file that simulates a rails application being -# boot from scratch in vendored mode. This file should really only be -# required in test cases that use the isolation helper so that requires -# can be reset correctly. -RAILS_ROOT = "#{File.dirname(__FILE__)}/root" -RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") - -require 'rubygems' -gem 'rack', '~> 1.0.0' - -require "test/unit" -# We are purposely avoiding adding things to the load path to catch bugs that only happen in the genuine article -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" -require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" - -class Test::Unit::TestCase - extend ActiveSupport::Testing::Declarative - - def assert_stderr(match) - $stderr = StringIO.new - yield - $stderr.rewind - err = $stderr.read - assert_match match, err - ensure - $stderr = STDERR - end -end - -# Fake boot.rb -module Rails - class << self - attr_accessor :vendor_rails - - def vendor_rails? - @vendor_rails - end - - def boot! - # Require the initializer - require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer" - # Run the initializer the same way boot.rb does it - Rails::Initializer.run(:install_gem_spec_stubs) - Rails::GemDependency.add_frozen_gem_path - Rails::Initializer.run(:set_load_path) - end - end -end - -# All that for this: -Rails.boot! diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 5bbd060962..b67db9c835 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' -require 'initializer' -require 'generators' +require 'rails/initializer' +require 'rails/generators' require 'action_view' require 'action_mailer' diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb new file mode 100644 index 0000000000..869e8429cf --- /dev/null +++ b/railties/test/isolation/abstract_unit.rb @@ -0,0 +1,131 @@ +# Note: +# It is important to keep this file as light as possible +# the goal for tests that require this is to test booting up +# rails from an empty state, so anything added here could +# hide potential failures +# +# It is also good to know what is the bare minimum to get +# Rails booted up. + +# TODO: Remove rubygems when possible +require 'rubygems' +require 'test/unit' + +# TODO: Remove setting this magic constant +RAILS_FRAMEWORK_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../../..") + +# These files do not require any others and are needed +# to run the tests +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/isolation" +require "#{RAILS_FRAMEWORK_ROOT}/activesupport/lib/active_support/testing/declarative" + +module TestHelpers + module Paths + module_function + + def tmp_path(*args) + File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. tmp] + args)) + end + + def app_path(*args) + tmp_path(*%w[app] + args) + end + end + + module Rack + def extract_body(response) + "".tap do |body| + response[2].each {|chunk| body << chunk } + end + end + + def get(path) + @app.call(::Rack::MockRequest.env_for(path)) + end + + def assert_welcome(resp) + assert_equal 200, resp[0] + assert resp[1]["Content-Type"] = "text/html" + assert extract_body(resp).match(/Welcome aboard/) + end + + def assert_success(resp) + assert_equal 202, resp[0] + end + + def assert_missing(resp) + assert_equal 404, resp[0] + end + + def assert_header(key, value, resp) + assert_equal value, resp[1][key.to_s] + end + + def assert_body(expected, resp) + assert_equal expected, extract_body(resp) + end + end + + module Generation + def build_app(options = {}) + FileUtils.rm_rf(app_path) + FileUtils.cp_r(tmp_path('app_template'), app_path) + + # Delete the initializers unless requested + unless options[:initializers] + Dir["#{app_path}/config/initializers/*.rb"].each do |initializer| + File.delete(initializer) + end + end + + environment = File.read("#{app_path}/config/environment.rb") + if environment =~ /(\n\s*end\s*)\Z/ + File.open("#{app_path}/config/environment.rb", 'w') do |f| + f.puts $` + %'\nconfig.action_controller.session = { :key => "_myapp_session", :secret => "bac838a849c1d5c4de2e6a50af826079" }\n' + $1 + end + end + end + + def app_file(path, contents) + File.open(app_path(path), 'w') do |f| + f.puts contents + end + end + + def controller(name, contents) + app_file("app/controllers/#{name}_controller.rb", contents) + end + + def boot_rails + # TMP mega hax to prevent boot.rb from actually booting + Object.class_eval <<-RUBY, __FILE__, __LINE__+1 + module Rails + Initializer = 'lol' + require "#{app_path}/config/boot" + remove_const(:Initializer) + booter = VendorBoot.new + booter.run + end + RUBY + end + end +end + +class Test::Unit::TestCase + include TestHelpers::Paths + include TestHelpers::Rack + include TestHelpers::Generation + extend ActiveSupport::Testing::Declarative +end + +# Create a scope and build a fixture rails app +Module.new do + extend TestHelpers::Paths + # Build a rails app + if File.exist?(tmp_path) + FileUtils.rm_rf(tmp_path) + end + + FileUtils.mkdir(tmp_path) + `#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/bin/rails #{tmp_path('app_template')}` +end diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb index c79a819a76..6864254e4c 100644 --- a/railties/test/metal_test.rb +++ b/railties/test/metal_test.rb @@ -1,5 +1,5 @@ require 'abstract_unit' -require 'initializer' +require 'rails/initializer' class MetalTest < Test::Unit::TestCase def test_metals_should_return_list_of_found_metal_apps diff --git a/railties/test/new_initializer_test.rb b/railties/test/new_initializer_test.rb index 8d9ef7bee3..67b66fb088 100644 --- a/railties/test/new_initializer_test.rb +++ b/railties/test/new_initializer_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'active_support/ruby/shim' -require 'initializer' +require 'rails/initializer' class InitializerRunnerTest < ActiveSupport::TestCase diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb index 893095fa66..93004e0ddf 100644 --- a/railties/test/plugin_test_helper.rb +++ b/railties/test/plugin_test_helper.rb @@ -3,7 +3,7 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" require 'test/unit' require 'active_support' -require 'initializer' +require 'rails/initializer' require 'abstract_unit' # We need to set RAILS_ROOT if it isn't already set diff --git a/railties/test/rack_static_test.rb b/railties/test/rack_static_test.rb deleted file mode 100644 index ad673f6f19..0000000000 --- a/railties/test/rack_static_test.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'abstract_unit' - -require 'action_controller' -require 'rails/rack' - -class RackStaticTest < ActiveSupport::TestCase - def setup - FileUtils.cp_r "#{RAILS_ROOT}/fixtures/public", "#{RAILS_ROOT}/public" - end - - def teardown - FileUtils.rm_rf "#{RAILS_ROOT}/public" - end - - DummyApp = lambda { |env| - [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] - } - App = Rails::Rack::Static.new(DummyApp) - - test "serves dynamic content" do - assert_equal "Hello, World!", get("/nofile") - end - - test "serves static index at root" do - assert_equal "/index.html", get("/index.html") - assert_equal "/index.html", get("/index") - assert_equal "/index.html", get("/") - end - - test "serves static file in directory" do - assert_equal "/foo/bar.html", get("/foo/bar.html") - assert_equal "/foo/bar.html", get("/foo/bar/") - assert_equal "/foo/bar.html", get("/foo/bar") - end - - test "serves static index file in directory" do - assert_equal "/foo/index.html", get("/foo/index.html") - assert_equal "/foo/index.html", get("/foo/") - assert_equal "/foo/index.html", get("/foo") - end - - private - def get(path) - Rack::MockRequest.new(App).request("GET", path).body - end -end diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 6a60908859..99cf9168e1 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -1,6 +1,5 @@ require 'abstract_unit' require 'action_controller' -require 'action_controller/testing/process' require 'rails/info' require 'rails/info_controller' diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 568e2a9972..dcf9966c0d 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -80,11 +80,11 @@ EOS end end - def test_middleware_property - assert property_defined?('Middleware') - end - def test_html_includes_middleware + Rails::Info.module_eval do + property 'Middleware', ['Rack::Lock', 'Rack::Static'] + end + html = Rails::Info.to_html assert html.include?('<tr><td class="name">Middleware</td>') properties.value_for('Middleware').each do |value| |