From dcba6e114884d993089fc1aa47bfaa7c4258a536 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 1 Jun 2009 13:44:43 -0700 Subject: Fix initializer i18n path test --- railties/test/initializer_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index bdda319916..987a5ada86 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -312,6 +312,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase 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"), "my/test/locale.yml", "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } -- cgit v1.2.3 From 41a94048e55e082f373e19d9fcee311860aaba9e Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Sat, 6 Jun 2009 17:59:33 -0400 Subject: Fix several issues with the 2.3.2 gem loader. Incorporates the following: - migrates back small change to gems:build:force from bfc1609a501fc3ed442685819de5bcdb5fbada1c to finish closing #2266. - unrolls to_proc calls in gems.rake, to match the change in master. - fixes #2722 by passing the options hash to dependencies during build. (includes a test) - fixes #2721 by loading the specification directly in from_directory_name. Adds an option to opt-out of specification loading when needed (in gems:refresh_specs, for instance). Includes tests. - fixes #2679 by refreshing specs for all frozen gems rather than just gems loaded from the environment. - fixes #2678 by passing the options hash to dependencies during unpack. Signed-off-by: Michael Koziarski --- railties/test/gem_dependency_test.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index ff27af5572..195494a926 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -166,8 +166,14 @@ class GemDependencyTest < Test::Unit::TestCase dummy_gem.unpack end + def test_gem_from_directory_name_attempts_to_load_specification + assert_raises RuntimeError do + dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1') + end + end + def test_gem_from_directory_name - dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1') + dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem-1.1', false) assert_equal 'dummy-gem', dummy_gem.name assert_equal '= 1.1', dummy_gem.version_requirements.to_s end @@ -187,4 +193,12 @@ class GemDependencyTest < Test::Unit::TestCase assert_equal false, Rails::GemDependency.new("dummy-gem-j").built? end + def test_gem_build_passes_options_to_dependencies + start_gem = Rails::GemDependency.new("dummy-gem-g") + dep_gem = Rails::GemDependency.new("dummy-gem-f") + start_gem.stubs(:dependencies).returns([dep_gem]) + dep_gem.expects(:build).with({ :force => true }).once + start_gem.build(:force => true) + end + end -- cgit v1.2.3 From d7e0cb05cc8adad430d0e97efef1608eef58db80 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Tue, 9 Jun 2009 12:26:52 -0400 Subject: Fix incorrect specification path in GemDependency#from_directory_name Signed-off-by: Michael Koziarski --- railties/test/gem_dependency_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 195494a926..70f4496685 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -178,6 +178,13 @@ class GemDependencyTest < Test::Unit::TestCase assert_equal '= 1.1', dummy_gem.version_requirements.to_s end + def test_gem_from_directory_name_loads_specification_successfully + assert_nothing_raised do + dummy_gem = Rails::GemDependency.from_directory_name(File.join(Rails::GemDependency.unpacked_path, 'dummy-gem-g-1.0.0')) + assert_not_nil dummy_gem.specification + end + end + def test_gem_from_invalid_directory_name assert_raises RuntimeError do dummy_gem = Rails::GemDependency.from_directory_name('dummy-gem') -- cgit v1.2.3 From 7b1f483fda4fc8e4fc931649364a211a9f9d945f Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 15 Jun 2009 16:14:45 -0700 Subject: Get all of rake tests to pass --- railties/test/rails_info_controller_test.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index ab31f3a487..3deb81965c 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'action_controller' -require 'action_controller/testing/process' +require 'action_controller/testing/process2' require 'rails/info' require 'rails/info_controller' @@ -9,6 +9,12 @@ ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' end +module ActionController + class Base + include ActionController::Testing + end +end + class InfoControllerTest < ActionController::TestCase tests Rails::InfoController -- cgit v1.2.3 From 85f2f34d5ec8ccdea4755740b810ac514d9f3dd9 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 16 Jun 2009 16:29:33 -0700 Subject: Remove a stray process2 require --- railties/test/rails_info_controller_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 3deb81965c..6a60908859 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -1,6 +1,6 @@ require 'abstract_unit' require 'action_controller' -require 'action_controller/testing/process2' +require 'action_controller/testing/process' require 'rails/info' require 'rails/info_controller' -- cgit v1.2.3 From 805369c8c84a15115e4f7a2fe9b3d4de07e2c7f2 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 18 Jun 2009 12:43:43 -0700 Subject: Starting to write the new initializer --- railties/test/new_initializer_test.rb | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 railties/test/new_initializer_test.rb (limited to 'railties/test') diff --git a/railties/test/new_initializer_test.rb b/railties/test/new_initializer_test.rb new file mode 100644 index 0000000000..166e7e613f --- /dev/null +++ b/railties/test/new_initializer_test.rb @@ -0,0 +1,118 @@ +require 'abstract_unit' +require 'active_support/ruby/shim' + +module Rails + class Initializer + class Error < StandardError ; end + class Runner + def initialize + @names = {} + @initializers = [] + end + + def add(name, options = {}, &block) + if other = options[:before] || options[:after] and !@names[other] + raise Error, "The #{other.inspect} initializer does not exist" + end + + Class.new(Initializer, &block).new.tap do |initializer| + index = if options[:before] + @initializers.index(@names[other]) + elsif options[:after] + @initializers.index(@names[other]) + 1 + else + -1 + end + + @initializers.insert(index, initializer) + @names[name] = initializer + end + end + + def run + @initializers.each { |init| init.run } + end + end + + def self.run(&blk) + define_method(:run, &blk) + end + end +end + + +class InitializerRunnerTest < ActiveSupport::TestCase + + def setup + @runner = Rails::Initializer::Runner.new + end + + test "A new runner can be created" do + assert @runner + end + + test "You can create initializers" do + init = @runner.add :foo do + + end + + assert_kind_of Rails::Initializer, init + 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 + +end + -- cgit v1.2.3 From 99b8248f6e83b87fc7f09e43a11c68aebcb2712e Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 18 Jun 2009 12:51:15 -0700 Subject: Initial initializer impl --- railties/test/new_initializer_test.rb | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'railties/test') diff --git a/railties/test/new_initializer_test.rb b/railties/test/new_initializer_test.rb index 166e7e613f..ffa10060ce 100644 --- a/railties/test/new_initializer_test.rb +++ b/railties/test/new_initializer_test.rb @@ -11,20 +11,15 @@ module Rails end def add(name, options = {}, &block) - if other = options[:before] || options[:after] and !@names[other] - raise Error, "The #{other.inspect} initializer does not exist" + # If :before or :after is specified, set the index to the right spot + if other = options[:before] || options[:after] + raise Error, "The #{other.inspect} initializer does not exist" unless @names[other] + index = @initializers.index(@names[other]) + index += 1 if options[:after] end Class.new(Initializer, &block).new.tap do |initializer| - index = if options[:before] - @initializers.index(@names[other]) - elsif options[:after] - @initializers.index(@names[other]) + 1 - else - -1 - end - - @initializers.insert(index, initializer) + @initializers.insert(index || -1, initializer) @names[name] = initializer end end -- cgit v1.2.3 From a3309e4d70101ec1b32064a99042622c43619d09 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 18 Jun 2009 17:44:35 -0700 Subject: Started making progress on implementing a new initializer. Class.any_instance.expects(:require).raises(LoadError) ... w0t --- railties/test/initializer_test.rb | 55 ++++++----- railties/test/new_initializer_test.rb | 174 ++++++++++++++++++++++------------ 2 files changed, 140 insertions(+), 89 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 987a5ada86..744b0d32d1 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -38,14 +38,15 @@ class Initializer_eager_loading_Test < Test::Unit::TestCase @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.new(@config) - @initializer.set_load_path - @initializer.set_autoload_paths + @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.load_application_classes + @initializer.run(:load_application_classes) end end end @@ -62,7 +63,7 @@ class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::Te assert_nil $test_after_initialize_block1 assert_nil $test_after_initialize_block2 - Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) + config.expects(:gems_dependencies_loaded).returns(true) Rails::Initializer.run(:after_initialize, config) end @@ -92,7 +93,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit:: end assert_nil $test_after_initialize_block1 - Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) + config.expects(:gems_dependencies_loaded).returns(true) Rails::Initializer.run(:after_initialize, config) end @@ -114,68 +115,65 @@ 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) - @config.stubs(:framework_root_path).returns('') + Rails::Initializer.run(:set_root_path, @config) end def test_minimal - expected = %w( - /railties - /railties/lib - /activesupport/lib - ) - assert_equal expected, @config.framework_paths + 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' + assert_framework_path "actionpack/lib" @config.frameworks = [:action_view] - assert_framework_path '/actionpack/lib' + 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" + assert_framework_path "#{framework.to_s.gsub('_', '')}/lib" end end def test_unknown_framework_raises_error @config.frameworks << :action_foo - initializer = Rails::Initializer.new @config - initializer.expects(:require).raises(LoadError) + + Class.any_instance.expects(:require).raises(LoadError) assert_raise RuntimeError do - initializer.send :require_frameworks + @initializer.run(:require_frameworks) end end def test_action_mailer_load_paths_set_only_if_action_mailer_in_use @config.frameworks = [:action_controller] - initializer = Rails::Initializer.new @config - initializer.send :require_frameworks + @initializer.config = @config + @initializer.run :require_frameworks assert_nothing_raised NameError do - initializer.send :load_view_paths + @initializer.run :load_view_paths end end def test_action_controller_load_paths_set_only_if_action_controller_in_use @config.frameworks = [] - initializer = Rails::Initializer.new @config - initializer.send :require_frameworks + @initializer.run :require_frameworks assert_nothing_raised NameError do - initializer.send :load_view_paths + @initializer.run :load_view_paths end end protected def assert_framework_path(path) - assert @config.framework_paths.include?(path), + assert @config.framework_paths.include?("#{@config.framework_root_path}/#{path}"), "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>" end end @@ -187,14 +185,15 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase @configuration = Rails::Configuration.new @configuration.frameworks -= [:action_mailer] @configuration.plugin_paths << plugin_fixture_root_path - @initializer = Rails::Initializer.new(@configuration) + @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.load_plugins + @initializer.run :load_plugins assert_equal [], @initializer.loaded_plugins end diff --git a/railties/test/new_initializer_test.rb b/railties/test/new_initializer_test.rb index ffa10060ce..8d9ef7bee3 100644 --- a/railties/test/new_initializer_test.rb +++ b/railties/test/new_initializer_test.rb @@ -1,113 +1,165 @@ require 'abstract_unit' require 'active_support/ruby/shim' - -module Rails - class Initializer - class Error < StandardError ; end - class Runner - def initialize - @names = {} - @initializers = [] - end - - def add(name, options = {}, &block) - # If :before or :after is specified, set the index to the right spot - if other = options[:before] || options[:after] - raise Error, "The #{other.inspect} initializer does not exist" unless @names[other] - index = @initializers.index(@names[other]) - index += 1 if options[:after] - end - - Class.new(Initializer, &block).new.tap do |initializer| - @initializers.insert(index || -1, initializer) - @names[name] = initializer - end - end - - def run - @initializers.each { |init| init.run } - end - end - - def self.run(&blk) - define_method(:run, &blk) - end - end -end - +require '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 "You can create initializers" do - init = @runner.add :foo do - - end - - assert_kind_of Rails::Initializer, init - 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 - -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 -- cgit v1.2.3 From f2aea4d3eac467b85a63593ba7e2de28b2a2eb0a Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 19 Jun 2009 11:13:38 -0700 Subject: Get initializer_test.rb to pass with the new initializer. --- railties/test/initializer_test.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 744b0d32d1..5caa5858a4 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -194,20 +194,20 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase 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 [], @initializer.loaded_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, @initializer.loaded_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], @initializer.loaded_plugins, failure_tip + 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 @@ -215,7 +215,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase 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], @initializer.loaded_plugins, failure_tip + 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 @@ -223,7 +223,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase 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], @initializer.loaded_plugins, failure_tip + 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 @@ -231,7 +231,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase 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, @initializer.loaded_plugins, failure_tip + assert_plugins plugin_names, @configuration.loaded_plugins, failure_tip end def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error @@ -250,7 +250,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase 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, @initializer.loaded_plugins, failure_tip + 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 @@ -264,7 +264,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase 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.add_plugin_load_paths + @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')) @@ -273,8 +273,8 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase private def load_plugins! - @initializer.add_plugin_load_paths - @initializer.load_plugins + @initializer.run(:add_plugin_load_paths) + @initializer.run(:load_plugins) end end @@ -314,7 +314,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase 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"), "my/test/locale.yml", - "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } + "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /\.\./ ? File.expand_path(path) : path } end def test_setting_another_default_locale -- cgit v1.2.3 From 9cfd1d44915f4615bbb760198cd01bf4dfc69f5a Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 19 Jun 2009 11:27:24 -0700 Subject: Get more tests to pass --- railties/test/generator_lookup_test.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generator_lookup_test.rb b/railties/test/generator_lookup_test.rb index b650f304ed..b67087e5ea 100644 --- a/railties/test/generator_lookup_test.rb +++ b/railties/test/generator_lookup_test.rb @@ -7,9 +7,11 @@ class GeneratorLookupTest < Test::Unit::TestCase # 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 += @fixture_dirs.map{|fd| plugin_fixture_path(fd)} - @initializer = Rails::Initializer.new(@configuration) - @initializer.add_plugin_load_paths - @initializer.load_plugins + @initializer = Rails::Initializer.default + @initializer.config = @configuration + @initializer.run(:add_plugin_load_paths) + @initializer.run(:load_plugins) + @initializer.run(:set_root_path) load 'rails_generator.rb' require 'rails_generator/scripts' end -- cgit v1.2.3 From 30baaac5465a352e78dac6330407a7b3460db180 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 19 Jun 2009 11:41:02 -0700 Subject: Fix the default frameworks --- railties/test/plugin_loader_test.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index c647d7b478..873e000222 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -20,7 +20,8 @@ class TestPluginLoader < Test::Unit::TestCase @configuration = Rails::Configuration.new @configuration.plugin_paths << plugin_fixture_root_path - @initializer = Rails::Initializer.new(@configuration) + @initializer = Rails::Initializer.default + @initializer.config = @configuration @valid_plugin_path = plugin_fixture_path('default/stubby') @empty_plugin_path = plugin_fixture_path('default/empty') -- cgit v1.2.3 From 9d398f48275a2740b0c7545da207ac2ebbe012ec Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 19 Jun 2009 12:12:56 -0700 Subject: Got all the railties tests to pass, rails must boot! --- railties/test/plugin_locator_test.rb | 3 ++- railties/test/plugin_test.rb | 3 ++- railties/test/rails_generator_test.rb | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index 855ac7d82f..da1548dee1 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -27,7 +27,8 @@ class PluginFileSystemLocatorTest < Test::Unit::TestCase # 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.new(@configuration) + @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 a6c390a45a..ae03ea4662 100644 --- a/railties/test/plugin_test.rb +++ b/railties/test/plugin_test.rb @@ -2,7 +2,8 @@ require 'plugin_test_helper' class PluginTest < Test::Unit::TestCase def setup - @initializer = Rails::Initializer.new(Rails::Configuration.new) + @initializer = Rails::Initializer.default + @initializer.config = Rails::Configuration.new @valid_plugin_path = plugin_fixture_path('default/stubby') @empty_plugin_path = plugin_fixture_path('default/empty') @gemlike_plugin_path = plugin_fixture_path('default/gemlike') diff --git a/railties/test/rails_generator_test.rb b/railties/test/rails_generator_test.rb index b2fc2f585d..38bd90dcc1 100644 --- a/railties/test/rails_generator_test.rb +++ b/railties/test/rails_generator_test.rb @@ -50,6 +50,9 @@ class RailsGeneratorTest < Test::Unit::TestCase def setup ActiveRecord::Base.pluralize_table_names = true + @initializer = Rails::Initializer.default + @initializer.config = Rails.configuration + @initializer.run(:set_root_path) end def test_sources -- cgit v1.2.3 From 728e3b4047a55ead0f5fbb3bc57095b2b273352b Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 26 Jun 2009 11:21:17 -0700 Subject: Simple initial Paths impl --- railties/test/paths_test.rb | 68 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 railties/test/paths_test.rb (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb new file mode 100644 index 0000000000..0da31b467a --- /dev/null +++ b/railties/test/paths_test.rb @@ -0,0 +1,68 @@ +require 'abstract_unit' + +module Rails + class Application + class Path + attr_accessor :path, :root #, :glob, :load_once, :eager + + def initialize(path, root = nil) + @children = {} + @path = path + @root = root || self + end + + def method_missing(id, *args) + name = id.to_s + + if name =~ /^(.*)=$/ + @children[$1] = Path.new(args.first, @root) + elsif path = @children[name] + path + else + super + end + end + + def path + @path.index('/') == 0 ? @path : File.join(@root.path, @path) + end + + alias to_s path + end + end +end + +class PathsTest < ActiveSupport::TestCase + + def setup + @root = Rails::Application::Path.new("/foo/bar") + end + + test "the paths object is initialized with the root path" do + root = Rails::Application::Path.new("/fiz/baz") + assert_equal "/fiz/baz", root.to_s + end + + test "creating a root level path" do + @root.app = "/foo/bar" + assert_equal "/foo/bar", @root.app.to_s + end + + test "relative paths are relative to the paths root" do + @root.app = "app" + assert_equal "/foo/bar/app", @root.app.to_s + end + + test "creating a child level path" do + @root.app = "/foo/bar" + @root.app.models = "/foo/bar/baz" + assert_equal "/foo/bar/baz", @root.app.models.to_s + end + + test "child level paths are relative from the root" do + @root.app = "/app" + @root.app.models = "baz" + + assert_equal "/foo/bar/baz", @root.app.models.to_s + end +end \ No newline at end of file -- cgit v1.2.3 From b0774281ef4008f2c249b1e85bbdb1f28629d18f Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 26 Jun 2009 12:12:20 -0700 Subject: Update paths to support an explicit root and multiple paths per category --- railties/test/paths_test.rb | 120 +++++++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 29 deletions(-) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 0da31b467a..1fad324015 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -2,18 +2,10 @@ require 'abstract_unit' module Rails class Application - class Path - attr_accessor :path, :root #, :glob, :load_once, :eager - - def initialize(path, root = nil) - @children = {} - @path = path - @root = root || self - end - + module PathParent def method_missing(id, *args) name = id.to_s - + if name =~ /^(.*)=$/ @children[$1] = Path.new(args.first, @root) elsif path = @children[name] @@ -22,47 +14,117 @@ module Rails super end end - - def path - @path.index('/') == 0 ? @path : File.join(@root.path, @path) + end + + class Root + include PathParent + + attr_reader :path + def initialize(path) + raise unless path.is_a?(String) + + @children = {} + + # TODO: Move logic from set_root_path initializer + @path = File.expand_path(path) + @root = self + end + end + + class Path + include PathParent + + attr_reader :path #, :glob, :load_once, :eager + + def initialize(path, root) + @children = {} + @root = root + @paths = [path].flatten + end + + def push(path) + @paths.push path + end + + alias << push + + def unshift(path) + @paths.unshift path + end + + + def paths + @paths.map do |path| + path.index('/') == 0 ? path : File.join(@root.path, path) + end end - - alias to_s path + + alias to_a paths end end end class PathsTest < ActiveSupport::TestCase - + def setup - @root = Rails::Application::Path.new("/foo/bar") + @root = Rails::Application::Root.new("/foo/bar") end - + test "the paths object is initialized with the root path" do - root = Rails::Application::Path.new("/fiz/baz") - assert_equal "/fiz/baz", root.to_s + root = Rails::Application::Root.new("/fiz/baz") + assert_equal "/fiz/baz", root.path end - + test "creating a root level path" do @root.app = "/foo/bar" - assert_equal "/foo/bar", @root.app.to_s + assert_equal ["/foo/bar"], @root.app.to_a end - + test "relative paths are relative to the paths root" do @root.app = "app" - assert_equal "/foo/bar/app", @root.app.to_s + assert_equal ["/foo/bar/app"], @root.app.to_a end - + test "creating a child level path" do @root.app = "/foo/bar" @root.app.models = "/foo/bar/baz" - assert_equal "/foo/bar/baz", @root.app.models.to_s + assert_equal ["/foo/bar/baz"], @root.app.models.to_a end - + test "child level paths are relative from the root" do @root.app = "/app" @root.app.models = "baz" - - assert_equal "/foo/bar/baz", @root.app.models.to_s + + assert_equal ["/foo/bar/baz"], @root.app.models.to_a + end + + test "adding multiple physical paths as an array" do + @root.app = ["/app", "/app2"] + assert_equal ["/app", "/app2"], @root.app.to_a + end + + test "adding multiple physical paths using #push" do + @root.app = "/app" + @root.app.push "/app2" + assert_equal ["/app", "/app2"], @root.app.to_a + end + + test "adding multiple physical paths using <<" do + @root.app = "/app" + @root.app << "/app2" + assert_equal ["/app", "/app2"], @root.app.to_a + end + + test "adding multiple physical paths using #unshift" do + @root.app = "/app" + @root.app.unshift "/app2" + assert_equal ["/app2", "/app"], @root.app.to_a + end + + test "the root can only have one physical path" do + assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) } + assert_raise(NoMethodError) { @root.push "/biz" } + assert_raise(NoMethodError) { @root.unshift "/biz" } + assert_raise(NoMethodError) { @root << "/biz" } end end \ No newline at end of file -- cgit v1.2.3 From 4153c6b720563e1c43bb96e95f0ff5fbd59d6be7 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 26 Jun 2009 15:36:38 -0700 Subject: Finished a first stab at the Rails application path object. --- railties/test/paths_test.rb | 104 +++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 64 deletions(-) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index 1fad324015..e7df58579f 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -1,68 +1,5 @@ require 'abstract_unit' - -module Rails - class Application - module PathParent - def method_missing(id, *args) - name = id.to_s - - if name =~ /^(.*)=$/ - @children[$1] = Path.new(args.first, @root) - elsif path = @children[name] - path - else - super - end - end - end - - class Root - include PathParent - - attr_reader :path - def initialize(path) - raise unless path.is_a?(String) - - @children = {} - - # TODO: Move logic from set_root_path initializer - @path = File.expand_path(path) - @root = self - end - end - - class Path - include PathParent - - attr_reader :path #, :glob, :load_once, :eager - - def initialize(path, root) - @children = {} - @root = root - @paths = [path].flatten - end - - def push(path) - @paths.push path - end - - alias << push - - def unshift(path) - @paths.unshift path - end - - - def paths - @paths.map do |path| - path.index('/') == 0 ? path : File.join(@root.path, path) - end - end - - alias to_a paths - end - end -end +require 'rails/paths' class PathsTest < ActiveSupport::TestCase @@ -127,4 +64,43 @@ class PathsTest < ActiveSupport::TestCase assert_raise(NoMethodError) { @root.unshift "/biz" } assert_raise(NoMethodError) { @root << "/biz" } end + + test "it is possible to add a path that should be loaded only once" do + @root.app = "/app" + @root.app.load_once! + assert @root.app.load_once? + assert @root.load_once.include?(@root.app) + end + + test "making a path load_once more than once only includes it once in @root.load_once" do + @root.app = "/app" + @root.app.load_once! + @root.app.load_once! + assert_equal 1, @root.load_once.select {|p| p == @root.app }.size + end + + test "it is possible to mark a path as eager" do + @root.app = "/app" + @root.app.eager_load! + assert @root.app.eager_load? + assert @root.eager_load.include?(@root.app) + end + + test "making a path eager more than once only includes it once in @root.eager_paths" do + @root.app = "/app" + @root.app.eager_load! + @root.app.eager_load! + assert_equal 1, @root.eager_load.select {|p| p == @root.app }.size + end + + test "a path should have a glob that defaults to **/*.rb" do + @root.app = "/app" + assert_equal "**/*.rb", @root.app.glob + end + + test "it should be possible to override a path's default glob" do + @root.app = "/app" + @root.app.glob = "*.rb" + assert_equal "*.rb", @root.app.glob + end end \ No newline at end of file -- cgit v1.2.3 From 188a892c5a097ee6d62249d048a6be7d2dfe9649 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Fri, 26 Jun 2009 17:32:05 -0700 Subject: Starting to replace scattered path configuration settings with the path object --- railties/test/abstract_unit.rb | 1 + railties/test/initializer/path_test.rb | 86 ++++++++++++++++++++++ .../test/initializer/root/app/controllers/.keep | 0 railties/test/initializer/root/app/helpers/.keep | 0 railties/test/initializer/root/app/metal/.keep | 0 railties/test/initializer/root/app/models/.keep | 0 railties/test/initializer/root/app/views/.keep | 0 railties/test/initializer/root/config/database.yml | 4 + .../initializer/root/config/environments/.keep | 0 .../test/initializer/root/config/locales/.keep | 0 railties/test/initializer/root/config/routes.rb | 0 railties/test/initializer/root/lib/.keep | 0 railties/test/initializer/root/tmp/.keep | 0 railties/test/initializer/root/tmp/cache/.keep | 0 railties/test/initializer/root/vendor/.keep | 0 railties/test/paths_test.rb | 21 +++++- 16 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 railties/test/initializer/path_test.rb create mode 100644 railties/test/initializer/root/app/controllers/.keep create mode 100644 railties/test/initializer/root/app/helpers/.keep create mode 100644 railties/test/initializer/root/app/metal/.keep create mode 100644 railties/test/initializer/root/app/models/.keep create mode 100644 railties/test/initializer/root/app/views/.keep create mode 100644 railties/test/initializer/root/config/database.yml create mode 100644 railties/test/initializer/root/config/environments/.keep create mode 100644 railties/test/initializer/root/config/locales/.keep create mode 100644 railties/test/initializer/root/config/routes.rb create mode 100644 railties/test/initializer/root/lib/.keep create mode 100644 railties/test/initializer/root/tmp/.keep create mode 100644 railties/test/initializer/root/tmp/cache/.keep create mode 100644 railties/test/initializer/root/vendor/.keep (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 0addcb8bf3..cef69e90cb 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -2,6 +2,7 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" $:.unshift File.dirname(__FILE__) + "/../../activerecord/lib" $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib" +$:.unshift File.dirname(__FILE__) + "/../../activeresource/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb new file mode 100644 index 0000000000..37e1eebbc7 --- /dev/null +++ b/railties/test/initializer/path_test.rb @@ -0,0 +1,86 @@ +require 'abstract_unit' +require 'active_support/ruby/shim' +require 'initializer' + +RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") + +module Rails + def self.vendor_rails? ; false ; end +end + +# TODO: Can this be reset? +Rails::Initializer.run do |config| + config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] +end + +class PathsTest < ActiveSupport::TestCase + def setup + @paths = Rails::Initializer.default.config.paths + end + + def root(*path) + File.expand_path(File.join(File.dirname(__FILE__), "root", *path)) + end + + def assert_path(paths, *dir) + assert_equal [root(*dir)], paths.paths + end + + test "booting up Rails yields a valid paths object" do + assert_path @paths.app, "app" + assert_path @paths.app.metals, "app", "metal" + assert_path @paths.app.models, "app", "models" + assert_path @paths.app.helpers, "app", "helpers" + assert_path @paths.app.services, "app", "services" + assert_path @paths.lib, "lib" + assert_path @paths.vendor, "vendor" + assert_path @paths.vendor.plugins, "vendor", "plugins" + assert_path @paths.cache, "tmp", "cache" + assert_path @paths.config, "config" + 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 Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, + Pathname.new(@paths.app.controllers.to_a[1]).expand_path + end + + test "booting up Rails yields a list of paths that are eager" do + assert @paths.app.models.eager_load? + assert @paths.app.controllers.eager_load? + assert @paths.app.helpers.eager_load? + assert @paths.app.metals.eager_load? + end + + test "environments has a glob equal to the current environment" do + 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", "services" + assert_not_in_load_path "config" + assert_not_in_load_path "config", "locales" + assert_not_in_load_path "config", "environments" + assert_not_in_load_path "tmp" + assert_not_in_load_path "tmp", "cache" + end + +end \ No newline at end of file diff --git a/railties/test/initializer/root/app/controllers/.keep b/railties/test/initializer/root/app/controllers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/app/helpers/.keep b/railties/test/initializer/root/app/helpers/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/app/metal/.keep b/railties/test/initializer/root/app/metal/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/app/models/.keep b/railties/test/initializer/root/app/models/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/app/views/.keep b/railties/test/initializer/root/app/views/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/config/database.yml b/railties/test/initializer/root/config/database.yml new file mode 100644 index 0000000000..ce3356be0c --- /dev/null +++ b/railties/test/initializer/root/config/database.yml @@ -0,0 +1,4 @@ +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 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/config/locales/.keep b/railties/test/initializer/root/config/locales/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/config/routes.rb b/railties/test/initializer/root/config/routes.rb new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/lib/.keep b/railties/test/initializer/root/lib/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/tmp/.keep b/railties/test/initializer/root/tmp/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/tmp/cache/.keep b/railties/test/initializer/root/tmp/cache/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/initializer/root/vendor/.keep b/railties/test/initializer/root/vendor/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index e7df58579f..a1ed43ad6d 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -69,28 +69,28 @@ class PathsTest < ActiveSupport::TestCase @root.app = "/app" @root.app.load_once! assert @root.app.load_once? - assert @root.load_once.include?(@root.app) + assert @root.load_once.include?(@root.app.paths.first) end test "making a path load_once more than once only includes it once in @root.load_once" do @root.app = "/app" @root.app.load_once! @root.app.load_once! - assert_equal 1, @root.load_once.select {|p| p == @root.app }.size + assert_equal 1, @root.load_once.select {|p| p == @root.app.paths.first }.size end test "it is possible to mark a path as eager" do @root.app = "/app" @root.app.eager_load! assert @root.app.eager_load? - assert @root.eager_load.include?(@root.app) + assert @root.eager_load.include?(@root.app.paths.first) end test "making a path eager more than once only includes it once in @root.eager_paths" do @root.app = "/app" @root.app.eager_load! @root.app.eager_load! - assert_equal 1, @root.eager_load.select {|p| p == @root.app }.size + assert_equal 1, @root.eager_load.select {|p| p == @root.app.paths.first }.size end test "a path should have a glob that defaults to **/*.rb" do @@ -103,4 +103,17 @@ class PathsTest < ActiveSupport::TestCase @root.app.glob = "*.rb" assert_equal "*.rb", @root.app.glob end + + test "a path can be added to the load path" do + @root.app = "app" + @root.app.load_path! + @root.app.models = "app/models" + assert_equal ["/foo/bar/app"], @root.load_paths + end + + test "adding a path to the eager paths also adds it to the load path" do + @root.app = "app" + @root.app.eager_load! + assert_equal ["/foo/bar/app"], @root.load_paths + end end \ No newline at end of file -- cgit v1.2.3 From f281745056cd67c967c5a695694061f515385be8 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 30 Jun 2009 13:53:03 -0700 Subject: Test that builtin_directories is only used in development mode --- railties/test/initializer/path_test.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'railties/test') diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 37e1eebbc7..8fbad24a73 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -14,6 +14,8 @@ Rails::Initializer.run do |config| end class PathsTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + def setup @paths = Rails::Initializer.default.config.paths end @@ -83,4 +85,19 @@ class PathsTest < ActiveSupport::TestCase assert_not_in_load_path "tmp", "cache" end + test "controller paths include builtin in development mode" do + RAILS_ENV.replace "development" + assert Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in test mode" do + RAILS_ENV.replace "test" + assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in production mode" do + RAILS_ENV.replace "production" + assert !Rails::Configuration.new.paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + end \ No newline at end of file -- cgit v1.2.3 From 132e6d00638dc6370fafa0f1377d3bca17eee2d1 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Tue, 30 Jun 2009 13:55:11 -0700 Subject: Add #concat to Rails::Application::Path --- railties/test/paths_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index a1ed43ad6d..fa2f6ceee2 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -52,6 +52,12 @@ class PathsTest < ActiveSupport::TestCase assert_equal ["/app", "/app2"], @root.app.to_a end + test "adding multiple physical paths using concat" do + @root.app = "/app" + @root.app.concat ["/app2", "/app3"] + assert_equal ["/app", "/app2", "/app3"], @root.app.to_a + end + test "adding multiple physical paths using #unshift" do @root.app = "/app" @root.app.unshift "/app2" @@ -62,6 +68,7 @@ class PathsTest < ActiveSupport::TestCase assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) } assert_raise(NoMethodError) { @root.push "/biz" } assert_raise(NoMethodError) { @root.unshift "/biz" } + assert_raise(NoMethodError) { @root.concat ["/biz"]} assert_raise(NoMethodError) { @root << "/biz" } end -- cgit v1.2.3 From eea7b5db1db5d7e6020c5bcb6b4d85afcbc2e696 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Tue, 30 Jun 2009 17:26:46 -0700 Subject: Crazy hacks to get the Isolation testing module to work on non forking environments --- railties/test/abstract_unit.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index cef69e90cb..dd9d0448b2 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,3 +1,5 @@ +ORIG_ARGV = ARGV.dup + $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" $:.unshift File.dirname(__FILE__) + "/../../activerecord/lib" $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" -- cgit v1.2.3 From 7583a24ee0ea85d55a5e235c3082f1b67d3d7694 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Wed, 1 Jul 2009 11:53:17 -0700 Subject: Move mocha down below initial T::U require and bump version to 0.9.7 [#2858 state:resolved] --- railties/test/abstract_unit.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index dd9d0448b2..9a640bdbc5 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -12,9 +12,6 @@ require 'stringio' require 'rubygems' require 'test/unit' -gem 'mocha', '>= 0.9.5' -require 'mocha' - require 'active_support' require 'active_support/test_case' -- cgit v1.2.3 From 9eab435631e1b0a659126d068972ee88cff160de Mon Sep 17 00:00:00 2001 From: "J.D. Hollis" Date: Tue, 30 Jun 2009 08:58:35 -0400 Subject: Only check for built extensions on gem dependencies that are in vendor/gems. [#2825 state:resolved] Signed-off-by: Yehuda Katz + Carl Lerche --- railties/test/gem_dependency_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 70f4496685..92132be992 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -199,6 +199,15 @@ class GemDependencyTest < Test::Unit::TestCase assert_equal true, Rails::GemDependency.new("dummy-gem-i").built? assert_equal false, Rails::GemDependency.new("dummy-gem-j").built? end + + def test_gem_determines_build_status_only_on_vendor_gems + framework_gem = Rails::GemDependency.new('dummy-framework-gem') + framework_gem.stubs(:framework_gem?).returns(true) # already loaded + framework_gem.stubs(:vendor_rails?).returns(false) # but not in vendor/rails + framework_gem.stubs(:vendor_gem?).returns(false) # and not in vendor/gems + framework_gem.add_load_paths # freeze framework gem early + assert framework_gem.built? + end def test_gem_build_passes_options_to_dependencies start_gem = Rails::GemDependency.new("dummy-gem-g") -- cgit v1.2.3 From 913bb2f4c2feb79dcbc9ed2c0fb1ef6d436f7d02 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 2 Jul 2009 15:47:11 -0700 Subject: Modify the Rails::Application::Path object to allow for more concise path definition. --- railties/test/paths_test.rb | 92 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 88 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index fa2f6ceee2..d50882110f 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -17,17 +17,37 @@ class PathsTest < ActiveSupport::TestCase assert_equal ["/foo/bar"], @root.app.to_a end + test "creating a root level path without assignment" do + @root.app "/foo/bar" + assert_equal ["/foo/bar"], @root.app.to_a + end + + test "trying to access a path that does not exist raises NoMethodError" do + assert_raises(NoMethodError) { @root.app } + end + test "relative paths are relative to the paths root" do @root.app = "app" assert_equal ["/foo/bar/app"], @root.app.to_a end + test "relative paths are relative to the paths root without assignment" do + @root.app "app" + assert_equal ["/foo/bar/app"], @root.app.to_a + end + test "creating a child level path" do @root.app = "/foo/bar" @root.app.models = "/foo/bar/baz" assert_equal ["/foo/bar/baz"], @root.app.models.to_a end + test "creating a child level path without assignment" do + @root.app = "/foo/bar" + @root.app.models "/foo/bar/baz" + assert_equal ["/foo/bar/baz"], @root.app.models.to_a + end + test "child level paths are relative from the root" do @root.app = "/app" @root.app.models = "baz" @@ -40,6 +60,11 @@ class PathsTest < ActiveSupport::TestCase assert_equal ["/app", "/app2"], @root.app.to_a end + test "adding multiple physical paths as an array without assignment" do + @root.app "/app", "/app2" + assert_equal ["/app", "/app2"], @root.app.to_a + end + test "adding multiple physical paths using #push" do @root.app = "/app" @root.app.push "/app2" @@ -66,10 +91,10 @@ class PathsTest < ActiveSupport::TestCase test "the root can only have one physical path" do assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) } - assert_raise(NoMethodError) { @root.push "/biz" } - assert_raise(NoMethodError) { @root.unshift "/biz" } - assert_raise(NoMethodError) { @root.concat ["/biz"]} - assert_raise(NoMethodError) { @root << "/biz" } + assert_raise(RuntimeError) { @root.push "/biz" } + assert_raise(RuntimeError) { @root.unshift "/biz" } + assert_raise(RuntimeError) { @root.concat ["/biz"]} + assert_raise(RuntimeError) { @root << "/biz" } end test "it is possible to add a path that should be loaded only once" do @@ -79,6 +104,19 @@ class PathsTest < ActiveSupport::TestCase assert @root.load_once.include?(@root.app.paths.first) end + test "it is possible to add a path without assignment and specify it should be loaded only once" do + @root.app "/app", :load_once => true + assert @root.app.load_once? + assert @root.load_once.include?("/app") + end + + test "it is possible to add multiple paths without assignment and specify it should be loaded only once" do + @root.app "/app", "/app2", :load_once => true + assert @root.app.load_once? + assert @root.load_once.include?("/app") + assert @root.load_once.include?("/app2") + end + test "making a path load_once more than once only includes it once in @root.load_once" do @root.app = "/app" @root.app.load_once! @@ -86,6 +124,13 @@ class PathsTest < ActiveSupport::TestCase assert_equal 1, @root.load_once.select {|p| p == @root.app.paths.first }.size end + test "paths added to a load_once path should be added to the load_once collection" do + @root.app = "/app" + @root.app.load_once! + @root.app << "/app2" + assert_equal 2, @root.load_once.size + end + test "it is possible to mark a path as eager" do @root.app = "/app" @root.app.eager_load! @@ -93,6 +138,27 @@ class PathsTest < ActiveSupport::TestCase assert @root.eager_load.include?(@root.app.paths.first) end + test "it is possible to add a path without assignment and mark it as eager" do + @root.app "/app", :eager_load => true + assert @root.app.eager_load? + assert @root.eager_load.include?("/app") + end + + test "it is possible to add multiple paths without assignment and mark them as eager" do + @root.app "/app", "/app2", :eager_load => true + assert @root.app.eager_load? + assert @root.eager_load.include?("/app") + assert @root.eager_load.include?("/app2") + end + + test "it is possible to create a path without assignment and mark it both as eager and load once" do + @root.app "/app", :eager_load => true, :load_once => true + assert @root.app.eager_load? + assert @root.app.load_once? + assert @root.eager_load.include?("/app") + assert @root.load_once.include?("/app") + end + test "making a path eager more than once only includes it once in @root.eager_paths" do @root.app = "/app" @root.app.eager_load! @@ -100,6 +166,13 @@ class PathsTest < ActiveSupport::TestCase assert_equal 1, @root.eager_load.select {|p| p == @root.app.paths.first }.size end + test "paths added to a eager_load path should be added to the eager_load collection" do + @root.app = "/app" + @root.app.eager_load! + @root.app << "/app2" + assert_equal 2, @root.eager_load.size + end + test "a path should have a glob that defaults to **/*.rb" do @root.app = "/app" assert_equal "**/*.rb", @root.app.glob @@ -111,6 +184,11 @@ class PathsTest < ActiveSupport::TestCase assert_equal "*.rb", @root.app.glob end + test "it should be possible to override a path's default glob without assignment" do + @root.app "/app", :glob => "*.rb" + assert_equal "*.rb", @root.app.glob + end + test "a path can be added to the load path" do @root.app = "app" @root.app.load_path! @@ -118,6 +196,12 @@ class PathsTest < ActiveSupport::TestCase assert_equal ["/foo/bar/app"], @root.load_paths end + test "a path can be added to the load path on creation" do + @root.app "/app", :load_path => true + assert @root.app.load_path? + assert_equal ["/app"], @root.load_paths + end + test "adding a path to the eager paths also adds it to the load path" do @root.app = "app" @root.app.eager_load! -- cgit v1.2.3 From 1d280e21a19aff74e1b35779be2633e6efa511f0 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 2 Jul 2009 16:03:41 -0700 Subject: Adds support for def self.setup in isolation tests for setup that should be run only once in the parent --- railties/test/initializer/path_test.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 8fbad24a73..db62796ea5 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -8,14 +8,15 @@ module Rails def self.vendor_rails? ; false ; end end -# TODO: Can this be reset? -Rails::Initializer.run do |config| - config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] -end - class PathsTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation + def self.setup + Rails::Initializer.run do |config| + config.frameworks = [:action_controller, :action_view, :action_mailer, :active_record] + end + end + def setup @paths = Rails::Initializer.default.config.paths end -- cgit v1.2.3 From d8406f0c20e7809ce797d37c509e2f58f07109d2 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 2 Jul 2009 16:51:05 -0700 Subject: Wrote tests for the :check_ruby_version initializer --- .../test/initializer/check_ruby_version_test.rb | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 railties/test/initializer/check_ruby_version_test.rb (limited to 'railties/test') diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb new file mode 100644 index 0000000000..12503fb481 --- /dev/null +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -0,0 +1,59 @@ +require 'abstract_unit' +require 'active_support/ruby/shim' +require 'initializer' + +RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") + +module Rails + def self.vendor_rails? ; false ; end +end + +module InitializerTests + class PathsTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + + test "rails does not initialize with ruby version 1.8.1" do + assert_rails_does_not_boot "1.8.1" + end + + test "rails initializes with ruby version 1.8.2" do + assert_rails_boots "1.8.2" + end + + test "rails does not initialize with ruby version 1.8.3" do + assert_rails_does_not_boot "1.8.3" + end + + test "rails initializes with ruby version 1.8.4" do + assert_rails_boots "1.8.4" + end + + test "rails initializes with ruby version 1.8.5" do + assert_rails_boots "1.8.5" + end + + test "rails initializes with ruby version 1.8.6" do + assert_rails_boots "1.8.6" + end + + def set_ruby_version(version) + $-w = nil + Object.const_set(:RUBY_VERSION, version.freeze) + end + + def assert_rails_boots(version) + set_ruby_version(version) + assert_nothing_raised "It appears that rails does not boot" do + Rails::Initializer.run { |c| c.frameworks = [] } + end + end + + def assert_rails_does_not_boot(version) + set_ruby_version(version) + $stderr = File.open("/dev/null", "w") + assert_raises(SystemExit) do + Rails::Initializer.run { |c| c.frameworks = [] } + end + end + end +end -- cgit v1.2.3 From 378a65a909439ebca909125fdfada23ed89cec63 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Thu, 2 Jul 2009 17:52:46 -0700 Subject: Added tests for the :install_gem_spec_stubs initializer --- .../test/initializer/check_ruby_version_test.rb | 10 +-- .../initializer/install_gem_spec_stubs_test.rb | 85 ++++++++++++++++++++++ railties/test/initializer/path_test.rb | 10 +-- railties/test/initializer/test_helper.rb | 24 ++++++ railties/test/initializer_test.rb | 2 +- railties/test/plugin_test_helper.rb | 2 +- 6 files changed, 113 insertions(+), 20 deletions(-) create mode 100644 railties/test/initializer/install_gem_spec_stubs_test.rb create mode 100644 railties/test/initializer/test_helper.rb (limited to 'railties/test') diff --git a/railties/test/initializer/check_ruby_version_test.rb b/railties/test/initializer/check_ruby_version_test.rb index 12503fb481..33de653906 100644 --- a/railties/test/initializer/check_ruby_version_test.rb +++ b/railties/test/initializer/check_ruby_version_test.rb @@ -1,12 +1,4 @@ -require 'abstract_unit' -require 'active_support/ruby/shim' -require 'initializer' - -RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") - -module Rails - def self.vendor_rails? ; false ; end -end +require "initializer/test_helper" module InitializerTests class PathsTest < ActiveSupport::TestCase diff --git a/railties/test/initializer/install_gem_spec_stubs_test.rb b/railties/test/initializer/install_gem_spec_stubs_test.rb new file mode 100644 index 0000000000..2e94c9968f --- /dev/null +++ b/railties/test/initializer/install_gem_spec_stubs_test.rb @@ -0,0 +1,85 @@ +require "initializer/test_helper" + +module InitializerTests + class GemSpecStubsTest < ActiveSupport::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 + + 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 db62796ea5..26f796f93d 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -1,12 +1,4 @@ -require 'abstract_unit' -require 'active_support/ruby/shim' -require 'initializer' - -RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") - -module Rails - def self.vendor_rails? ; false ; end -end +require "initializer/test_helper" class PathsTest < ActiveSupport::TestCase include ActiveSupport::Testing::Isolation diff --git a/railties/test/initializer/test_helper.rb b/railties/test/initializer/test_helper.rb new file mode 100644 index 0000000000..ddb03397ab --- /dev/null +++ b/railties/test/initializer/test_helper.rb @@ -0,0 +1,24 @@ +require 'abstract_unit' +require 'active_support/ruby/shim' +require 'initializer' + +RAILS_ROOT.replace File.join(File.dirname(__FILE__), "root") + +module Rails + class << self + attr_accessor :vendor_rails + def vendor_rails?() @vendor_rails end + end +end + +class ActiveSupport::TestCase + def assert_stderr(match) + $stderr = StringIO.new + yield + $stderr.rewind + err = $stderr.read + assert_match match, err + ensure + $stderr = STDERR + end +end \ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 5caa5858a4..550cb7de76 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -178,7 +178,7 @@ class ConfigurationFrameworkPathsTests < Test::Unit::TestCase end end -require File.dirname(__FILE__) + '/plugin_test_helper' +require 'plugin_test_helper' class InitializerPluginLoadingTests < Test::Unit::TestCase def setup diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb index 55d1a1fa96..893095fa66 100644 --- a/railties/test/plugin_test_helper.rb +++ b/railties/test/plugin_test_helper.rb @@ -4,7 +4,7 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" require 'test/unit' require 'active_support' require 'initializer' -require File.join(File.dirname(__FILE__), 'abstract_unit') +require 'abstract_unit' # We need to set RAILS_ROOT if it isn't already set RAILS_ROOT = '.' unless defined?(RAILS_ROOT) -- cgit v1.2.3 From 3c1dab72259d01c6335bf359d7f9b3af69d45bb4 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Fri, 3 Jul 2009 12:23:57 +0100 Subject: Revert "Modify the Rails::Application::Path object to allow for more concise path definition." This reverts commit 913bb2f4c2feb79dcbc9ed2c0fb1ef6d436f7d02. Reason : The server does not start --- railties/test/paths_test.rb | 92 ++------------------------------------------- 1 file changed, 4 insertions(+), 88 deletions(-) (limited to 'railties/test') diff --git a/railties/test/paths_test.rb b/railties/test/paths_test.rb index d50882110f..fa2f6ceee2 100644 --- a/railties/test/paths_test.rb +++ b/railties/test/paths_test.rb @@ -17,37 +17,17 @@ class PathsTest < ActiveSupport::TestCase assert_equal ["/foo/bar"], @root.app.to_a end - test "creating a root level path without assignment" do - @root.app "/foo/bar" - assert_equal ["/foo/bar"], @root.app.to_a - end - - test "trying to access a path that does not exist raises NoMethodError" do - assert_raises(NoMethodError) { @root.app } - end - test "relative paths are relative to the paths root" do @root.app = "app" assert_equal ["/foo/bar/app"], @root.app.to_a end - test "relative paths are relative to the paths root without assignment" do - @root.app "app" - assert_equal ["/foo/bar/app"], @root.app.to_a - end - test "creating a child level path" do @root.app = "/foo/bar" @root.app.models = "/foo/bar/baz" assert_equal ["/foo/bar/baz"], @root.app.models.to_a end - test "creating a child level path without assignment" do - @root.app = "/foo/bar" - @root.app.models "/foo/bar/baz" - assert_equal ["/foo/bar/baz"], @root.app.models.to_a - end - test "child level paths are relative from the root" do @root.app = "/app" @root.app.models = "baz" @@ -60,11 +40,6 @@ class PathsTest < ActiveSupport::TestCase assert_equal ["/app", "/app2"], @root.app.to_a end - test "adding multiple physical paths as an array without assignment" do - @root.app "/app", "/app2" - assert_equal ["/app", "/app2"], @root.app.to_a - end - test "adding multiple physical paths using #push" do @root.app = "/app" @root.app.push "/app2" @@ -91,10 +66,10 @@ class PathsTest < ActiveSupport::TestCase test "the root can only have one physical path" do assert_raise(RuntimeError) { Rails::Application::Root.new(["/fiz", "/biz"]) } - assert_raise(RuntimeError) { @root.push "/biz" } - assert_raise(RuntimeError) { @root.unshift "/biz" } - assert_raise(RuntimeError) { @root.concat ["/biz"]} - assert_raise(RuntimeError) { @root << "/biz" } + assert_raise(NoMethodError) { @root.push "/biz" } + assert_raise(NoMethodError) { @root.unshift "/biz" } + assert_raise(NoMethodError) { @root.concat ["/biz"]} + assert_raise(NoMethodError) { @root << "/biz" } end test "it is possible to add a path that should be loaded only once" do @@ -104,19 +79,6 @@ class PathsTest < ActiveSupport::TestCase assert @root.load_once.include?(@root.app.paths.first) end - test "it is possible to add a path without assignment and specify it should be loaded only once" do - @root.app "/app", :load_once => true - assert @root.app.load_once? - assert @root.load_once.include?("/app") - end - - test "it is possible to add multiple paths without assignment and specify it should be loaded only once" do - @root.app "/app", "/app2", :load_once => true - assert @root.app.load_once? - assert @root.load_once.include?("/app") - assert @root.load_once.include?("/app2") - end - test "making a path load_once more than once only includes it once in @root.load_once" do @root.app = "/app" @root.app.load_once! @@ -124,13 +86,6 @@ class PathsTest < ActiveSupport::TestCase assert_equal 1, @root.load_once.select {|p| p == @root.app.paths.first }.size end - test "paths added to a load_once path should be added to the load_once collection" do - @root.app = "/app" - @root.app.load_once! - @root.app << "/app2" - assert_equal 2, @root.load_once.size - end - test "it is possible to mark a path as eager" do @root.app = "/app" @root.app.eager_load! @@ -138,27 +93,6 @@ class PathsTest < ActiveSupport::TestCase assert @root.eager_load.include?(@root.app.paths.first) end - test "it is possible to add a path without assignment and mark it as eager" do - @root.app "/app", :eager_load => true - assert @root.app.eager_load? - assert @root.eager_load.include?("/app") - end - - test "it is possible to add multiple paths without assignment and mark them as eager" do - @root.app "/app", "/app2", :eager_load => true - assert @root.app.eager_load? - assert @root.eager_load.include?("/app") - assert @root.eager_load.include?("/app2") - end - - test "it is possible to create a path without assignment and mark it both as eager and load once" do - @root.app "/app", :eager_load => true, :load_once => true - assert @root.app.eager_load? - assert @root.app.load_once? - assert @root.eager_load.include?("/app") - assert @root.load_once.include?("/app") - end - test "making a path eager more than once only includes it once in @root.eager_paths" do @root.app = "/app" @root.app.eager_load! @@ -166,13 +100,6 @@ class PathsTest < ActiveSupport::TestCase assert_equal 1, @root.eager_load.select {|p| p == @root.app.paths.first }.size end - test "paths added to a eager_load path should be added to the eager_load collection" do - @root.app = "/app" - @root.app.eager_load! - @root.app << "/app2" - assert_equal 2, @root.eager_load.size - end - test "a path should have a glob that defaults to **/*.rb" do @root.app = "/app" assert_equal "**/*.rb", @root.app.glob @@ -184,11 +111,6 @@ class PathsTest < ActiveSupport::TestCase assert_equal "*.rb", @root.app.glob end - test "it should be possible to override a path's default glob without assignment" do - @root.app "/app", :glob => "*.rb" - assert_equal "*.rb", @root.app.glob - end - test "a path can be added to the load path" do @root.app = "app" @root.app.load_path! @@ -196,12 +118,6 @@ class PathsTest < ActiveSupport::TestCase assert_equal ["/foo/bar/app"], @root.load_paths end - test "a path can be added to the load path on creation" do - @root.app "/app", :load_path => true - assert @root.app.load_path? - assert_equal ["/app"], @root.load_paths - end - test "adding a path to the eager paths also adds it to the load path" do @root.app = "app" @root.app.eager_load! -- cgit v1.2.3