diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/configs/initializers/inflections.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/gem_dependency.rb | 31 | ||||
-rw-r--r-- | railties/lib/rails/plugin.rb | 10 | ||||
-rw-r--r-- | railties/lib/webrick_server.rb | 13 | ||||
-rw-r--r-- | railties/test/fixtures/plugins/default/gemlike/init.rb | 1 | ||||
-rw-r--r-- | railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb | 2 | ||||
-rw-r--r-- | railties/test/fixtures/plugins/default/gemlike/rails/init.rb | 7 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 102 | ||||
-rw-r--r-- | railties/test/plugin_loader_test.rb | 12 | ||||
-rw-r--r-- | railties/test/plugin_locator_test.rb | 4 | ||||
-rw-r--r-- | railties/test/plugin_test.rb | 16 | ||||
-rw-r--r-- | railties/test/rails_info_controller_test.rb | 4 |
12 files changed, 112 insertions, 92 deletions
diff --git a/railties/configs/initializers/inflections.rb b/railties/configs/initializers/inflections.rb index 09158b865c..d531b8bb82 100644 --- a/railties/configs/initializers/inflections.rb +++ b/railties/configs/initializers/inflections.rb @@ -2,7 +2,7 @@ # Add new inflection rules using the following format # (all these examples are active by default): -# Inflector.inflections do |inflect| +# ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 30bdf416fc..4cac7f725a 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -98,27 +98,26 @@ module Rails self.name == other.name && self.requirement == other.requirement end -private ################################################################### - def specification @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last end - def gem_command - RUBY_PLATFORM =~ /win32/ ? 'gem.bat' : 'gem' - end + private + def gem_command + RUBY_PLATFORM =~ /win32/ ? 'gem.bat' : 'gem' + end - def install_command - cmd = %w(install) << @name - cmd << "--version" << %("#{@requirement.to_s}") if @requirement - cmd << "--source" << @source if @source - cmd - end + def install_command + cmd = %w(install) << @name + cmd << "--version" << %("#{@requirement.to_s}") if @requirement + cmd << "--source" << @source if @source + cmd + end - def unpack_command - cmd = %w(unpack) << @name - cmd << "--version" << %("#{@requirement.to_s}") if @requirement - cmd - end + def unpack_command + cmd = %w(unpack) << @name + cmd << "--version" << %("#{@requirement.to_s}") if @requirement + cmd + end end end diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 256f4b0132..a54ab85dbe 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -74,10 +74,18 @@ module Rails File.join(directory, 'lib') end - def init_path + def classic_init_path File.join(directory, 'init.rb') end + def gem_init_path + File.join(directory, 'rails', 'init.rb') + end + + def init_path + File.file?(gem_init_path) ? gem_init_path : classic_init_path + end + def has_lib_directory? File.directory?(lib_path) end diff --git a/railties/lib/webrick_server.rb b/railties/lib/webrick_server.rb index ad4ca926ba..2f60151b22 100644 --- a/railties/lib/webrick_server.rb +++ b/railties/lib/webrick_server.rb @@ -43,8 +43,6 @@ end # can change this behavior by setting ActionController::Base.allow_concurrency # to true. class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet - REQUEST_MUTEX = Mutex.new - # Start the WEBrick server with the given options, mounting the # DispatchServlet at <tt>/</tt>. def self.dispatch(options = {}) @@ -73,15 +71,8 @@ class DispatchServlet < WEBrick::HTTPServlet::AbstractServlet def service(req, res) #:nodoc: unless handle_file(req, res) - begin - REQUEST_MUTEX.lock unless ActionController::Base.allow_concurrency - unless handle_dispatch(req, res) - raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." - end - ensure - unless ActionController::Base.allow_concurrency - REQUEST_MUTEX.unlock if REQUEST_MUTEX.locked? - end + unless handle_dispatch(req, res) + raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." end end end diff --git a/railties/test/fixtures/plugins/default/gemlike/init.rb b/railties/test/fixtures/plugins/default/gemlike/init.rb new file mode 100644 index 0000000000..6a771b5b68 --- /dev/null +++ b/railties/test/fixtures/plugins/default/gemlike/init.rb @@ -0,0 +1 @@ +raise 'This init.rb should not be evaluated because rails/init.rb exists' diff --git a/railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb b/railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb new file mode 100644 index 0000000000..2088103e45 --- /dev/null +++ b/railties/test/fixtures/plugins/default/gemlike/lib/gemlike.rb @@ -0,0 +1,2 @@ +module Gemlike +end
\ No newline at end of file diff --git a/railties/test/fixtures/plugins/default/gemlike/rails/init.rb b/railties/test/fixtures/plugins/default/gemlike/rails/init.rb new file mode 100644 index 0000000000..171a293eb3 --- /dev/null +++ b/railties/test/fixtures/plugins/default/gemlike/rails/init.rb @@ -0,0 +1,7 @@ +# I have access to my directory and the Rails config. +raise 'directory expected but undefined in init.rb' unless defined? directory +raise 'config expected but undefined in init.rb' unless defined? config + +# My lib/ dir must be in the load path. +require 'gemlike' +raise 'missing mixin from my lib/ dir' unless defined? Gemlike diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index efce4f292d..dee7abe05f 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -30,66 +30,66 @@ class Initializer_load_environment_Test < Test::Unit::TestCase end -class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase - def setup - config = ConfigurationMock.new("") - config.after_initialize do - $test_after_initialize_block1 = "success" - end - config.after_initialize do - $test_after_initialize_block2 = "congratulations" - end - assert_nil $test_after_initialize_block1 - assert_nil $test_after_initialize_block2 +uses_mocha 'Initializer after_initialize' do + class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::TestCase + def setup + config = ConfigurationMock.new("") + config.after_initialize do + $test_after_initialize_block1 = "success" + end + config.after_initialize do + $test_after_initialize_block2 = "congratulations" + end + assert_nil $test_after_initialize_block1 + assert_nil $test_after_initialize_block2 - Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) - Rails::Initializer.run(:after_initialize, config) - end + Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) + Rails::Initializer.run(:after_initialize, config) + end - def teardown - $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil - end + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil + end - def test_should_have_called_the_first_after_initialize_block - assert_equal "success", $test_after_initialize_block1 - end + def test_should_have_called_the_first_after_initialize_block + assert_equal "success", $test_after_initialize_block1 + end - def test_should_have_called_the_second_after_initialize_block - assert_equal "congratulations", $test_after_initialize_block2 + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end end -end -class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase + class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase + def setup + config = ConfigurationMock.new("") + config.after_initialize do + $test_after_initialize_block1 = "success" + end + config.after_initialize # don't pass a block, this is what we're testing! + config.after_initialize do + $test_after_initialize_block2 = "congratulations" + end + assert_nil $test_after_initialize_block1 - def setup - config = ConfigurationMock.new("") - config.after_initialize do - $test_after_initialize_block1 = "success" + Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) + Rails::Initializer.run(:after_initialize, config) end - config.after_initialize # don't pass a block, this is what we're testing! - config.after_initialize do - $test_after_initialize_block2 = "congratulations" - end - assert_nil $test_after_initialize_block1 - - Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) - Rails::Initializer.run(:after_initialize, config) - end - def teardown - $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil - end + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil + end - def test_should_have_called_the_first_after_initialize_block - assert_equal "success", $test_after_initialize_block1, "should still get set" - end + def test_should_have_called_the_first_after_initialize_block + assert_equal "success", $test_after_initialize_block1, "should still get set" + end - def test_should_have_called_the_second_after_initialize_block - assert_equal "congratulations", $test_after_initialize_block2 + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end end - end uses_mocha 'framework paths' do @@ -173,7 +173,7 @@ uses_mocha "Initializer plugin loading tests" do 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, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip end def test_all_plugins_loaded_when_all_is_used @@ -181,7 +181,7 @@ uses_mocha "Initializer plugin loading tests" do 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, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip end def test_all_plugins_loaded_after_all @@ -189,7 +189,7 @@ uses_mocha "Initializer plugin loading tests" do 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, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip + assert_plugins [:stubby, :a, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip end def test_plugin_names_may_be_strings diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index bce4446f79..e5fc0926eb 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -48,16 +48,16 @@ uses_mocha "Plugin Loader Tests" do end def test_should_find_all_availble_plugins_and_return_as_all_plugins - assert_plugins [:stubby, :plugin_with_no_lib_dir, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip + assert_plugins [:stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip end def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip end def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil @configuration.plugins = nil - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip end def test_should_return_specific_plugins_named_in_config_plugins_array_if_set @@ -74,17 +74,17 @@ uses_mocha "Plugin Loader Tests" do def test_should_load_all_plugins_in_natural_order_when_all_is_used only_load_the_following_plugins! [:all] - assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip end def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip end def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] - assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip + assert_plugins [:stubby, :a, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip end def test_should_accept_plugin_names_given_as_strings diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index 5f1dd991ea..363fa27f15 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -47,12 +47,12 @@ uses_mocha "Plugin Locator Tests" do end def test_should_return_all_plugins_found_under_the_set_plugin_paths - assert_equal ["a", "acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + assert_equal ["a", "acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort end def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")] - assert_equal ["acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + assert_equal ["acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")] assert_equal ["a"], @locator.plugins.map(&:name) diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb index 1445338f14..50124240a5 100644 --- a/railties/test/plugin_test.rb +++ b/railties/test/plugin_test.rb @@ -5,9 +5,10 @@ uses_mocha "Plugin Tests" do class PluginTest < Test::Unit::TestCase def setup - @initializer = Rails::Initializer.new(Rails::Configuration.new) - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') + @initializer = Rails::Initializer.new(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') end def test_should_determine_plugin_name_from_the_directory_of_the_plugin @@ -70,7 +71,14 @@ uses_mocha "Plugin Tests" do plugin.stubs(:evaluate_init_rb) plugin.send(:load, @initializer) end - + + # This path is fine so nothing is raised + assert_nothing_raised do + plugin = plugin_for(@gemlike_plugin_path) + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) + end + # This is an empty path so it raises assert_raises(LoadError) do plugin = plugin_for(@empty_plugin_path) diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index 17c7d9deea..e1872ebf33 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -30,6 +30,8 @@ class Rails::InfoControllerTest < Test::Unit::TestCase @controller = Rails::InfoController.new @request = ActionController::TestRequest.new @response = ActionController::TestResponse.new + + ActionController::Base.consider_all_requests_local = true end def test_rails_info_properties_table_rendered_for_local_request @@ -41,6 +43,8 @@ class Rails::InfoControllerTest < Test::Unit::TestCase def test_rails_info_properties_error_rendered_for_non_local_request Rails::InfoController.local_request = false + ActionController::Base.consider_all_requests_local = false + get :properties assert_tag :tag => 'p' assert_response 500 |