diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-09-30 22:27:02 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-09-30 22:27:02 +0100 |
commit | dd2779e1b83b4d867d47dd286ec0c919f5df12a9 (patch) | |
tree | 6e52ea0a329c24429f4d1d41b065e082f0ed6baa /railties/test/initializer | |
parent | 329b14aa8fdd291a00d17ba12c2e0ab4c3a157cc (diff) | |
parent | 420004e030e96f2ace6e27fd622c90ee9e986677 (diff) | |
download | rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.gz rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.tar.bz2 rails-dd2779e1b83b4d867d47dd286ec0c919f5df12a9.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'railties/test/initializer')
18 files changed, 40 insertions, 159 deletions
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! |