From 278186534c0ccf285a20497461f40d2e54aa20a0 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 3 Feb 2009 18:25:37 -0800 Subject: Bump mocha requirement for Ruby 1.9 compat. Remove uses_mocha. --- railties/test/abstract_unit.rb | 12 +- railties/test/boot_test.rb | 5 - railties/test/console_app_test.rb | 22 +- railties/test/gem_dependency_test.rb | 230 ++++++------ .../generators/rails_scaffold_generator_test.rb | 20 +- railties/test/initializer_test.rb | 416 ++++++++++----------- railties/test/plugin_locator_test.rb | 107 +++--- railties/test/plugin_test.rb | 271 +++++++------- 8 files changed, 525 insertions(+), 558 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index b6edc03391..43736ee7ec 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -3,20 +3,18 @@ $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" +require 'stringio' require 'rubygems' require 'test/unit' -gem 'mocha', '>= 0.9.3' + +gem 'mocha', '>= 0.9.5' require 'mocha' -require 'stringio' + require 'active_support' require 'active_support/test_case' -def uses_mocha(test_name) - yield -end - if defined?(RAILS_ROOT) RAILS_ROOT.replace File.dirname(__FILE__) else RAILS_ROOT = File.dirname(__FILE__) -end \ No newline at end of file +end diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb index 7736a8f4c0..16776af098 100644 --- a/railties/test/boot_test.rb +++ b/railties/test/boot_test.rb @@ -2,8 +2,6 @@ require 'abstract_unit' require 'initializer' require "#{File.dirname(__FILE__)}/../environments/boot" -uses_mocha 'boot tests' do - class BootTest < Test::Unit::TestCase def test_boot_returns_if_booted Rails.expects(:booted?).returns(true) @@ -121,9 +119,6 @@ class GemBootTest < Test::Unit::TestCase end end -end # uses_mocha - - class ParseGemVersionTest < Test::Unit::TestCase def test_should_return_nil_if_no_lines_are_passed assert_equal nil, parse('') diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb index f419fe0d8d..7a5de5af8f 100644 --- a/railties/test/console_app_test.rb +++ b/railties/test/console_app_test.rb @@ -23,20 +23,18 @@ class ConsoleAppTest < Test::Unit::TestCase end end - uses_mocha 'console reload test' do - def test_reload_should_fire_preparation_callbacks - a = b = c = nil + def test_reload_should_fire_preparation_callbacks + a = b = c = nil - Dispatcher.to_prepare { a = b = c = 1 } - Dispatcher.to_prepare { b = c = 2 } - Dispatcher.to_prepare { c = 3 } - ActionController::Routing::Routes.expects(:reload) + Dispatcher.to_prepare { a = b = c = 1 } + Dispatcher.to_prepare { b = c = 2 } + Dispatcher.to_prepare { c = 3 } + ActionController::Routing::Routes.expects(:reload) - reload! + reload! - assert_equal 1, a - assert_equal 2, b - assert_equal 3, c - end + assert_equal 1, a + assert_equal 2, b + assert_equal 3, c end end diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 6c1f0961a1..9cb02fcd06 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -6,141 +6,139 @@ end Rails::VendorGemSourceIndex.silence_spec_warnings = true -uses_mocha "Plugin Tests" do - class GemDependencyTest < Test::Unit::TestCase - def setup - @gem = Rails::GemDependency.new "xhpricotx" - @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net" - @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6" - @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3" - @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false - end +class GemDependencyTest < Test::Unit::TestCase + def setup + @gem = Rails::GemDependency.new "xhpricotx" + @gem_with_source = Rails::GemDependency.new "xhpricotx", :source => "http://code.whytheluckystiff.net" + @gem_with_version = Rails::GemDependency.new "xhpricotx", :version => "= 0.6" + @gem_with_lib = Rails::GemDependency.new "xaws-s3x", :lib => "aws/s3" + @gem_without_load = Rails::GemDependency.new "xhpricotx", :lib => false + end - def test_configuration_adds_gem_dependency - config = Rails::Configuration.new - config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0" - assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command) - end + def test_configuration_adds_gem_dependency + config = Rails::Configuration.new + config.gem "xaws-s3x", :lib => "aws/s3", :version => "0.4.0" + assert_equal [["install", "xaws-s3x", "--version", '"= 0.4.0"']], config.gems.collect(&:install_command) + end - def test_gem_creates_install_command - assert_equal %w(install xhpricotx), @gem.install_command - end + def test_gem_creates_install_command + assert_equal %w(install xhpricotx), @gem.install_command + end - def test_gem_with_source_creates_install_command - assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command - end + def test_gem_with_source_creates_install_command + assert_equal %w(install xhpricotx --source http://code.whytheluckystiff.net), @gem_with_source.install_command + end - def test_gem_with_version_creates_install_command - assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command - end + def test_gem_with_version_creates_install_command + assert_equal ["install", "xhpricotx", "--version", '"= 0.6"'], @gem_with_version.install_command + end - def test_gem_creates_unpack_command - assert_equal %w(unpack xhpricotx), @gem.unpack_command - end + def test_gem_creates_unpack_command + assert_equal %w(unpack xhpricotx), @gem.unpack_command + end - def test_gem_with_version_unpack_install_command - # stub out specification method, or else test will fail if hpricot 0.6 isn't installed - mock_spec = mock() - mock_spec.stubs(:version).returns('0.6') - @gem_with_version.stubs(:specification).returns(mock_spec) - assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command - end + def test_gem_with_version_unpack_install_command + # stub out specification method, or else test will fail if hpricot 0.6 isn't installed + mock_spec = mock() + mock_spec.stubs(:version).returns('0.6') + @gem_with_version.stubs(:specification).returns(mock_spec) + assert_equal ["unpack", "xhpricotx", "--version", '= 0.6'], @gem_with_version.unpack_command + end - def test_gem_adds_load_paths - @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) - @gem.add_load_paths - end + def test_gem_adds_load_paths + @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) + @gem.add_load_paths + end - def test_gem_with_version_adds_load_paths - @gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s)) - @gem_with_version.add_load_paths - end + def test_gem_with_version_adds_load_paths + @gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s)) + @gem_with_version.add_load_paths + end - def test_gem_loading - @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) - @gem.expects(:require).with(@gem.name) - @gem.add_load_paths - @gem.load - end + def test_gem_loading + @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) + @gem.expects(:require).with(@gem.name) + @gem.add_load_paths + @gem.load + end - def test_gem_with_lib_loading - @gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil)) - @gem_with_lib.expects(:require).with(@gem_with_lib.lib) - @gem_with_lib.add_load_paths - @gem_with_lib.load - end + def test_gem_with_lib_loading + @gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil)) + @gem_with_lib.expects(:require).with(@gem_with_lib.lib) + @gem_with_lib.add_load_paths + @gem_with_lib.load + end - def test_gem_without_lib_loading - @gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil)) - @gem_without_load.expects(:require).with(@gem_without_load.lib).never - @gem_without_load.add_load_paths - @gem_without_load.load - end + def test_gem_without_lib_loading + @gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil)) + @gem_without_load.expects(:require).with(@gem_without_load.lib).never + @gem_without_load.add_load_paths + @gem_without_load.load + end - def test_gem_dependencies_compare_for_uniq - gem1 = Rails::GemDependency.new "gem1" - gem1a = Rails::GemDependency.new "gem1" - gem2 = Rails::GemDependency.new "gem2" - gem2a = Rails::GemDependency.new "gem2" - gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1" - gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1" - gem4 = Rails::GemDependency.new "gem3" - gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4] - assert_equal 4, gems.uniq.size - end + def test_gem_dependencies_compare_for_uniq + gem1 = Rails::GemDependency.new "gem1" + gem1a = Rails::GemDependency.new "gem1" + gem2 = Rails::GemDependency.new "gem2" + gem2a = Rails::GemDependency.new "gem2" + gem3 = Rails::GemDependency.new "gem2", :version => ">=0.1" + gem3a = Rails::GemDependency.new "gem2", :version => ">=0.1" + gem4 = Rails::GemDependency.new "gem3" + gems = [gem1, gem2, gem1a, gem3, gem2a, gem4, gem3a, gem2, gem4] + assert_equal 4, gems.uniq.size + end - def test_gem_load_frozen - dummy_gem = Rails::GemDependency.new "dummy-gem-a" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_A_VERSION - end + def test_gem_load_frozen + dummy_gem = Rails::GemDependency.new "dummy-gem-a" + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_A_VERSION + end - def test_gem_load_frozen_specific_version - dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0' - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_B_VERSION - assert_equal '0.4.0', DUMMY_GEM_B_VERSION - end + def test_gem_load_frozen_specific_version + dummy_gem = Rails::GemDependency.new "dummy-gem-b", :version => '0.4.0' + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_B_VERSION + assert_equal '0.4.0', DUMMY_GEM_B_VERSION + end - def test_gem_load_frozen_minimum_version - dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0' - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_C_VERSION - assert_equal '0.6.0', DUMMY_GEM_C_VERSION - end + def test_gem_load_frozen_minimum_version + dummy_gem = Rails::GemDependency.new "dummy-gem-c", :version => '>=0.5.0' + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_C_VERSION + assert_equal '0.6.0', DUMMY_GEM_C_VERSION + end - def test_gem_load_missing_specification - dummy_gem = Rails::GemDependency.new "dummy-gem-d" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_D_VERSION - assert_equal '1.0.0', DUMMY_GEM_D_VERSION - assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files - end + def test_gem_load_missing_specification + dummy_gem = Rails::GemDependency.new "dummy-gem-d" + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_D_VERSION + assert_equal '1.0.0', DUMMY_GEM_D_VERSION + assert_equal ['lib', 'lib/dummy-gem-d.rb'], dummy_gem.specification.files + end - def test_gem_load_bad_specification - dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0" - dummy_gem.add_load_paths - dummy_gem.load - assert_not_nil DUMMY_GEM_E_VERSION - assert_equal '1.0.0', DUMMY_GEM_E_VERSION - end + def test_gem_load_bad_specification + dummy_gem = Rails::GemDependency.new "dummy-gem-e", :version => "= 1.0.0" + dummy_gem.add_load_paths + dummy_gem.load + assert_not_nil DUMMY_GEM_E_VERSION + assert_equal '1.0.0', DUMMY_GEM_E_VERSION + end - def test_gem_handle_missing_dependencies - dummy_gem = Rails::GemDependency.new "dummy-gem-g" - dummy_gem.add_load_paths - dummy_gem.load - assert dummy_gem.loaded? - assert_equal 2, dummy_gem.dependencies.size - assert_nothing_raised do - dummy_gem.dependencies.each do |g| - g.dependencies - end + def test_gem_handle_missing_dependencies + dummy_gem = Rails::GemDependency.new "dummy-gem-g" + dummy_gem.add_load_paths + dummy_gem.load + assert dummy_gem.loaded? + assert_equal 2, dummy_gem.dependencies.size + assert_nothing_raised do + dummy_gem.dependencies.each do |g| + g.dependencies end end - end + end diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/generators/rails_scaffold_generator_test.rb index 926607f55c..0155e463c7 100644 --- a/railties/test/generators/rails_scaffold_generator_test.rb +++ b/railties/test/generators/rails_scaffold_generator_test.rb @@ -107,17 +107,15 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_added_route_for :products end - uses_mocha("scaffold_force_plural_names") do - def test_scaffolded_plural_names - Rails::Generator::Base.logger.expects(:warning) - g = Rails::Generator::Base.instance('scaffold', %w(ProductLines)) - assert_equal "ProductLines", g.controller_name - assert_equal "ProductLines", g.controller_class_name - assert_equal "ProductLine", g.controller_singular_name - assert_equal "product_lines", g.controller_plural_name - assert_equal "product_lines", g.controller_file_name - assert_equal "product_lines", g.controller_table_name - end + def test_scaffolded_plural_names + Rails::Generator::Base.logger.expects(:warning) + g = Rails::Generator::Base.instance('scaffold', %w(ProductLines)) + assert_equal "ProductLines", g.controller_name + assert_equal "ProductLines", g.controller_class_name + assert_equal "ProductLine", g.controller_singular_name + assert_equal "product_lines", g.controller_plural_name + assert_equal "product_lines", g.controller_file_name + assert_equal "product_lines", g.controller_table_name end def test_scaffold_plural_model_name_without_force_plural_generates_singular_model diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index dad9e55e61..39372dc5ab 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -47,268 +47,260 @@ class Initializer_eager_loading_Test < Test::Unit::TestCase end end -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) +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 - - def teardown - $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil + config.after_initialize do + $test_after_initialize_block2 = "congratulations" end + assert_nil $test_after_initialize_block1 + assert_nil $test_after_initialize_block2 - def test_should_have_called_the_first_after_initialize_block - assert_equal "success", $test_after_initialize_block1 - end + Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) + Rails::Initializer.run(:after_initialize, config) + end - def test_should_have_called_the_second_after_initialize_block - assert_equal "congratulations", $test_after_initialize_block2 - end + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil end - class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase - def setup - config = ConfigurationMock.new("") - config.after_initialize do - $test_after_initialize_block1 = "success" - end - config.after_initialize # don't pass a block, this is what we're testing! - config.after_initialize do - $test_after_initialize_block2 = "congratulations" - end - assert_nil $test_after_initialize_block1 - - Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true) - Rails::Initializer.run(:after_initialize, config) - end + def test_should_have_called_the_first_after_initialize_block + assert_equal "success", $test_after_initialize_block1 + end - def teardown - $test_after_initialize_block1 = nil - $test_after_initialize_block2 = nil - end + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end +end - def test_should_have_called_the_first_after_initialize_block - assert_equal "success", $test_after_initialize_block1, "should still get set" +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 - - def test_should_have_called_the_second_after_initialize_block - assert_equal "congratulations", $test_after_initialize_block2 + 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 -end -uses_mocha 'framework paths' do - class ConfigurationFrameworkPathsTests < Test::Unit::TestCase - def setup - @config = Rails::Configuration.new - @config.frameworks.clear + def teardown + $test_after_initialize_block1 = nil + $test_after_initialize_block2 = nil + end - File.stubs(:directory?).returns(true) - @config.stubs(:framework_root_path).returns('') - 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_minimal - expected = %w( - /railties - /railties/lib - /activesupport/lib - ) - assert_equal expected, @config.framework_paths - end + def test_should_have_called_the_second_after_initialize_block + assert_equal "congratulations", $test_after_initialize_block2 + end +end - def test_actioncontroller_or_actionview_add_actionpack - @config.frameworks << :action_controller - assert_framework_path '/actionpack/lib' +class ConfigurationFrameworkPathsTests < Test::Unit::TestCase + def setup + @config = Rails::Configuration.new + @config.frameworks.clear - @config.frameworks = [:action_view] - assert_framework_path '/actionpack/lib' - end + File.stubs(:directory?).returns(true) + @config.stubs(:framework_root_path).returns('') + end - def test_paths_for_ar_ares_and_mailer - [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| - @config.frameworks = [framework] - assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib" - end - end + def test_minimal + expected = %w( + /railties + /railties/lib + /activesupport/lib + ) + assert_equal expected, @config.framework_paths + end + + def test_actioncontroller_or_actionview_add_actionpack + @config.frameworks << :action_controller + assert_framework_path '/actionpack/lib' - def test_unknown_framework_raises_error - @config.frameworks << :action_foo - initializer = Rails::Initializer.new @config - initializer.expects(:require).raises(LoadError) + @config.frameworks = [:action_view] + assert_framework_path '/actionpack/lib' + end - assert_raise RuntimeError do - initializer.send :require_frameworks - end + def test_paths_for_ar_ares_and_mailer + [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| + @config.frameworks = [framework] + assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib" end + end - def test_action_mailer_load_paths_set_only_if_action_mailer_in_use - @config.frameworks = [:action_controller] - initializer = Rails::Initializer.new @config - initializer.send :require_frameworks + def test_unknown_framework_raises_error + @config.frameworks << :action_foo + initializer = Rails::Initializer.new @config + initializer.expects(:require).raises(LoadError) - assert_nothing_raised NameError do - initializer.send :load_view_paths - end + assert_raise RuntimeError do + initializer.send :require_frameworks 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 + 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 - assert_nothing_raised NameError do - initializer.send :load_view_paths - end + assert_nothing_raised NameError do + initializer.send :load_view_paths end - - protected - def assert_framework_path(path) - assert @config.framework_paths.include?(path), - "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>" - end end -end -uses_mocha "Initializer plugin loading tests" do - require File.dirname(__FILE__) + '/plugin_test_helper' + def test_action_controller_load_paths_set_only_if_action_controller_in_use + @config.frameworks = [] + initializer = Rails::Initializer.new @config + initializer.send :require_frameworks - class InitializerPluginLoadingTests < Test::Unit::TestCase - def setup - @configuration = Rails::Configuration.new - @configuration.plugin_paths << plugin_fixture_root_path - @initializer = Rails::Initializer.new(@configuration) - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') + assert_nothing_raised NameError do + initializer.send :load_view_paths end + end - def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list - only_load_the_following_plugins! [] - @initializer.load_plugins - assert_equal [], @initializer.loaded_plugins + protected + def assert_framework_path(path) + assert @config.framework_paths.include?(path), + "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>" end +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 - end +require File.dirname(__FILE__) + '/plugin_test_helper' - 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 - end +class InitializerPluginLoadingTests < Test::Unit::TestCase + def setup + @configuration = Rails::Configuration.new + @configuration.plugin_paths << plugin_fixture_root_path + @initializer = Rails::Initializer.new(@configuration) + @valid_plugin_path = plugin_fixture_path('default/stubby') + @empty_plugin_path = plugin_fixture_path('default/empty') + end - def test_all_plugins_loaded_when_all_is_used - plugin_names = [:stubby, :acts_as_chunky_bacon, :all] - only_load_the_following_plugins! plugin_names - load_plugins! - failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip - end + def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list + only_load_the_following_plugins! [] + @initializer.load_plugins + assert_equal [], @initializer.loaded_plugins + end - def test_all_plugins_loaded_after_all - plugin_names = [:stubby, :all, :acts_as_chunky_bacon] - only_load_the_following_plugins! plugin_names - load_plugins! - failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip - 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 + end - def test_plugin_names_may_be_strings - plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] - only_load_the_following_plugins! plugin_names - load_plugins! - failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_plugins plugin_names, @initializer.loaded_plugins, failure_tip - 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 + end - def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error - only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin] - assert_raises(LoadError) do - load_plugins! - end - end + def test_all_plugins_loaded_when_all_is_used + plugin_names = [:stubby, :acts_as_chunky_bacon, :all] + only_load_the_following_plugins! plugin_names + load_plugins! + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip + end - def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + def test_all_plugins_loaded_after_all + plugin_names = [:stubby, :all, :acts_as_chunky_bacon] + only_load_the_following_plugins! plugin_names + load_plugins! + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip + end - @initializer.add_plugin_load_paths + def test_plugin_names_may_be_strings + plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + only_load_the_following_plugins! plugin_names + load_plugins! + failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + assert_plugins plugin_names, @initializer.loaded_plugins, failure_tip + end - 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')) + def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error + only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin] + assert_raises(LoadError) do + load_plugins! end + end + def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - private + @initializer.add_plugin_load_paths - def load_plugins! - @initializer.add_plugin_load_paths - @initializer.load_plugins - end + assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end -end -uses_mocha 'i18n settings' do - class InitializerSetupI18nTests < Test::Unit::TestCase - def test_no_config_locales_dir_present_should_return_empty_load_path - File.stubs(:exist?).returns(false) - assert_equal [], Rails::Configuration.new.i18n.load_path - end - def test_config_locales_dir_present_should_be_added_to_load_path - File.stubs(:exist?).returns(true) - Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) - assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path + private + + def load_plugins! + @initializer.add_plugin_load_paths + @initializer.load_plugins end - - def test_config_defaults_should_be_added_with_config_settings - File.stubs(:exist?).returns(true) - Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) +end + +class InitializerSetupI18nTests < Test::Unit::TestCase + def test_no_config_locales_dir_present_should_return_empty_load_path + File.stubs(:exist?).returns(false) + assert_equal [], Rails::Configuration.new.i18n.load_path + end - config = Rails::Configuration.new - config.i18n.load_path << "my/other/locale.yml" + def test_config_locales_dir_present_should_be_added_to_load_path + File.stubs(:exist?).returns(true) + Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) + assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path + end + + def test_config_defaults_should_be_added_with_config_settings + File.stubs(:exist?).returns(true) + Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) - assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path - end - - def test_config_defaults_and_settings_should_be_added_to_i18n_defaults - File.stubs(:exist?).returns(true) - Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) - - config = Rails::Configuration.new - config.i18n.load_path << "my/other/locale.yml" - - # To bring in AV's i18n load path. - require 'action_view' - - Rails::Initializer.run(:initialize_i18n, config) - assert_equal [ - File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"), - File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"), - "my/test/locale.yml", - "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } - end - - def test_setting_another_default_locale - config = Rails::Configuration.new - config.i18n.default_locale = :de - Rails::Initializer.run(:initialize_i18n, config) - assert_equal :de, I18n.default_locale - end + config = Rails::Configuration.new + config.i18n.load_path << "my/other/locale.yml" + + assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path + end + + def test_config_defaults_and_settings_should_be_added_to_i18n_defaults + File.stubs(:exist?).returns(true) + Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) + + config = Rails::Configuration.new + config.i18n.load_path << "my/other/locale.yml" + + # To bring in AV's i18n load path. + require 'action_view' + + Rails::Initializer.run(:initialize_i18n, config) + assert_equal [ + File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"), + File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"), + "my/test/locale.yml", + "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } + end + + def test_setting_another_default_locale + config = Rails::Configuration.new + config.i18n.default_locale = :de + Rails::Initializer.run(:initialize_i18n, config) + assert_equal :de, I18n.default_locale end end @@ -320,4 +312,4 @@ class RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_should_be_a_pathname assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s end -end \ No newline at end of file +end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index 5a8c651e5a..c8404e126e 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -1,69 +1,62 @@ require 'plugin_test_helper' -uses_mocha "Plugin Locator Tests" do - - class PluginLocatorTest < Test::Unit::TestCase - - def test_should_require_subclasses_to_implement_the_plugins_method - assert_raises(RuntimeError) do - Rails::Plugin::Locator.new(nil).plugins - end +class PluginLocatorTest < Test::Unit::TestCase + def test_should_require_subclasses_to_implement_the_plugins_method + assert_raises(RuntimeError) do + Rails::Plugin::Locator.new(nil).plugins end + end + + def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each + locator = Rails::Plugin::Locator.new(nil) + locator.stubs(:plugins).returns([:a, :b, :c]) + plugin_consumer = mock + plugin_consumer.expects(:consume).with(:a) + plugin_consumer.expects(:consume).with(:b) + plugin_consumer.expects(:consume).with(:c) - def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each - locator = Rails::Plugin::Locator.new(nil) - locator.stubs(:plugins).returns([:a, :b, :c]) - plugin_consumer = mock - plugin_consumer.expects(:consume).with(:a) - plugin_consumer.expects(:consume).with(:b) - plugin_consumer.expects(:consume).with(:c) - - locator.each do |plugin| - plugin_consumer.consume(plugin) - end + locator.each do |plugin| + plugin_consumer.consume(plugin) end - end +end +class PluginFileSystemLocatorTest < Test::Unit::TestCase + def setup + @configuration = Rails::Configuration.new + # 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) + @locator = Rails::Plugin::FileSystemLocator.new(@initializer) + @valid_plugin_path = plugin_fixture_path('default/stubby') + @empty_plugin_path = plugin_fixture_path('default/empty') + end - class PluginFileSystemLocatorTest < Test::Unit::TestCase - def setup - @configuration = Rails::Configuration.new - # 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) - @locator = Rails::Plugin::FileSystemLocator.new(@initializer) - @valid_plugin_path = plugin_fixture_path('default/stubby') - @empty_plugin_path = plugin_fixture_path('default/empty') - end + def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory + assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path) + end - def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory - assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path) - end - - def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory - assert_nil @locator.send(:create_plugin, @empty_plugin_path) - end - - def test_should_return_all_plugins_found_under_the_set_plugin_paths - assert_equal ["a", "acts_as_chunky_bacon", "engine", "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", "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) - end + def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory + assert_nil @locator.send(:create_plugin, @empty_plugin_path) + end + + def test_should_return_all_plugins_found_under_the_set_plugin_paths + assert_equal ["a", "acts_as_chunky_bacon", "engine", "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", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort - def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist - @configuration.plugin_paths = ["some_missing_directory"] - assert_nothing_raised do - assert @locator.plugins.empty? - end - end + @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")] + assert_equal ["a"], @locator.plugins.map(&:name) end -end # uses_mocha + def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist + @configuration.plugin_paths = ["some_missing_directory"] + assert_nothing_raised do + assert @locator.plugins.empty? + end + end +end diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb index 50124240a5..5500711df8 100644 --- a/railties/test/plugin_test.rb +++ b/railties/test/plugin_test.rb @@ -1,167 +1,162 @@ require 'plugin_test_helper' -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') + @gemlike_plugin_path = plugin_fixture_path('default/gemlike') + end - class PluginTest < Test::Unit::TestCase + def test_should_determine_plugin_name_from_the_directory_of_the_plugin + assert_equal 'stubby', plugin_for(@valid_plugin_path).name + assert_equal 'empty', plugin_for(@empty_plugin_path).name + end - 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') - @gemlike_plugin_path = plugin_fixture_path('default/gemlike') - end + def test_should_not_be_loaded_when_created + assert !plugin_for(@valid_plugin_path).loaded? + end - def test_should_determine_plugin_name_from_the_directory_of_the_plugin - assert_equal 'stubby', plugin_for(@valid_plugin_path).name - assert_equal 'empty', plugin_for(@empty_plugin_path).name + def test_should_be_marked_as_loaded_when_load_is_called + plugin = plugin_for(@valid_plugin_path) + assert !plugin.loaded? + plugin.stubs(:evaluate_init_rb) + assert_nothing_raised do + plugin.send(:load, anything) end + assert plugin.loaded? + end - def test_should_not_be_loaded_when_created - assert !plugin_for(@valid_plugin_path).loaded? - end + def test_should_determine_validity_of_given_path + # This is a plugin path, with a lib dir + assert plugin_for(@valid_plugin_path).valid? + # This just has an init.rb and no lib dir + assert plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).valid? + # This would be a plugin path, but the directory is empty + assert !plugin_for(plugin_fixture_path('default/empty')).valid? + # This is a non sense path + assert !plugin_for(plugin_fixture_path('default/this_directory_does_not_exist')).valid? + end - def test_should_be_marked_as_loaded_when_load_is_called - plugin = plugin_for(@valid_plugin_path) - assert !plugin.loaded? - plugin.stubs(:evaluate_init_rb) - assert_nothing_raised do - plugin.send(:load, anything) - end - assert plugin.loaded? - end - - def test_should_determine_validity_of_given_path - # This is a plugin path, with a lib dir - assert plugin_for(@valid_plugin_path).valid? - # This just has an init.rb and no lib dir - assert plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).valid? - # This would be a plugin path, but the directory is empty - assert !plugin_for(plugin_fixture_path('default/empty')).valid? - # This is a non sense path - assert !plugin_for(plugin_fixture_path('default/this_directory_does_not_exist')).valid? + def test_should_return_empty_array_for_load_paths_when_plugin_has_no_lib_directory + assert_equal [], plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).load_paths + end + + def test_should_return_array_with_lib_path_for_load_paths_when_plugin_has_a_lib_directory + expected_lib_dir = File.join(plugin_fixture_path('default/stubby'), 'lib') + assert_equal [expected_lib_dir], plugin_for(plugin_fixture_path('default/stubby')).load_paths + end + + def test_should_raise_a_load_error_when_trying_to_determine_the_load_paths_from_an_invalid_plugin + assert_nothing_raised do + plugin_for(@valid_plugin_path).load_paths end - def test_should_return_empty_array_for_load_paths_when_plugin_has_no_lib_directory - assert_equal [], plugin_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).load_paths + assert_raises(LoadError) do + plugin_for(@empty_plugin_path).load_paths end - def test_should_return_array_with_lib_path_for_load_paths_when_plugin_has_a_lib_directory - expected_lib_dir = File.join(plugin_fixture_path('default/stubby'), 'lib') - assert_equal [expected_lib_dir], plugin_for(plugin_fixture_path('default/stubby')).load_paths + assert_raises(LoadError) do + plugin_for('this_is_not_a_plugin_directory').load_paths end - - def test_should_raise_a_load_error_when_trying_to_determine_the_load_paths_from_an_invalid_plugin - assert_nothing_raised do - plugin_for(@valid_plugin_path).load_paths - end - - assert_raises(LoadError) do - plugin_for(@empty_plugin_path).load_paths - end - - assert_raises(LoadError) do - plugin_for('this_is_not_a_plugin_directory').load_paths - end + end + + def test_should_raise_a_load_error_when_trying_to_load_an_invalid_plugin + # This path is fine so nothing is raised + assert_nothing_raised do + plugin = plugin_for(@valid_plugin_path) + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) end - - def test_should_raise_a_load_error_when_trying_to_load_an_invalid_plugin - # This path is fine so nothing is raised - assert_nothing_raised do - plugin = plugin_for(@valid_plugin_path) - 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 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) - plugin.stubs(:evaluate_init_rb) - plugin.send(:load, @initializer) - end - - assert_raises(LoadError) do - plugin = plugin_for('this_is_not_a_plugin_directory') - 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) + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) end - - def test_should_raise_a_load_error_when_trying_to_access_load_paths_of_an_invalid_plugin - # This path is fine so nothing is raised - assert_nothing_raised do - plugin_for(@valid_plugin_path).load_paths - end - - # This is an empty path so it raises - assert_raises(LoadError) do - plugin_for(@empty_plugin_path).load_paths - end - - assert_raises(LoadError) do - plugin_for('this_is_not_a_plugin_directory').load_paths - end - end - def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs - failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already." - assert !defined?(StubbyMixin), failure_tip - plugin = plugin_for(@valid_plugin_path) - plugin.load_paths.each { |path| $LOAD_PATH.unshift(path) } - # The init.rb of this plugin raises if it doesn't have access to all the things it needs - assert_nothing_raised do - plugin.load(@initializer) - end - assert defined?(StubbyMixin) + assert_raises(LoadError) do + plugin = plugin_for('this_is_not_a_plugin_directory') + plugin.stubs(:evaluate_init_rb) + plugin.send(:load, @initializer) end - - def test_should_sort_naturally_by_name - a = plugin_for("path/a") - b = plugin_for("path/b") - z = plugin_for("path/z") - assert_equal [a, b, z], [b, z, a].sort + end + + def test_should_raise_a_load_error_when_trying_to_access_load_paths_of_an_invalid_plugin + # This path is fine so nothing is raised + assert_nothing_raised do + plugin_for(@valid_plugin_path).load_paths end - - def test_should_only_be_loaded_once - plugin = plugin_for(@valid_plugin_path) - assert !plugin.loaded? - plugin.expects(:evaluate_init_rb) - assert_nothing_raised do - plugin.send(:load, @initializer) - plugin.send(:load, @initializer) - end - assert plugin.loaded? + + # This is an empty path so it raises + assert_raises(LoadError) do + plugin_for(@empty_plugin_path).load_paths end - - def test_should_make_about_yml_available_as_about_method_on_plugin - plugin = plugin_for(@valid_plugin_path) - assert_equal "Plugin Author", plugin.about['author'] - assert_equal "1.0.0", plugin.about['version'] + + assert_raises(LoadError) do + plugin_for('this_is_not_a_plugin_directory').load_paths end - - def test_should_return_empty_hash_for_about_if_about_yml_is_missing - assert_equal({}, plugin_for(about_yml_plugin_path('plugin_without_about_yaml')).about) + end + + def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs + failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already." + assert !defined?(StubbyMixin), failure_tip + plugin = plugin_for(@valid_plugin_path) + plugin.load_paths.each { |path| $LOAD_PATH.unshift(path) } + # The init.rb of this plugin raises if it doesn't have access to all the things it needs + assert_nothing_raised do + plugin.load(@initializer) end - - def test_should_return_empty_hash_for_about_if_about_yml_is_malformed - assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about) + assert defined?(StubbyMixin) + end + + def test_should_sort_naturally_by_name + a = plugin_for("path/a") + b = plugin_for("path/b") + z = plugin_for("path/z") + assert_equal [a, b, z], [b, z, a].sort + end + + def test_should_only_be_loaded_once + plugin = plugin_for(@valid_plugin_path) + assert !plugin.loaded? + plugin.expects(:evaluate_init_rb) + assert_nothing_raised do + plugin.send(:load, @initializer) + plugin.send(:load, @initializer) end + assert plugin.loaded? + end - private + def test_should_make_about_yml_available_as_about_method_on_plugin + plugin = plugin_for(@valid_plugin_path) + assert_equal "Plugin Author", plugin.about['author'] + assert_equal "1.0.0", plugin.about['version'] + end - def about_yml_plugin_path(name) - File.join(File.dirname(__FILE__), 'fixtures', 'about_yml_plugins', name) - end + def test_should_return_empty_hash_for_about_if_about_yml_is_missing + assert_equal({}, plugin_for(about_yml_plugin_path('plugin_without_about_yaml')).about) + end - def plugin_for(path) - Rails::Plugin.new(path) - end + def test_should_return_empty_hash_for_about_if_about_yml_is_malformed + assert_equal({}, plugin_for(about_yml_plugin_path('bad_about_yml')).about) end -end # uses_mocha + private + + def about_yml_plugin_path(name) + File.join(File.dirname(__FILE__), 'fixtures', 'about_yml_plugins', name) + end + + def plugin_for(path) + Rails::Plugin.new(path) + end +end -- cgit v1.2.3 From 4866ce45d0ab66a1b237c55e21be730de282b059 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Thu, 5 Feb 2009 14:00:57 -0600 Subject: Fix broken scaffolding tests [#1889 state:committed] Signed-off-by: David Heinemeier Hansson --- railties/test/generators/rails_scaffold_generator_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/generators/rails_scaffold_generator_test.rb index 0155e463c7..70829a77fd 100644 --- a/railties/test/generators/rails_scaffold_generator_test.rb +++ b/railties/test/generators/rails_scaffold_generator_test.rb @@ -19,7 +19,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_controller_for :products do |f| assert_has_method f, :index do |name, m| - assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" + assert_match /@products = Product\.all/, m, "#{name} should query products table" end assert_has_method f, :show, :edit, :update, :destroy do |name, m| @@ -71,7 +71,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_controller_for :products do |f| assert_has_method f, :index do |name, m| - assert_match /@products = Product\.find\(:all\)/, m, "#{name} should query products table" + assert_match /@products = Product\.all/, m, "#{name} should query products table" end assert_has_method f, :show, :edit, :update, :destroy do |name, m| -- cgit v1.2.3 From 10b6073968eb43a3e20efd352d97d08720beeb12 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 6 Feb 2009 15:22:04 +0100 Subject: This is no longer relevant when the 500.html is comletely static --- railties/test/error_page_test.rb | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 railties/test/error_page_test.rb (limited to 'railties/test') diff --git a/railties/test/error_page_test.rb b/railties/test/error_page_test.rb deleted file mode 100644 index f819e468e8..0000000000 --- a/railties/test/error_page_test.rb +++ /dev/null @@ -1,40 +0,0 @@ -require 'abstract_unit' -require 'action_controller' -require 'action_controller/test_case' - -RAILS_ENV = "test" -CURRENT_DIR = File.expand_path(File.dirname(__FILE__)) -HTML_DIR = File.expand_path(File.join(CURRENT_DIR, "..", "html")) - -module Rails - def self.public_path - CURRENT_DIR - end -end - -class ErrorPageController < ActionController::Base - def crash - raise StandardError, "crash!" - end -end - -ActionController::Routing::Routes.draw do |map| - map.connect ':controller/:action/:id' -end - -class ErrorPageControllerTest < ActionController::TestCase - def setup - ActionController::Base.consider_all_requests_local = false - rescue_action_in_public! - end - - def test_500_error_page_instructs_system_administrator_to_check_log_file - template = ERB.new(File.read(File.join(HTML_DIR, "500.html"))) - File.open(File.join(CURRENT_DIR, "500.html"), "w") do |f| - f.write(template.result) - end - get :crash - expected_log_file = "#{RAILS_ENV}.log" - assert_not_nil @response.body.index(expected_log_file), @response.body - end -end -- cgit v1.2.3 From f98d8ee72b2fd92bf0e09f3cade60add9efd3a15 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sat, 7 Feb 2009 00:35:15 -0600 Subject: Fix up failing tests broke by 2316e7d --- railties/test/fcgi_dispatcher_test.rb | 61 ++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'railties/test') diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb index c469c5dd01..805c4f3a60 100644 --- a/railties/test/fcgi_dispatcher_test.rb +++ b/railties/test/fcgi_dispatcher_test.rb @@ -4,6 +4,8 @@ begin require 'action_controller' require 'fcgi_handler' +Dispatcher.middleware.clear + class RailsFCGIHandlerTest < Test::Unit::TestCase def setup @log = StringIO.new @@ -11,14 +13,14 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase end def test_process_restart - cgi = mock - FCGI.stubs(:each_cgi).yields(cgi) + request = mock + FCGI.stubs(:each).yields(request) @handler.expects(:process_request).once @handler.expects(:dispatcher_error).never @handler.expects(:when_ready).returns(:restart) - @handler.expects(:close_connection).with(cgi) + @handler.expects(:close_connection).with(request) @handler.expects(:reload!).never @handler.expects(:restart!) @@ -26,14 +28,14 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase end def test_process_exit - cgi = mock - FCGI.stubs(:each_cgi).yields(cgi) + request = mock + FCGI.stubs(:each).yields(request) @handler.expects(:process_request).once @handler.expects(:dispatcher_error).never @handler.expects(:when_ready).returns(:exit) - @handler.expects(:close_connection).with(cgi) + @handler.expects(:close_connection).with(request) @handler.expects(:reload!).never @handler.expects(:restart!).never @@ -41,8 +43,8 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase end def test_process_with_system_exit_exception - cgi = mock - FCGI.stubs(:each_cgi).yields(cgi) + request = mock + FCGI.stubs(:each).yields(request) @handler.expects(:process_request).once.raises(SystemExit) @handler.stubs(:dispatcher_log) @@ -110,9 +112,9 @@ class RailsFCGIHandlerTest < Test::Unit::TestCase end def test_uninterrupted_processing - cgi = mock - FCGI.expects(:each_cgi).yields(cgi) - @handler.expects(:process_request).with(cgi) + request = mock + FCGI.expects(:each).yields(request) + @handler.expects(:process_request).with(request) @handler.process! @@ -138,8 +140,8 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase end def test_interrupted_via_HUP_when_not_in_request - cgi = mock - FCGI.expects(:each_cgi).once.yields(cgi) + request = mock + FCGI.expects(:each).once.yields(request) @handler.expects(:signal).times(2).returns('HUP') @handler.expects(:reload!).once @@ -151,13 +153,13 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase end def test_interrupted_via_USR1_when_not_in_request - cgi = mock - FCGI.expects(:each_cgi).once.yields(cgi) + request = mock + FCGI.expects(:each).once.yields(request) @handler.expects(:signal).times(2).returns('USR1') @handler.expects(:exit_handler).never @handler.expects(:reload!).never - @handler.expects(:close_connection).with(cgi).once + @handler.expects(:close_connection).with(request).once @handler.expects(:exit).never @handler.process! @@ -165,13 +167,13 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase end def test_restart_via_USR2_when_in_request - cgi = mock - FCGI.expects(:each_cgi).once.yields(cgi) + request = mock + FCGI.expects(:each).once.yields(request) @handler.expects(:signal).times(2).returns('USR2') @handler.expects(:exit_handler).never @handler.expects(:reload!).never - @handler.expects(:close_connection).with(cgi).once + @handler.expects(:close_connection).with(request).once @handler.expects(:exit).never @handler.expects(:restart!).once @@ -180,8 +182,8 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase end def test_interrupted_via_TERM - cgi = mock - FCGI.expects(:each_cgi).once.yields(cgi) + request = mock + FCGI.expects(:each).once.yields(request) ::Rack::Handler::FastCGI.expects(:serve).once.returns('TERM') @handler.expects(:reload!).never @@ -193,16 +195,16 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_runtime_exception_in_fcgi error = RuntimeError.new('foo') - FCGI.expects(:each_cgi).times(2).raises(error) + FCGI.expects(:each).times(2).raises(error) @handler.expects(:dispatcher_error).with(error, regexp_matches(/^retrying/)) @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/)) @handler.process! end def test_runtime_error_in_dispatcher - cgi = mock + request = mock error = RuntimeError.new('foo') - FCGI.expects(:each_cgi).once.yields(cgi) + FCGI.expects(:each).once.yields(request) ::Rack::Handler::FastCGI.expects(:serve).once.raises(error) @handler.expects(:dispatcher_error).with(error, regexp_matches(/^unhandled/)) @handler.process! @@ -210,15 +212,15 @@ class RailsFCGIHandlerSignalsTest < Test::Unit::TestCase def test_signal_exception_in_fcgi error = SignalException.new('USR2') - FCGI.expects(:each_cgi).once.raises(error) + FCGI.expects(:each).once.raises(error) @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/)) @handler.process! end def test_signal_exception_in_dispatcher - cgi = mock + request = mock error = SignalException.new('USR2') - FCGI.expects(:each_cgi).once.yields(cgi) + FCGI.expects(:each).once.yields(request) ::Rack::Handler::FastCGI.expects(:serve).once.raises(error) @handler.expects(:dispatcher_error).with(error, regexp_matches(/^stopping/)) @handler.process! @@ -247,9 +249,8 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase @handler = RailsFCGIHandler.new(@log, 10) assert_equal 10, @handler.gc_request_period - cgi = mock - FCGI.expects(:each_cgi).times(10).yields(cgi) - Dispatcher.expects(:new).times(10) + request = mock + FCGI.expects(:each).times(10).yields(request) @handler.expects(:run_gc!).never 9.times { @handler.process! } -- cgit v1.2.3 From 3942cb406e1d5db0ac00e03153809cc8dc4cc4db Mon Sep 17 00:00:00 2001 From: thedarkone Date: Thu, 12 Feb 2009 19:35:14 +0100 Subject: Port fast reloadable templates from rails-dev-boost. --- railties/test/plugin_loader_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 23b81ddbf6..59491fe99e 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -130,7 +130,7 @@ class TestPluginLoader < Test::Unit::TestCase @loader.send :add_engine_view_paths - assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths + assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views').sub(/\A\.\//, '') ], ActionController::Base.view_paths end def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths -- cgit v1.2.3 From a6508527570cd3f7225a7030218447bcc5824224 Mon Sep 17 00:00:00 2001 From: Oshoma Momoh Date: Mon, 9 Feb 2009 10:29:15 -0500 Subject: Fix loader's LoadError exception message to mention missing plugins and omit loaded plugins. Prior to this change the LoadError message listed all plugins if any one of them was missing. Signed-off-by: Michael Koziarski [#1921 state:committed] --- railties/test/initializer_test.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 39372dc5ab..2ab4101eaf 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -238,6 +238,26 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase end end + def test_load_error_messages_mention_missing_plugins_and_no_others + valid_plugin_names = [:stubby, :acts_as_chunky_bacon] + invalid_plugin_names = [:non_existant_plugin1, :non_existant_plugin2] + only_load_the_following_plugins!( valid_plugin_names + invalid_plugin_names ) + begin + load_plugins! + flunk "Expected a LoadError but did not get one" + rescue LoadError => e + failure_tip = "It's likely someone renamed or deleted plugin fixtures without updating this test" + assert_plugins valid_plugin_names, @initializer.loaded_plugins, failure_tip + invalid_plugin_names.each do |plugin| + assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'") + end + valid_plugin_names.each do |plugin| + assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'") + end + + end + end + def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] -- cgit v1.2.3 From 2414fdb244cc0ba97620dd3f50e269d2e26c7392 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 3 Feb 2009 13:03:47 +0000 Subject: Ensure template_runner can run script/* ruby scripts under Windows. [#1859 state:resolved] Signed-off-by: Pratik Naik --- railties/test/generators/rails_template_runner_test.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb index fcc020603d..56afc85eba 100644 --- a/railties/test/generators/rails_template_runner_test.rb +++ b/railties/test/generators/rails_template_runner_test.rb @@ -53,12 +53,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase end def test_plugin_with_git_option_should_run_plugin_install - expects_run_with_command("script/plugin install #{@git_plugin_uri}") + expects_run_ruby_script_with_command("script/plugin install #{@git_plugin_uri}") run_template_method(:plugin, 'restful-authentication', :git => @git_plugin_uri) end def test_plugin_with_svn_option_should_run_plugin_install - expects_run_with_command("script/plugin install #{@svn_plugin_uri}") + expects_run_ruby_script_with_command("script/plugin install #{@svn_plugin_uri}") run_template_method(:plugin, 'restful-authentication', :svn => @svn_plugin_uri) end @@ -127,7 +127,7 @@ class RailsTemplateRunnerTest < GeneratorTestCase end def test_generate_should_run_script_generate_with_argument_and_options - expects_run_with_command('script/generate model MyModel') + expects_run_ruby_script_with_command('script/generate model MyModel') run_template_method(:generate, 'model', 'MyModel') end @@ -162,6 +162,12 @@ class RailsTemplateRunnerTest < GeneratorTestCase assert_generated_file_with_data 'config/routes.rb', route_command end + def test_run_ruby_script_should_add_ruby_to_command_in_win32_environment + ruby_command = RUBY_PLATFORM =~ /win32/ ? 'ruby ' : '' + expects_run_with_command("#{ruby_command}script/generate model MyModel") + run_template_method(:generate, 'model', 'MyModel') + end + protected def run_template_method(method_name, *args, &block) silence_generator do @@ -174,6 +180,10 @@ class RailsTemplateRunnerTest < GeneratorTestCase Rails::TemplateRunner.any_instance.stubs(:run).once.with(command, false) end + def expects_run_ruby_script_with_command(command) + Rails::TemplateRunner.any_instance.stubs(:run_ruby_script).once.with(command,false) + end + def assert_rails_initializer_includes(data, message = nil) message ||= "Rails::Initializer should include #{data}" assert_generated_file 'config/environment.rb' do |body| -- cgit v1.2.3 From c33ab118f8207f2fe6226a01587ee1e950055873 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 16 Feb 2009 15:12:28 -0600 Subject: Properly skip fcgi tests if the gem is not installed --- railties/test/abstract_unit.rb | 8 ++++++++ railties/test/fcgi_dispatcher_test.rb | 8 +++----- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 43736ee7ec..a950fc8b7e 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -18,3 +18,11 @@ if defined?(RAILS_ROOT) else RAILS_ROOT = File.dirname(__FILE__) end + +def uses_gem(gem_name, test_name, version = '> 0') + gem gem_name.to_s, version + require gem_name.to_s + yield +rescue LoadError + $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again." +end diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb index 805c4f3a60..c7a7f77118 100644 --- a/railties/test/fcgi_dispatcher_test.rb +++ b/railties/test/fcgi_dispatcher_test.rb @@ -1,6 +1,7 @@ require 'abstract_unit' -begin +uses_gem "fcgi", "0.8.7" do + require 'action_controller' require 'fcgi_handler' @@ -260,7 +261,4 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase assert_nil @handler.when_ready end end - -rescue LoadError => e - raise unless e.message =~ /fcgi/ -end +end # uses_gem "fcgi" -- cgit v1.2.3 From f8ea9f85d4f1e3e6f3b5d895bef6b013aa4b0690 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 19 Feb 2009 20:55:56 -0600 Subject: Fix templates reloading in development when using custom view path [#2012 state:resolved] --- railties/test/plugin_loader_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 59491fe99e..23b81ddbf6 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -130,7 +130,7 @@ class TestPluginLoader < Test::Unit::TestCase @loader.send :add_engine_view_paths - assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views').sub(/\A\.\//, '') ], ActionController::Base.view_paths + assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths end def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths -- cgit v1.2.3 From 441e4e22352c8805a882f6a661ab3982dd7eda12 Mon Sep 17 00:00:00 2001 From: Sven Fuchs Date: Sun, 22 Feb 2009 10:39:56 -0600 Subject: load plugin view_paths to action_mailer view_paths and make action_mailer use them [#2031 state:resolved] Signed-off-by: Joshua Peek --- railties/test/initializer_test.rb | 5 +++-- railties/test/plugin_loader_test.rb | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 2ab4101eaf..eb9ec750da 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -182,6 +182,7 @@ require File.dirname(__FILE__) + '/plugin_test_helper' class InitializerPluginLoadingTests < Test::Unit::TestCase def setup @configuration = Rails::Configuration.new + @configuration.frameworks -= [:action_mailer] @configuration.plugin_paths << plugin_fixture_root_path @initializer = Rails::Initializer.new(@configuration) @valid_plugin_path = plugin_fixture_path('default/stubby') @@ -310,8 +311,8 @@ class InitializerSetupI18nTests < Test::Unit::TestCase Rails::Initializer.run(:initialize_i18n, config) assert_equal [ - File.expand_path("./test/../../activesupport/lib/active_support/locale/en.yml"), - File.expand_path("./test/../../actionpack/lib/action_view/locale/en.yml"), + 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"), "my/test/locale.yml", "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } end diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 23b81ddbf6..e802b1ace7 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -1,7 +1,9 @@ require 'plugin_test_helper' $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" +$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib" require 'action_controller' +require 'action_mailer' # Mocks out the configuration module Rails @@ -125,14 +127,15 @@ class TestPluginLoader < Test::Unit::TestCase end end - def test_engine_controllers_should_have_their_view_path_set_when_loaded + def test_engine_controllers_and_action_mailers_should_have_their_view_path_set_when_loaded only_load_the_following_plugins!([ :engine ]) @loader.send :add_engine_view_paths assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths + assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionMailer::Base.view_paths end - + def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] -- cgit v1.2.3 From ea5d288606cac0b6055dd4e088cfb848f3b9b78f Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Wed, 25 Feb 2009 11:36:10 +0100 Subject: Test database middleware loading from the initializer. Signed-off-by: Joshua Peek --- railties/test/abstract_unit.rb | 3 ++- railties/test/initializer_test.rb | 57 ++++++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 10 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index a950fc8b7e..0775b3ff55 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,4 +1,5 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" +$:.unshift File.dirname(__FILE__) + "/../../activerecord/lib" $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" @@ -25,4 +26,4 @@ def uses_gem(gem_name, test_name, version = '> 0') yield rescue LoadError $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again." -end +end \ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index eb9ec750da..2c448f6dbd 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -1,6 +1,9 @@ require 'abstract_unit' require 'initializer' +require 'action_view' +require 'active_record' + # Mocks out the configuration module Rails def self.configuration @@ -26,7 +29,6 @@ class Initializer_load_environment_Test < Test::Unit::TestCase ensure $initialize_test_set_from_env = nil end - end class Initializer_eager_loading_Test < Test::Unit::TestCase @@ -268,7 +270,6 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end - private def load_plugins! @@ -288,7 +289,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path end - + def test_config_defaults_should_be_added_with_config_settings File.stubs(:exist?).returns(true) Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) @@ -298,7 +299,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path end - + def test_config_defaults_and_settings_should_be_added_to_i18n_defaults File.stubs(:exist?).returns(true) Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) @@ -306,17 +307,15 @@ class InitializerSetupI18nTests < Test::Unit::TestCase config = Rails::Configuration.new config.i18n.load_path << "my/other/locale.yml" - # To bring in AV's i18n load path. - require 'action_view' - Rails::Initializer.run(:initialize_i18n, config) assert_equal [ File.expand_path(File.dirname(__FILE__) + "/../../activesupport/lib/active_support/locale/en.yml"), File.expand_path(File.dirname(__FILE__) + "/../../actionpack/lib/action_view/locale/en.yml"), + File.expand_path(File.dirname(__FILE__) + "/../../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 } end - + def test_setting_another_default_locale config = Rails::Configuration.new config.i18n.default_locale = :de @@ -325,6 +324,46 @@ class InitializerSetupI18nTests < Test::Unit::TestCase end end +class InitializerDatabaseMiddlewareTest < Test::Unit::TestCase + def setup + @config = Rails::Configuration.new + @config.frameworks = [:active_record, :action_controller, :action_view] + end + + def test_database_middleware_doesnt_perform_anything_when_active_record_in_frameworks + @config.frameworks.clear + @config.expects(:middleware).never + Rails::Initializer.run(:initialize_database_middleware, @config) + end + + def test_database_middleware_initializes_when_session_store_is_active_record + store = ActionController::Base.session_store + ActionController::Base.session_store = ActiveRecord::SessionStore + + @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement) + @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::QueryCache) + + Rails::Initializer.run(:initialize_database_middleware, @config) + ensure + ActionController::Base.session_store = store + end + + def test_database_middleware_doesnt_initialize_when_session_store_is_not_active_record + store = ActionController::Base.session_store + ActionController::Base.session_store = ActionController::Session::CookieStore + + # Define the class, so we don't have to actually make it load + eval("class ActiveRecord::ConnectionAdapters::ConnectionManagement; end") + + @config.middleware.expects(:use).with(ActiveRecord::ConnectionAdapters::ConnectionManagement) + @config.middleware.expects(:use).with(ActiveRecord::QueryCache) + + Rails::Initializer.run(:initialize_database_middleware, @config) + ensure + ActionController::Base.session_store = store + end +end + class RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_equals_rails_root assert_equal RAILS_ROOT, Rails.root.to_s @@ -333,4 +372,4 @@ class RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_should_be_a_pathname assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s end -end +end \ No newline at end of file -- cgit v1.2.3 From 6099f261ea7c624aa45b47be7573ed1cab7b6b71 Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Wed, 25 Feb 2009 12:10:22 +0100 Subject: Test view path loading from the initializer. Signed-off-by: Joshua Peek --- railties/test/initializer_test.rb | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 2c448f6dbd..e91e05d939 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -2,6 +2,7 @@ require 'abstract_unit' require 'initializer' require 'action_view' +require 'action_mailer' require 'active_record' # Mocks out the configuration @@ -330,7 +331,7 @@ class InitializerDatabaseMiddlewareTest < Test::Unit::TestCase @config.frameworks = [:active_record, :action_controller, :action_view] end - def test_database_middleware_doesnt_perform_anything_when_active_record_in_frameworks + def test_initialize_database_middleware_doesnt_perform_anything_when_active_record_not_in_frameworks @config.frameworks.clear @config.expects(:middleware).never Rails::Initializer.run(:initialize_database_middleware, @config) @@ -360,7 +361,30 @@ class InitializerDatabaseMiddlewareTest < Test::Unit::TestCase Rails::Initializer.run(:initialize_database_middleware, @config) ensure - ActionController::Base.session_store = store + ActionController::Base.session_store = store + end +end + +class InitializerViewPathsTest < Test::Unit::TestCase + def setup + @config = Rails::Configuration.new + @config.frameworks = [:action_view, :action_controller, :action_mailer] + + ActionController::Base.stubs(:view_paths).returns(stub) + ActionMailer::Base.stubs(:view_paths).returns(stub) + end + + def test_load_view_paths_doesnt_perform_anything_when_action_view_not_in_frameworks + @config.frameworks -= [:action_view] + ActionController::Base.view_paths.expects(:load!).never + ActionMailer::Base.view_paths.expects(:load!).never + Rails::Initializer.run(:load_view_paths, @config) + end + + def test_load_view_paths_loads_view_paths + ActionController::Base.view_paths.expects(:load!) + ActionMailer::Base.view_paths.expects(:load!) + Rails::Initializer.run(:load_view_paths, @config) end end -- cgit v1.2.3 From dec91a2e0655d288bd5184c981e2f4c60d9b3cf1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 25 Feb 2009 14:01:44 -0800 Subject: Fix test failure introduced by 6099f261ea7c624aa45b47be7573ed1cab7b6b71 --- railties/test/abstract_unit.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 0775b3ff55..0addcb8bf3 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,6 +1,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__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" @@ -26,4 +27,4 @@ def uses_gem(gem_name, test_name, version = '> 0') yield rescue LoadError $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again." -end \ No newline at end of file +end -- cgit v1.2.3 From 319106d09c0ec2daf8b5345f525f1c97b6368ce2 Mon Sep 17 00:00:00 2001 From: Matthew Rudy Jacobs Date: Sun, 22 Feb 2009 19:23:04 +0000 Subject: Metal can now line in plugins under app/metal [#2045 state:committed] Signed-off-by: David Heinemeier Hansson --- .../fixtures/plugins/engines/engine/app/metal/engine_metal.rb | 10 ++++++++++ railties/test/plugin_loader_test.rb | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb b/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb new file mode 100644 index 0000000000..d67a127ca7 --- /dev/null +++ b/railties/test/fixtures/plugins/engines/engine/app/metal/engine_metal.rb @@ -0,0 +1,10 @@ +class EngineMetal + def self.call(env) + if env["PATH_INFO"] =~ /^\/metal/ + [200, {"Content-Type" => "text/html"}, ["Engine metal"]] + else + [404, {"Content-Type" => "text/html"}, ["Not Found"]] + end + end +end + diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index e802b1ace7..b270748dd6 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -120,7 +120,7 @@ class TestPluginLoader < Test::Unit::TestCase @loader.add_plugin_load_paths - %w( models controllers helpers ).each do |app_part| + %w( models controllers metal helpers ).each do |app_part| assert ActiveSupport::Dependencies.load_paths.include?( File.join(plugin_fixture_path('engines/engine'), 'app', app_part) ), "Couldn't find #{app_part} in load path" @@ -161,4 +161,4 @@ class TestPluginLoader < Test::Unit::TestCase $LOAD_PATH.clear ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } end -end \ No newline at end of file +end -- cgit v1.2.3 From 1ceddd951449b8647dff7d2b4301477bc8b6b510 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 27 Feb 2009 12:18:45 -0800 Subject: Skip backtrace filter test when using minitest --- railties/test/backtrace_cleaner_test.rb | 44 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'railties/test') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index 5955fd2856..bfb9cb7639 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -3,26 +3,30 @@ require 'abstract_unit' require 'initializer' require 'rails/backtrace_cleaner' -class TestWithBacktrace - include Test::Unit::Util::BacktraceFilter - include Rails::BacktraceFilterForTestUnit -end - -class BacktraceCleanerFilterTest < ActiveSupport::TestCase - def setup - @test = TestWithBacktrace.new - @backtrace = [ './test/rails/benchmark_test.rb', './test/rails/dependencies.rb', '/opt/local/lib/ruby/kernel.rb' ] +if defined? Test::Unit::Util::BacktraceFilter + class TestWithBacktrace + include Test::Unit::Util::BacktraceFilter + include Rails::BacktraceFilterForTestUnit end - - test "test with backtrace should use the rails backtrace cleaner to clean" do - Rails.stubs(:backtrace_cleaner).returns(stub(:clean)) - Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil) - @test.filter_backtrace(@backtrace) - end - - test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do - assert_nothing_raised do - @test.filter_backtrace(@backtrace, '/opt/local/lib') + + class BacktraceCleanerFilterTest < ActiveSupport::TestCase + def setup + @test = TestWithBacktrace.new + @backtrace = [ './test/rails/benchmark_test.rb', './test/rails/dependencies.rb', '/opt/local/lib/ruby/kernel.rb' ] + end + + test "test with backtrace should use the rails backtrace cleaner to clean" do + Rails.stubs(:backtrace_cleaner).returns(stub(:clean)) + Rails.backtrace_cleaner.expects(:clean).with(@backtrace, nil) + @test.filter_backtrace(@backtrace) + end + + test "filter backtrace should have the same arity as Test::Unit::Util::BacktraceFilter" do + assert_nothing_raised do + @test.filter_backtrace(@backtrace, '/opt/local/lib') + end end end -end \ No newline at end of file +else + $stderr.puts 'No BacktraceFilter for minitest' +end -- cgit v1.2.3 From 884068a13ac097450e183f4eca50509f2037c122 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 27 Feb 2009 12:19:23 -0800 Subject: Skip console test when using minitest --- railties/test/console_app_test.rb | 42 ++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'railties/test') diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb index 7a5de5af8f..f11de087e3 100644 --- a/railties/test/console_app_test.rb +++ b/railties/test/console_app_test.rb @@ -11,30 +11,32 @@ require 'dispatcher' require 'console_app' # console_app sets Test::Unit.run to work around the at_exit hook in test/unit, which kills IRB -Test::Unit.run = false - -class ConsoleAppTest < Test::Unit::TestCase - def test_app_method_should_return_integration_session - assert_nothing_thrown do - console_session = app - assert_not_nil console_session - assert_instance_of ActionController::Integration::Session, - console_session +if Test::Unit.respond_to?(:run=) + Test::Unit.run = false + + class ConsoleAppTest < Test::Unit::TestCase + def test_app_method_should_return_integration_session + assert_nothing_thrown do + console_session = app + assert_not_nil console_session + assert_instance_of ActionController::Integration::Session, + console_session + end end - end - def test_reload_should_fire_preparation_callbacks - a = b = c = nil + def test_reload_should_fire_preparation_callbacks + a = b = c = nil - Dispatcher.to_prepare { a = b = c = 1 } - Dispatcher.to_prepare { b = c = 2 } - Dispatcher.to_prepare { c = 3 } - ActionController::Routing::Routes.expects(:reload) + Dispatcher.to_prepare { a = b = c = 1 } + Dispatcher.to_prepare { b = c = 2 } + Dispatcher.to_prepare { c = 3 } + ActionController::Routing::Routes.expects(:reload) - reload! + reload! - assert_equal 1, a - assert_equal 2, b - assert_equal 3, c + assert_equal 1, a + assert_equal 2, b + assert_equal 3, c + end end end -- cgit v1.2.3 From 16b3d2b621b1682f249209097c31b0a10f0f87ef Mon Sep 17 00:00:00 2001 From: Andrew Vit Date: Sun, 15 Feb 2009 19:33:12 -0800 Subject: Added :env option for gem in template runner [#1983 state:resolved] For installing gems that are only needed in the test environment, specify the :env option so the dependency is written to config/environments/test.rb: gem 'rspec', :env => 'test' gem 'quietbacktrace', :env => %w[development test] Signed-off-by: Pratik Naik --- railties/test/generators/rails_template_runner_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb index 56afc85eba..4e1937e0c6 100644 --- a/railties/test/generators/rails_template_runner_test.rb +++ b/railties/test/generators/rails_template_runner_test.rb @@ -82,6 +82,17 @@ class RailsTemplateRunnerTest < GeneratorTestCase assert_rails_initializer_includes("config.gem 'mislav-will-paginate', :lib => 'will-paginate', :source => 'http://gems.github.com'") end + def test_gem_with_env_string_should_put_gem_dependency_in_specified_environment + run_template_method(:gem, 'rspec', :env => 'test') + assert_generated_file_with_data('config/environments/test.rb', "config.gem 'rspec'", 'test') + end + + def test_gem_with_env_array_should_put_gem_dependency_in_specified_environments + run_template_method(:gem, 'quietbacktrace', :env => %w[ development test ]) + assert_generated_file_with_data('config/environments/development.rb', "config.gem 'quietbacktrace'") + assert_generated_file_with_data('config/environments/test.rb', "config.gem 'quietbacktrace'") + end + def test_environment_should_include_data_in_environment_initializer_block load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]' run_template_method(:environment, load_paths) -- cgit v1.2.3 From a3ac1e1621506a6519b265ef6ec6abc70f6c8a27 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Sun, 1 Mar 2009 11:53:58 +0000 Subject: Display gem dependencies correctly and unpack exactly once [#2097 state:resolved] Signed-off-by: Pratik Naik --- railties/test/gem_dependency_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 9cb02fcd06..8b761c48b2 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -133,7 +133,7 @@ class GemDependencyTest < Test::Unit::TestCase dummy_gem.add_load_paths dummy_gem.load assert dummy_gem.loaded? - assert_equal 2, dummy_gem.dependencies.size + assert_equal 2, dummy_gem.dependencies(:flatten => true).size assert_nothing_raised do dummy_gem.dependencies.each do |g| g.dependencies -- cgit v1.2.3 From 4d4d2c3896ed5a5d74da833c5c3132f406f4eab7 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Tue, 3 Mar 2009 12:39:19 -0600 Subject: Enhanced Rails Metal - the load order of metals can now be configured [#2057 state:resolved] Signed-off-by: Joshua Peek --- .../metal/multiplemetals/app/metal/metal_a.rb | 5 ++ .../metal/multiplemetals/app/metal/metal_b.rb | 5 ++ .../metal/singlemetal/app/metal/foo_metal.rb | 5 ++ .../metal/subfolders/app/metal/Folder/metal_a.rb | 7 +++ .../metal/subfolders/app/metal/Folder/metal_b.rb | 7 +++ railties/test/metal_test.rb | 57 ++++++++++++++++++++++ 6 files changed, 86 insertions(+) create mode 100644 railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb create mode 100644 railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb create mode 100644 railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb create mode 100644 railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb create mode 100644 railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb create mode 100644 railties/test/metal_test.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb new file mode 100644 index 0000000000..b8e7001351 --- /dev/null +++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb @@ -0,0 +1,5 @@ +class MetalA < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end +end diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb new file mode 100644 index 0000000000..adc2f45fcf --- /dev/null +++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb @@ -0,0 +1,5 @@ +class MetalB < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end +end diff --git a/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb new file mode 100644 index 0000000000..9ade2ce8e7 --- /dev/null +++ b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb @@ -0,0 +1,5 @@ +class FooMetal < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end +end diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb new file mode 100644 index 0000000000..71a5a62eb8 --- /dev/null +++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb @@ -0,0 +1,7 @@ +module Folder + class MetalA < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end + end +end diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb new file mode 100644 index 0000000000..430d7bfed6 --- /dev/null +++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb @@ -0,0 +1,7 @@ +module Folder + class MetalB < Rails::Rack::Metal + def self.call(env) + [200, { "Content-Type" => "text/html"}, "Hi"] + end + end +end diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb new file mode 100644 index 0000000000..cff231ed00 --- /dev/null +++ b/railties/test/metal_test.rb @@ -0,0 +1,57 @@ +require 'abstract_unit' +require 'initializer' + +class MetalTest < Test::Unit::TestCase + def test_metals_should_return_list_of_found_metal_apps + use_appdir("singlemetal") do + assert_equal(["FooMetal"], found_metals_as_string_array) + end + end + + def test_metals_should_return_alphabetical_list_of_found_metal_apps + use_appdir("multiplemetals") do + assert_equal(["MetalA", "MetalB"], found_metals_as_string_array) + end + end + + def test_metals_load_order_should_be_overriden_by_requested_metals + use_appdir("multiplemetals") do + Rails::Rack::Metal.requested_metals = ["MetalB", "MetalA"] + assert_equal(["MetalB", "MetalA"], found_metals_as_string_array) + end + end + + def test_metals_not_listed_should_not_load + use_appdir("multiplemetals") do + Rails::Rack::Metal.requested_metals = ["MetalB"] + assert_equal(["MetalB"], found_metals_as_string_array) + end + end +p + def test_metal_finding_should_work_with_subfolders + use_appdir("subfolders") do + assert_equal(["Folder::MetalA", "Folder::MetalB"], found_metals_as_string_array) + end + end + + def test_metal_finding_with_requested_metals_should_work_with_subfolders + use_appdir("subfolders") do + Rails::Rack::Metal.requested_metals = ["Folder::MetalB"] + assert_equal(["Folder::MetalB"], found_metals_as_string_array) + end + end + + private + + def use_appdir(root) + dir = "#{File.dirname(__FILE__)}/fixtures/metal/#{root}" + Rails::Rack::Metal.metal_paths = ["#{dir}/app/metal"] + Rails::Rack::Metal.requested_metals = nil + $LOAD_PATH << "#{dir}/app/metal" + yield + end + + def found_metals_as_string_array + Rails::Rack::Metal.metals.map { |m| m.to_s } + end +end -- cgit v1.2.3 From 6087fe8eedf0249f74be10721714f5298286b198 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Wed, 4 Mar 2009 12:26:53 -0600 Subject: stray character in railties test --- railties/test/metal_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb index cff231ed00..a31f4ab273 100644 --- a/railties/test/metal_test.rb +++ b/railties/test/metal_test.rb @@ -27,7 +27,7 @@ class MetalTest < Test::Unit::TestCase assert_equal(["MetalB"], found_metals_as_string_array) end end -p + def test_metal_finding_should_work_with_subfolders use_appdir("subfolders") do assert_equal(["Folder::MetalA", "Folder::MetalB"], found_metals_as_string_array) -- cgit v1.2.3 From e97180c273ada9b252ddf42d340d2947a509cb26 Mon Sep 17 00:00:00 2001 From: Simon Jefford Date: Thu, 5 Mar 2009 18:50:52 -0600 Subject: Ensure that loading metals from the main app and engines works on older Ruby versions [#2143 state:resolved] Signed-off-by: Joshua Peek --- railties/test/metal_test.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'railties/test') diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb index a31f4ab273..143efdda11 100644 --- a/railties/test/metal_test.rb +++ b/railties/test/metal_test.rb @@ -41,6 +41,15 @@ class MetalTest < Test::Unit::TestCase end end + def test_metal_finding_should_work_with_multiple_metal_paths_in_185_and_below + use_appdir("singlemetal") do + engine_metal_path = "#{File.dirname(__FILE__)}/fixtures/plugins/engines/engine/app/metal" + Rails::Rack::Metal.metal_paths << engine_metal_path + $LOAD_PATH << engine_metal_path + assert_equal(["FooMetal", "EngineMetal"], found_metals_as_string_array) + end + end + private def use_appdir(root) -- cgit v1.2.3 From 4185fb1e58d8142162c3a39f9302559688dd431b Mon Sep 17 00:00:00 2001 From: karmi Date: Sat, 7 Mar 2009 16:02:52 +0000 Subject: Raise LoadError instead of a runtime exception [#1498 state:resolved] Signed-off-by: Pratik Naik --- railties/test/fixtures/plugins/engines/engine/init.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/fixtures/plugins/engines/engine/init.rb b/railties/test/fixtures/plugins/engines/engine/init.rb index f4b00c0fa4..64e9ae6c30 100644 --- a/railties/test/fixtures/plugins/engines/engine/init.rb +++ b/railties/test/fixtures/plugins/engines/engine/init.rb @@ -1,3 +1,3 @@ # My app/models dir must be in the load path. require 'engine_model' -raise 'missing model from my app/models dir' unless defined?(EngineModel) +raise LoadError, 'missing model from my app/models dir' unless defined?(EngineModel) -- cgit v1.2.3 From 1c36172c13fc51b22167f5e8fc41b1da9f8fcb2a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 8 Mar 2009 13:11:58 -0700 Subject: Ruby 1.9 compat: rename deprecated assert_raises to assert_raise. [#1617 state:resolved] --- railties/test/initializer_test.rb | 2 +- railties/test/plugin_locator_test.rb | 2 +- railties/test/plugin_test.rb | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index e91e05d939..561f7b8b54 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -237,7 +237,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin] - assert_raises(LoadError) do + assert_raise(LoadError) do load_plugins! end end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index c8404e126e..471d9fc7c3 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -2,7 +2,7 @@ require 'plugin_test_helper' class PluginLocatorTest < Test::Unit::TestCase def test_should_require_subclasses_to_implement_the_plugins_method - assert_raises(RuntimeError) do + assert_raise(RuntimeError) do Rails::Plugin::Locator.new(nil).plugins end end diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb index 5500711df8..a6c390a45a 100644 --- a/railties/test/plugin_test.rb +++ b/railties/test/plugin_test.rb @@ -52,11 +52,11 @@ class PluginTest < Test::Unit::TestCase plugin_for(@valid_plugin_path).load_paths end - assert_raises(LoadError) do + assert_raise(LoadError) do plugin_for(@empty_plugin_path).load_paths end - assert_raises(LoadError) do + assert_raise(LoadError) do plugin_for('this_is_not_a_plugin_directory').load_paths end end @@ -77,13 +77,13 @@ class PluginTest < Test::Unit::TestCase end # This is an empty path so it raises - assert_raises(LoadError) do + assert_raise(LoadError) do plugin = plugin_for(@empty_plugin_path) plugin.stubs(:evaluate_init_rb) plugin.send(:load, @initializer) end - assert_raises(LoadError) do + assert_raise(LoadError) do plugin = plugin_for('this_is_not_a_plugin_directory') plugin.stubs(:evaluate_init_rb) plugin.send(:load, @initializer) @@ -97,11 +97,11 @@ class PluginTest < Test::Unit::TestCase end # This is an empty path so it raises - assert_raises(LoadError) do + assert_raise(LoadError) do plugin_for(@empty_plugin_path).load_paths end - assert_raises(LoadError) do + assert_raise(LoadError) do plugin_for('this_is_not_a_plugin_directory').load_paths end end -- cgit v1.2.3 From 0da8e45baf592bf715023c0553b9aefd15b86579 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Thu, 5 Mar 2009 15:48:56 -0500 Subject: Correctly clean backtraces from vendor/gems and gems in alternate install locations Signed-off-by: David Heinemeier Hansson --- railties/test/backtrace_cleaner_test.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'railties/test') diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb index bfb9cb7639..7a1b361440 100644 --- a/railties/test/backtrace_cleaner_test.rb +++ b/railties/test/backtrace_cleaner_test.rb @@ -30,3 +30,32 @@ if defined? Test::Unit::Util::BacktraceFilter else $stderr.puts 'No BacktraceFilter for minitest' end + +class BacktraceCleanerVendorGemTest < ActiveSupport::TestCase + def setup + @cleaner = Rails::BacktraceCleaner.new + end + + test "should format installed gems correctly" do + @backtrace = [ "#{Gem.default_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] + @result = @cleaner.clean(@backtrace) + assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] + end + + test "should format installed gems not in Gem.default_dir correctly" do + @target_dir = Gem.path.detect { |p| p != Gem.default_dir } + # skip this test if default_dir is the only directory on Gem.path + if @target_dir + @backtrace = [ "#{@target_dir}/gems/nosuchgem-1.2.3/lib/foo.rb" ] + @result = @cleaner.clean(@backtrace) + assert_equal "nosuchgem (1.2.3) lib/foo.rb", @result[0] + end + end + + test "should format vendor gems correctly" do + @backtrace = [ "#{Rails::GemDependency.unpacked_path}/nosuchgem-1.2.3/lib/foo.rb" ] + @result = @cleaner.clean(@backtrace) + assert_equal "nosuchgem (1.2.3) [v] lib/foo.rb", @result[0] + end + +end -- cgit v1.2.3 From 0c9bbf8c9dca46fbd7916640c417d13bf8b5af30 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 9 Mar 2009 23:31:04 -0500 Subject: Fix serving index files with rack static file server [#2180 state:resolved] --- railties/test/public/foo/bar.html | 1 + railties/test/public/foo/index.html | 1 + railties/test/public/index.html | 1 + railties/test/rack_static_test.rb | 38 +++++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 railties/test/public/foo/bar.html create mode 100644 railties/test/public/foo/index.html create mode 100644 railties/test/public/index.html create mode 100644 railties/test/rack_static_test.rb (limited to 'railties/test') diff --git a/railties/test/public/foo/bar.html b/railties/test/public/foo/bar.html new file mode 100644 index 0000000000..9a35646205 --- /dev/null +++ b/railties/test/public/foo/bar.html @@ -0,0 +1 @@ +/foo/bar.html \ No newline at end of file diff --git a/railties/test/public/foo/index.html b/railties/test/public/foo/index.html new file mode 100644 index 0000000000..497a2e898f --- /dev/null +++ b/railties/test/public/foo/index.html @@ -0,0 +1 @@ +/foo/index.html \ No newline at end of file diff --git a/railties/test/public/index.html b/railties/test/public/index.html new file mode 100644 index 0000000000..525950ba6b --- /dev/null +++ b/railties/test/public/index.html @@ -0,0 +1 @@ +/index.html \ No newline at end of file diff --git a/railties/test/rack_static_test.rb b/railties/test/rack_static_test.rb new file mode 100644 index 0000000000..5449751002 --- /dev/null +++ b/railties/test/rack_static_test.rb @@ -0,0 +1,38 @@ +require 'abstract_unit' + +require 'action_controller' +require 'rails/rack' + +class RackStaticTest < ActiveSupport::TestCase + DummyApp = lambda { |env| + [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] + } + App = Rails::Rack::Static.new(DummyApp) + + test "serves dynamic content" do + assert_equal "Hello, World!", get("/nofile") + end + + test "serves static index at root" do + assert_equal "/index.html", get("/index.html") + assert_equal "/index.html", get("/index") + assert_equal "/index.html", get("/") + end + + test "serves static file in directory" do + assert_equal "/foo/bar.html", get("/foo/bar.html") + assert_equal "/foo/bar.html", get("/foo/bar/") + assert_equal "/foo/bar.html", get("/foo/bar") + end + + test "serves static index file in directory" do + assert_equal "/foo/index.html", get("/foo/index.html") + assert_equal "/foo/index.html", get("/foo/") + assert_equal "/foo/index.html", get("/foo") + end + + private + def get(path) + Rack::MockRequest.new(App).request("GET", path).body + end +end -- cgit v1.2.3 From e8b07dc340441d4d15889cb14ee9f0f00a1ecd30 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Tue, 10 Mar 2009 11:19:32 -0500 Subject: Ensure public folder structure is setup correctly if the tests are ran out of order, fixes tests in 0c9bbf8 --- railties/test/fixtures/public/foo/bar.html | 1 + railties/test/fixtures/public/foo/index.html | 1 + railties/test/fixtures/public/index.html | 1 + railties/test/public/foo/bar.html | 1 - railties/test/public/foo/index.html | 1 - railties/test/public/index.html | 1 - railties/test/rack_static_test.rb | 8 ++++++++ 7 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 railties/test/fixtures/public/foo/bar.html create mode 100644 railties/test/fixtures/public/foo/index.html create mode 100644 railties/test/fixtures/public/index.html delete mode 100644 railties/test/public/foo/bar.html delete mode 100644 railties/test/public/foo/index.html delete mode 100644 railties/test/public/index.html (limited to 'railties/test') diff --git a/railties/test/fixtures/public/foo/bar.html b/railties/test/fixtures/public/foo/bar.html new file mode 100644 index 0000000000..9a35646205 --- /dev/null +++ b/railties/test/fixtures/public/foo/bar.html @@ -0,0 +1 @@ +/foo/bar.html \ No newline at end of file diff --git a/railties/test/fixtures/public/foo/index.html b/railties/test/fixtures/public/foo/index.html new file mode 100644 index 0000000000..497a2e898f --- /dev/null +++ b/railties/test/fixtures/public/foo/index.html @@ -0,0 +1 @@ +/foo/index.html \ No newline at end of file diff --git a/railties/test/fixtures/public/index.html b/railties/test/fixtures/public/index.html new file mode 100644 index 0000000000..525950ba6b --- /dev/null +++ b/railties/test/fixtures/public/index.html @@ -0,0 +1 @@ +/index.html \ No newline at end of file diff --git a/railties/test/public/foo/bar.html b/railties/test/public/foo/bar.html deleted file mode 100644 index 9a35646205..0000000000 --- a/railties/test/public/foo/bar.html +++ /dev/null @@ -1 +0,0 @@ -/foo/bar.html \ No newline at end of file diff --git a/railties/test/public/foo/index.html b/railties/test/public/foo/index.html deleted file mode 100644 index 497a2e898f..0000000000 --- a/railties/test/public/foo/index.html +++ /dev/null @@ -1 +0,0 @@ -/foo/index.html \ No newline at end of file diff --git a/railties/test/public/index.html b/railties/test/public/index.html deleted file mode 100644 index 525950ba6b..0000000000 --- a/railties/test/public/index.html +++ /dev/null @@ -1 +0,0 @@ -/index.html \ No newline at end of file diff --git a/railties/test/rack_static_test.rb b/railties/test/rack_static_test.rb index 5449751002..ad673f6f19 100644 --- a/railties/test/rack_static_test.rb +++ b/railties/test/rack_static_test.rb @@ -4,6 +4,14 @@ require 'action_controller' require 'rails/rack' class RackStaticTest < ActiveSupport::TestCase + def setup + FileUtils.cp_r "#{RAILS_ROOT}/fixtures/public", "#{RAILS_ROOT}/public" + end + + def teardown + FileUtils.rm_rf "#{RAILS_ROOT}/public" + end + DummyApp = lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello, World!"]] } -- cgit v1.2.3 From 8a17fd1a65ab8e2fa6b36d79603fde0e6ffd083f Mon Sep 17 00:00:00 2001 From: Damian Terentiev Date: Thu, 12 Mar 2009 14:45:55 +0000 Subject: Fixed that template runner gem method to output :lib => false correctly [#1940 state:resolved] Signed-off-by: Pratik Naik --- railties/test/generators/rails_template_runner_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'railties/test') diff --git a/railties/test/generators/rails_template_runner_test.rb b/railties/test/generators/rails_template_runner_test.rb index 4e1937e0c6..2da6bd59b5 100644 --- a/railties/test/generators/rails_template_runner_test.rb +++ b/railties/test/generators/rails_template_runner_test.rb @@ -93,6 +93,11 @@ class RailsTemplateRunnerTest < GeneratorTestCase assert_generated_file_with_data('config/environments/test.rb', "config.gem 'quietbacktrace'") end + def test_gem_with_lib_option_set_to_false_should_put_gem_dependency_in_enviroment_correctly + run_template_method(:gem, 'mislav-will-paginate', :lib => false, :source => 'http://gems.github.com') + assert_rails_initializer_includes("config.gem 'mislav-will-paginate', :lib => false, :source => 'http://gems.github.com'") + end + def test_environment_should_include_data_in_environment_initializer_block load_paths = 'config.load_paths += %w["#{RAILS_ROOT}/app/extras"]' run_template_method(:environment, load_paths) -- cgit v1.2.3 From 9d906707bea997016fd370e33e12dbc21cfcc531 Mon Sep 17 00:00:00 2001 From: John Dzak Date: Thu, 12 Mar 2009 15:04:07 -0500 Subject: Vendored gem paths now being loaded if they exist [#2204 state:resolved] Signed-off-by: Pratik Naik --- railties/test/boot_test.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'railties/test') diff --git a/railties/test/boot_test.rb b/railties/test/boot_test.rb index 16776af098..08fcc82e6f 100644 --- a/railties/test/boot_test.rb +++ b/railties/test/boot_test.rb @@ -62,6 +62,8 @@ class VendorBootTest < Test::Unit::TestCase def test_load_initializer_requires_from_vendor_rails boot = VendorBoot.new boot.expects(:require).with("#{RAILS_ROOT}/vendor/rails/railties/lib/initializer") + Rails::Initializer.expects(:run).with(:install_gem_spec_stubs) + Rails::GemDependency.expects(:add_frozen_gem_path) boot.load_initializer end end -- cgit v1.2.3 From 99d75a7b02bf430a124b9c3e2515850959d78acf Mon Sep 17 00:00:00 2001 From: David Dollar Date: Fri, 13 Mar 2009 10:20:23 +0000 Subject: Makes the gem system understand development vs. runtime dependencies [#2195 state:resolved] The patch also fixes: * Fixes the chicken/egg problem present in the current gem system when gems are defined in the config that are not yet installed. * Remove the need to have hoe as a dependency of your production app. * Makes the gem 'unpacking' system a lot less fragile. Signed-off-by: Matt Jones Signed-off-by: Pratik Naik --- railties/test/gem_dependency_test.rb | 17 ++++++++++------- .../test/vendor/gems/dummy-gem-g-1.0.0/.specification | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 8b761c48b2..189ad02b76 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -46,31 +46,34 @@ class GemDependencyTest < Test::Unit::TestCase end def test_gem_adds_load_paths - @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) + @gem.expects(:gem).with(@gem) @gem.add_load_paths end def test_gem_with_version_adds_load_paths - @gem_with_version.expects(:gem).with(Gem::Dependency.new(@gem_with_version.name, @gem_with_version.requirement.to_s)) + @gem_with_version.expects(:gem).with(@gem_with_version) @gem_with_version.add_load_paths + assert @gem_with_version.load_paths_added? end def test_gem_loading - @gem.expects(:gem).with(Gem::Dependency.new(@gem.name, nil)) + @gem.expects(:gem).with(@gem) @gem.expects(:require).with(@gem.name) @gem.add_load_paths @gem.load + assert @gem.loaded? end def test_gem_with_lib_loading - @gem_with_lib.expects(:gem).with(Gem::Dependency.new(@gem_with_lib.name, nil)) + @gem_with_lib.expects(:gem).with(@gem_with_lib) @gem_with_lib.expects(:require).with(@gem_with_lib.lib) @gem_with_lib.add_load_paths @gem_with_lib.load + assert @gem_with_lib.loaded? end def test_gem_without_lib_loading - @gem_without_load.expects(:gem).with(Gem::Dependency.new(@gem_without_load.name, nil)) + @gem_without_load.expects(:gem).with(@gem_without_load) @gem_without_load.expects(:require).with(@gem_without_load.lib).never @gem_without_load.add_load_paths @gem_without_load.load @@ -132,8 +135,8 @@ class GemDependencyTest < Test::Unit::TestCase dummy_gem = Rails::GemDependency.new "dummy-gem-g" dummy_gem.add_load_paths dummy_gem.load - assert dummy_gem.loaded? - assert_equal 2, dummy_gem.dependencies(:flatten => true).size + assert_equal 1, dummy_gem.dependencies.size + assert_equal 1, dummy_gem.dependencies.first.dependencies.size assert_nothing_raised do dummy_gem.dependencies.each do |g| g.dependencies diff --git a/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification index 5483048c1c..27e29912a6 100644 --- a/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification +++ b/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification @@ -9,7 +9,7 @@ date: 2008-10-03 00:00:00 -04:00 dependencies: - !ruby/object:Gem::Dependency name: dummy-gem-f - type: :development + type: :runtime version_requirement: version_requirements: !ruby/object:Gem::Requirement requirements: -- cgit v1.2.3 From 5f10533949457e3797c8f0b51eb30a9268bceb4d Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Sun, 15 Mar 2009 18:41:21 -0500 Subject: Make sure Metal use ActionController class name conventions [#2242 state:resolved] Signed-off-by: Joshua Peek --- railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb | 5 +++++ railties/test/metal_test.rb | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb b/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb new file mode 100644 index 0000000000..6f9e382500 --- /dev/null +++ b/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb @@ -0,0 +1,5 @@ +class LegacyRoutes < Rails::Rack::Metal + def self.call(env) + [301, { "Location" => "http://example.com"}, nil] + end +end diff --git a/railties/test/metal_test.rb b/railties/test/metal_test.rb index 143efdda11..d3d231132b 100644 --- a/railties/test/metal_test.rb +++ b/railties/test/metal_test.rb @@ -8,6 +8,12 @@ class MetalTest < Test::Unit::TestCase end end + def test_metals_should_respect_class_name_conventions + use_appdir("pluralmetal") do + assert_equal(["LegacyRoutes"], found_metals_as_string_array) + end + end + def test_metals_should_return_alphabetical_list_of_found_metal_apps use_appdir("multiplemetals") do assert_equal(["MetalA", "MetalB"], found_metals_as_string_array) -- cgit v1.2.3 From 5a575bb99293837533dc357da891dac29a702616 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Sun, 15 Mar 2009 23:21:29 -0500 Subject: update metal fixtures to be ruby 1.9 compat --- railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb | 2 +- railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb | 2 +- railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb | 2 +- railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb | 2 +- railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb | 2 +- railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb index b8e7001351..2d373ce422 100644 --- a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb +++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_a.rb @@ -1,5 +1,5 @@ class MetalA < Rails::Rack::Metal def self.call(env) - [200, { "Content-Type" => "text/html"}, "Hi"] + [200, { "Content-Type" => "text/html"}, ["Hi"]] end end diff --git a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb index adc2f45fcf..a8bbf3fd60 100644 --- a/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb +++ b/railties/test/fixtures/metal/multiplemetals/app/metal/metal_b.rb @@ -1,5 +1,5 @@ class MetalB < Rails::Rack::Metal def self.call(env) - [200, { "Content-Type" => "text/html"}, "Hi"] + [200, { "Content-Type" => "text/html"}, ["Hi"]] end end diff --git a/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb b/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb index 6f9e382500..0cd3737c32 100644 --- a/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb +++ b/railties/test/fixtures/metal/pluralmetal/app/metal/legacy_routes.rb @@ -1,5 +1,5 @@ class LegacyRoutes < Rails::Rack::Metal def self.call(env) - [301, { "Location" => "http://example.com"}, nil] + [301, { "Location" => "http://example.com"}, []] end end diff --git a/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb index 9ade2ce8e7..5f5b087592 100644 --- a/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb +++ b/railties/test/fixtures/metal/singlemetal/app/metal/foo_metal.rb @@ -1,5 +1,5 @@ class FooMetal < Rails::Rack::Metal def self.call(env) - [200, { "Content-Type" => "text/html"}, "Hi"] + [200, { "Content-Type" => "text/html"}, ["Hi"]] end end diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb index 71a5a62eb8..25b3bb0abc 100644 --- a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb +++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_a.rb @@ -1,7 +1,7 @@ module Folder class MetalA < Rails::Rack::Metal def self.call(env) - [200, { "Content-Type" => "text/html"}, "Hi"] + [200, { "Content-Type" => "text/html"}, ["Hi"]] end end end diff --git a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb index 430d7bfed6..7583363f71 100644 --- a/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb +++ b/railties/test/fixtures/metal/subfolders/app/metal/Folder/metal_b.rb @@ -1,7 +1,7 @@ module Folder class MetalB < Rails::Rack::Metal def self.call(env) - [200, { "Content-Type" => "text/html"}, "Hi"] + [200, { "Content-Type" => "text/html"}, ["Hi"]] end end end -- cgit v1.2.3 From f209d3898fbd866e1405861319b85c97674a0508 Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Tue, 7 Apr 2009 09:16:48 -0500 Subject: Improve tests and code for Rails::InfoController and Rails::Info [#2411 state:resolved] - Refactor Rails::InfoController tests. - Return forbidden status from the InfoController for remote requests instead of a 500. - Add tests for displaying middleware in Rails::Info. Signed-off-by: Joshua Peek --- railties/test/rails_info_controller_test.rb | 54 +++++++++++++---------------- railties/test/rails_info_test.rb | 17 ++++++++- 2 files changed, 40 insertions(+), 31 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index e274e1aa6e..607ece99a9 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -2,51 +2,45 @@ require 'abstract_unit' require 'action_controller' require 'action_controller/test_process' -module Rails; end require 'rails/info' require 'rails/info_controller' -class Rails::InfoController < ActionController::Base - @local_request = false - class << self - cattr_accessor :local_request - end - - # Re-raise errors caught by the controller. - def rescue_action(e) raise e end; - -protected - def local_request? - self.class.local_request - end -end - ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' end -class Rails::InfoControllerTest < ActionController::TestCase +class InfoControllerTest < ActionController::TestCase + tests Rails::InfoController + def setup - @controller = Rails::InfoController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new + @controller.stubs(:consider_all_requests_local => false, :local_request? => true) + end + + test "info controller does not allow remote requests" do + @controller.stubs(:consider_all_requests_local => false, :local_request? => false) + get :properties + assert_response :forbidden + end - ActionController::Base.consider_all_requests_local = true + test "info controller renders an error message when request was forbidden" do + @controller.stubs(:consider_all_requests_local => false, :local_request? => false) + get :properties + assert_select 'p' + end + + test "info controller allows requests when all requests are considered local" do + @controller.stubs(:consider_all_requests_local => true, :local_request? => false) + get :properties + assert_response :success end - def test_rails_info_properties_table_rendered_for_local_request - Rails::InfoController.local_request = true + test "info controller allows local requests" do get :properties - assert_tag :tag => 'table' assert_response :success end - - def test_rails_info_properties_error_rendered_for_non_local_request - Rails::InfoController.local_request = false - ActionController::Base.consider_all_requests_local = false + test "info controller renders a table with properties" do get :properties - assert_tag :tag => 'p' - assert_response 500 + assert_select 'table' end end diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 9befd44a58..971cba89d0 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -1,9 +1,12 @@ $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" +$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" require 'test/unit' require 'active_support' +require 'active_support/test_case' +require 'action_controller' unless defined?(Rails) && defined?(Rails::Info) module Rails @@ -11,7 +14,7 @@ unless defined?(Rails) && defined?(Rails::Info) end end -class InfoTest < Test::Unit::TestCase +class InfoTest < ActiveSupport::TestCase def setup Rails.send :remove_const, :Info silence_warnings { load 'rails/info.rb' } @@ -72,6 +75,18 @@ EOS end end + def test_middleware_property + assert property_defined?('Middleware') + end + + def test_html_includes_middleware + html = Rails::Info.to_html + assert html.include?('Middleware') + properties.value_for('Middleware').each do |value| + assert html.include?("
  • #{CGI.escapeHTML(value)}
  • ") + end + end + protected def svn_info=(info) Rails::Info.module_eval do -- cgit v1.2.3