From 0cd9b149e2e8af10f835718018cf009ebc4f9fda Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 15 Nov 2008 12:26:37 -0800 Subject: Appropriate test case subclasses to get assert_tag and assert_deprecated --- railties/test/rails_info_controller_test.rb | 2 +- railties/test/secret_key_generation_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_controller_test.rb b/railties/test/rails_info_controller_test.rb index e1872ebf33..e274e1aa6e 100644 --- a/railties/test/rails_info_controller_test.rb +++ b/railties/test/rails_info_controller_test.rb @@ -25,7 +25,7 @@ ActionController::Routing::Routes.draw do |map| map.connect ':controller/:action/:id' end -class Rails::InfoControllerTest < Test::Unit::TestCase +class Rails::InfoControllerTest < ActionController::TestCase def setup @controller = Rails::InfoController.new @request = ActionController::TestRequest.new diff --git a/railties/test/secret_key_generation_test.rb b/railties/test/secret_key_generation_test.rb index 7269f98ce5..df486c3bbb 100644 --- a/railties/test/secret_key_generation_test.rb +++ b/railties/test/secret_key_generation_test.rb @@ -22,7 +22,7 @@ require 'rails_generator' require 'rails_generator/secret_key_generator' require 'rails_generator/generators/applications/app/app_generator' -class SecretKeyGenerationTest < Test::Unit::TestCase +class SecretKeyGenerationTest < ActiveSupport::TestCase SECRET_KEY_MIN_LENGTH = 128 APP_NAME = "foo" -- cgit v1.2.3 From 3c9beb3dab73013af83b90983f283b76625052b8 Mon Sep 17 00:00:00 2001 From: Eugene Bolshakov Date: Mon, 17 Nov 2008 21:55:56 -0600 Subject: Add helper test generators [#1199 state:resolved] Signed-off-by: Joshua Peek --- railties/test/generators/generator_test_helper.rb | 31 ++++++++++++++----- .../generators/rails_controller_generator_test.rb | 32 ++++++++++--------- .../test/generators/rails_helper_generator_test.rb | 36 ++++++++++++++++++++++ .../generators/rails_resource_generator_test.rb | 4 +-- .../generators/rails_scaffold_generator_test.rb | 7 +++-- 5 files changed, 83 insertions(+), 27 deletions(-) create mode 100644 railties/test/generators/rails_helper_generator_test.rb (limited to 'railties/test') diff --git a/railties/test/generators/generator_test_helper.rb b/railties/test/generators/generator_test_helper.rb index 0901b215e4..01bf1c90bd 100644 --- a/railties/test/generators/generator_test_helper.rb +++ b/railties/test/generators/generator_test_helper.rb @@ -145,6 +145,19 @@ class GeneratorTestCase < Test::Unit::TestCase end end + # Asserts that the given helper test test was generated. + # It takes a name or symbol without the _helper_test part and an optional super class. + # The contents of the class source file is passed to a block. + def assert_generated_helper_test_for(name, parent = "ActionView::TestCase") + path = "test/unit/helpers/#{name.to_s.underscore}_helper_test" + # Have to pass the path without the "test/" part so that class_name_from_path will return a correct result + class_name = class_name_from_path(path.gsub(/^test\//, '')) + + assert_generated_class path,parent,class_name do |body| + yield body if block_given? + end + end + # Asserts that the given unit test was generated. # It takes a name or symbol without the _test part and an optional super class. # The contents of the class source file is passed to a block. @@ -172,19 +185,21 @@ class GeneratorTestCase < Test::Unit::TestCase # Asserts that the given class source file was generated. # It takes a path without the .rb part and an optional super class. # The contents of the class source file is passed to a block. - def assert_generated_class(path, parent = nil) + def assert_generated_class(path, parent = nil, class_name = class_name_from_path(path)) + assert_generated_file("#{path}.rb") do |body| + assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class" + yield body if block_given? + end + end + + def class_name_from_path(path) # FIXME: Sucky way to detect namespaced classes if path.split('/').size > 3 path =~ /\/?(\d+_)?(\w+)\/(\w+)$/ - class_name = "#{$2.camelize}::#{$3.camelize}" + "#{$2.camelize}::#{$3.camelize}" else path =~ /\/?(\d+_)?(\w+)$/ - class_name = $2.camelize - end - - assert_generated_file("#{path}.rb") do |body| - assert_match /class #{class_name}#{parent.nil? ? '':" < #{parent}"}/, body, "the file '#{path}.rb' should be a class" - yield body if block_given? + $2.camelize end end diff --git a/railties/test/generators/rails_controller_generator_test.rb b/railties/test/generators/rails_controller_generator_test.rb index f839ea97e6..43fbe972e2 100644 --- a/railties/test/generators/rails_controller_generator_test.rb +++ b/railties/test/generators/rails_controller_generator_test.rb @@ -11,6 +11,7 @@ class RailsControllerGeneratorTest < GeneratorTestCase assert_generated_controller_for :products assert_generated_functional_test_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products end def test_controller_generates_namespaced_controller @@ -19,24 +20,25 @@ class RailsControllerGeneratorTest < GeneratorTestCase assert_generated_controller_for "admin::products" assert_generated_functional_test_for "admin::products" assert_generated_helper_for "admin::products" + assert_generated_helper_test_for "admin::products" end def test_controller_generates_namespaced_and_not_namespaced_controllers - run_generator('controller', %w(products)) - - # We have to require the generated helper to show the problem because - # the test helpers just check for generated files and contents but - # do not actually load them. But they have to be loaded (as in a real environment) - # to make the second generator run fail - require "#{RAILS_ROOT}/app/helpers/products_helper" - - assert_nothing_raised do - begin - run_generator('controller', %w(admin::products)) - ensure - # cleanup - Object.send(:remove_const, :ProductsHelper) - end + run_generator('controller', %w(products)) + + # We have to require the generated helper to show the problem because + # the test helpers just check for generated files and contents but + # do not actually load them. But they have to be loaded (as in a real environment) + # to make the second generator run fail + require "#{RAILS_ROOT}/app/helpers/products_helper" + + assert_nothing_raised do + begin + run_generator('controller', %w(admin::products)) + ensure + # cleanup + Object.send(:remove_const, :ProductsHelper) end + end end end diff --git a/railties/test/generators/rails_helper_generator_test.rb b/railties/test/generators/rails_helper_generator_test.rb new file mode 100644 index 0000000000..8d05f555e6 --- /dev/null +++ b/railties/test/generators/rails_helper_generator_test.rb @@ -0,0 +1,36 @@ +require File.dirname(__FILE__) + '/generator_test_helper' + +class RailsHelperGeneratorTest < GeneratorTestCase + def test_helper_generates_helper + run_generator('helper', %w(products)) + + assert_generated_helper_for :products + assert_generated_helper_test_for :products + end + + def test_helper_generates_namespaced_helper + run_generator('helper', %w(admin::products)) + + assert_generated_helper_for "admin::products" + assert_generated_helper_test_for "admin::products" + end + + def test_helper_generates_namespaced_and_not_namespaced_helpers + run_generator('helper', %w(products)) + + # We have to require the generated helper to show the problem because + # the test helpers just check for generated files and contents but + # do not actually load them. But they have to be loaded (as in a real environment) + # to make the second generator run fail + require "#{RAILS_ROOT}/app/helpers/products_helper" + + assert_nothing_raised do + begin + run_generator('helper', %w(admin::products)) + ensure + # cleanup + Object.send(:remove_const, :ProductsHelper) + end + end + end +end diff --git a/railties/test/generators/rails_resource_generator_test.rb b/railties/test/generators/rails_resource_generator_test.rb index 45e4850ef5..1f5bd0ef1e 100644 --- a/railties/test/generators/rails_resource_generator_test.rb +++ b/railties/test/generators/rails_resource_generator_test.rb @@ -1,7 +1,6 @@ require 'generators/generator_test_helper' class RailsResourceGeneratorTest < GeneratorTestCase - def test_resource_generates_resources run_generator('resource', %w(Product name:string)) @@ -10,6 +9,7 @@ class RailsResourceGeneratorTest < GeneratorTestCase assert_generated_fixtures_for :products assert_generated_functional_test_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_migration :create_products assert_added_route_for :products end @@ -22,8 +22,8 @@ class RailsResourceGeneratorTest < GeneratorTestCase assert_generated_fixtures_for :products assert_generated_functional_test_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_skipped_migration :create_products assert_added_route_for :products end - end diff --git a/railties/test/generators/rails_scaffold_generator_test.rb b/railties/test/generators/rails_scaffold_generator_test.rb index de6b38dafe..926607f55c 100644 --- a/railties/test/generators/rails_scaffold_generator_test.rb +++ b/railties/test/generators/rails_scaffold_generator_test.rb @@ -2,7 +2,6 @@ require 'generators/generator_test_helper' require 'abstract_unit' class RailsScaffoldGeneratorTest < GeneratorTestCase - def test_scaffolded_names g = Rails::Generator::Base.instance('scaffold', %w(ProductLine)) assert_equal "ProductLines", g.controller_name @@ -43,6 +42,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb" @@ -58,6 +58,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" assert_skipped_migration :create_products @@ -93,6 +94,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb", "new.html.erb", "edit.html.erb", "show.html.erb" @@ -126,6 +128,7 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :product assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" assert_skipped_migration :create_products @@ -140,10 +143,10 @@ class RailsScaffoldGeneratorTest < GeneratorTestCase assert_generated_unit_test_for :products assert_generated_fixtures_for :products assert_generated_helper_for :products + assert_generated_helper_test_for :products assert_generated_stylesheet :scaffold assert_generated_views_for :products, "index.html.erb","new.html.erb","edit.html.erb","show.html.erb" assert_skipped_migration :create_products assert_added_route_for :products end - end -- cgit v1.2.3 From d9b92ee11b33fed5c7a94a91415fa846705f7dd3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 18 Nov 2008 14:23:13 +0100 Subject: Added config.i18n settings gatherer to config/environment, auto-loading of all locales in config/locales/*.rb,yml, and config/locales/en.yml as a sample locale [DHH] --- railties/test/initializer_test.rb | 49 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 5147eeb482..9c045ed66a 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -18,7 +18,6 @@ class ConfigurationMock < Rails::Configuration end class Initializer_load_environment_Test < Test::Unit::TestCase - def test_load_environment_with_constant config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb") assert_nil $initialize_test_set_from_env @@ -260,5 +259,51 @@ uses_mocha "Initializer plugin loading tests" do @initializer.load_plugins end 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 + end + + def test_config_defaults_should_be_added_with_config_settings + File.stubs(:exist?).returns(true) + Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) + + 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" + + Rails::Initializer.run(:initialize_i18n, config) + assert_equal [ + "./test/../../activesupport/lib/active_support/locale/en-US.yml", + "./test/../../actionpack/lib/action_view/locale/en-US.yml", + "my/test/locale.yml", + "my/other/locale.yml" ], I18n.load_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 +end \ No newline at end of file -- cgit v1.2.3 From 549388c244a87562030268689fdfc051c680ec0d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 19 Nov 2008 12:22:06 -0800 Subject: Reflect default locale change from en-US to en --- railties/test/initializer_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 9c045ed66a..e09fd3d34e 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -293,8 +293,8 @@ uses_mocha 'i18n settings' do Rails::Initializer.run(:initialize_i18n, config) assert_equal [ - "./test/../../activesupport/lib/active_support/locale/en-US.yml", - "./test/../../actionpack/lib/action_view/locale/en-US.yml", + 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 end @@ -306,4 +306,4 @@ uses_mocha 'i18n settings' do assert_equal :de, I18n.default_locale end end -end \ No newline at end of file +end -- cgit v1.2.3 From e931012287df0bca83cae04d95c2e0835ae08758 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 23 Nov 2008 14:48:36 -0800 Subject: Require Mocha >= 0.9.3 which includes a MiniTest adapter --- railties/test/abstract_unit.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index e1ce32da65..516ab8523e 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -3,18 +3,15 @@ $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" +require 'rubygems' require 'test/unit' +gem 'mocha', '>= 0.9.3' +require 'mocha' require 'stringio' require 'active_support' -# Wrap tests that use Mocha and skip if unavailable. def uses_mocha(test_name) - require 'rubygems' - gem 'mocha', '>= 0.5.5' - require 'mocha' yield -rescue LoadError - $stderr.puts "Skipping #{test_name} tests. `gem install mocha` and try again." end if defined?(RAILS_ROOT) -- cgit v1.2.3 From 1f48c09094610cbf26ec1e93d9bf978b2ae86fa8 Mon Sep 17 00:00:00 2001 From: Manfred Stienstra Date: Mon, 24 Nov 2008 11:25:28 +0100 Subject: Accept a prefix argument to filter_backtrace_with_cleaning [#1456 state:committed] Add a prefix argument to filter_backtrace_with_cleaning so it has the same arity as test/unit's filter_backtrace. Signed-off-by: David Heinemeier Hansson --- railties/test/abstract_unit.rb | 3 ++- railties/test/backtrace_cleaner_test.rb | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 railties/test/backtrace_cleaner_test.rb (limited to 'railties/test') diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 516ab8523e..b6edc03391 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -9,6 +9,7 @@ gem 'mocha', '>= 0.9.3' require 'mocha' require 'stringio' require 'active_support' +require 'active_support/test_case' def uses_mocha(test_name) yield @@ -18,4 +19,4 @@ if defined?(RAILS_ROOT) RAILS_ROOT.replace File.dirname(__FILE__) else RAILS_ROOT = File.dirname(__FILE__) -end +end \ No newline at end of file diff --git a/railties/test/backtrace_cleaner_test.rb b/railties/test/backtrace_cleaner_test.rb new file mode 100644 index 0000000000..5955fd2856 --- /dev/null +++ b/railties/test/backtrace_cleaner_test.rb @@ -0,0 +1,28 @@ +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' ] + 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 \ No newline at end of file -- cgit v1.2.3 From a5870d43e3aac4ae02a650d0112b305c6a3d9114 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 18:47:42 -0800 Subject: Rename Rails::Info.components to frameworks --- railties/test/rails_info_test.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'railties/test') diff --git a/railties/test/rails_info_test.rb b/railties/test/rails_info_test.rb index 3e91e2f2ee..9befd44a58 100644 --- a/railties/test/rails_info_test.rb +++ b/railties/test/rails_info_test.rb @@ -61,14 +61,14 @@ EOS assert_property 'Goodbye', 'World' end - def test_component_version + def test_framework_version assert_property 'Active Support version', ActiveSupport::VERSION::STRING end - def test_components_exist - Rails::Info.components.each do |component| - dir = File.dirname(__FILE__) + "/../../" + component.gsub('_', '') - assert File.directory?(dir), "#{component.classify} does not exist" + def test_frameworks_exist + Rails::Info.frameworks.each do |framework| + dir = File.dirname(__FILE__) + "/../../" + framework.gsub('_', '') + assert File.directory?(dir), "#{framework.classify} does not exist" end end -- cgit v1.2.3 From d40bc307f9cc5836a3eb22e0cbdb612eaaf2bc04 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 21:47:09 -0800 Subject: Explicitly require action_view to bring in its i18n load path --- railties/test/initializer_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index e09fd3d34e..82c8abc290 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -291,6 +291,9 @@ uses_mocha 'i18n settings' do 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"), -- cgit v1.2.3 From cb4968171020bf3bb8f713cd69fe035ee5a3d608 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 21:47:26 -0800 Subject: Skip fcgi dispatcher tests if fcgi lib isn't available --- railties/test/fcgi_dispatcher_test.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'railties/test') diff --git a/railties/test/fcgi_dispatcher_test.rb b/railties/test/fcgi_dispatcher_test.rb index 64d054d45c..cc054c24aa 100644 --- a/railties/test/fcgi_dispatcher_test.rb +++ b/railties/test/fcgi_dispatcher_test.rb @@ -1,7 +1,6 @@ require 'abstract_unit' -uses_mocha 'fcgi dispatcher tests' do - +begin require 'fcgi_handler' module ActionController; module Routing; module Routes; end end end @@ -296,4 +295,6 @@ class RailsFCGIHandlerPeriodicGCTest < Test::Unit::TestCase end end -end # uses_mocha +rescue LoadError => e + raise unless e.message =~ /fcgi/ +end -- cgit v1.2.3 From ce50ca1baf29f2edc829011ffc247e68ebd995c3 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 24 Nov 2008 22:39:11 -0800 Subject: Explicitly require AS::Deprecation for the SecretKeyGenerator. Bring in ActiveSupport::TestCase for its tests. --- railties/test/secret_key_generation_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'railties/test') diff --git a/railties/test/secret_key_generation_test.rb b/railties/test/secret_key_generation_test.rb index df486c3bbb..2c7c3d5dfe 100644 --- a/railties/test/secret_key_generation_test.rb +++ b/railties/test/secret_key_generation_test.rb @@ -1,4 +1,4 @@ -require 'test/unit' +require 'abstract_unit' # Must set before requiring generator libs. if defined?(RAILS_ROOT) -- cgit v1.2.3 From 63d8f56774dcb1ea601928c3eb6c119d359fae10 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 14:41:20 +0100 Subject: Added app/[models|controllers|helpers] to the load path for plugins that has an app directory (go engines ;)) [DHH] --- railties/test/initializer_test.rb | 8 ++++---- railties/test/plugin_loader_test.rb | 25 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 82c8abc290..88c267b58e 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -209,7 +209,7 @@ uses_mocha "Initializer plugin loading tests" do def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched failure_tip = "It's likely someone has added a new plugin fixture without updating this list" load_plugins! - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip end def test_all_plugins_loaded_when_all_is_used @@ -217,7 +217,7 @@ uses_mocha "Initializer plugin loading tests" do only_load_the_following_plugins! plugin_names load_plugins! failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip end def test_all_plugins_loaded_after_all @@ -225,7 +225,7 @@ uses_mocha "Initializer plugin loading tests" do only_load_the_following_plugins! plugin_names load_plugins! failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - assert_plugins [:stubby, :a, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip + assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip end def test_plugin_names_may_be_strings @@ -299,7 +299,7 @@ uses_mocha 'i18n settings' do 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 + "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path } end def test_setting_another_default_locale diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index f429bae15c..0d3aec5fd6 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -48,16 +48,16 @@ uses_mocha "Plugin Loader Tests" do end def test_should_find_all_availble_plugins_and_return_as_all_plugins - assert_plugins [:stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip + assert_plugins [ :engine, :stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip end def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip end def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil @configuration.plugins = nil - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip end def test_should_return_specific_plugins_named_in_config_plugins_array_if_set @@ -74,17 +74,17 @@ uses_mocha "Plugin Loader Tests" do def test_should_load_all_plugins_in_natural_order_when_all_is_used only_load_the_following_plugins! [:all] - assert_plugins [:a, :acts_as_chunky_bacon, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip end def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip end def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] - assert_plugins [:stubby, :a, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip + assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip end def test_should_accept_plugin_names_given_as_strings @@ -112,6 +112,19 @@ uses_mocha "Plugin Loader Tests" do assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end + + def test_should_add_engine_load_paths_to_Dependencies_load_paths + only_load_the_following_plugins! [:engine] + + @loader.add_plugin_load_paths + + %w( models controllers 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" + end + 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 4999d52e08a02ebba344f6c318f0af4b5b18f0e5 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 26 Nov 2008 20:03:25 +0100 Subject: Added that config/routes.rb files in engine plugins are automatically loaded (and reloaded when they change in dev mode) [DHH] --- .../plugins/engines/engine/app/controllers/engine_controller.rb | 2 ++ .../test/fixtures/plugins/engines/engine/app/models/engine_model.rb | 2 ++ railties/test/fixtures/plugins/engines/engine/config/routes.rb | 3 +++ railties/test/fixtures/plugins/engines/engine/init.rb | 3 +++ railties/test/initializer_test.rb | 1 + railties/test/plugin_locator_test.rb | 2 +- 6 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb create mode 100644 railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb create mode 100644 railties/test/fixtures/plugins/engines/engine/config/routes.rb create mode 100644 railties/test/fixtures/plugins/engines/engine/init.rb (limited to 'railties/test') diff --git a/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb b/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb new file mode 100644 index 0000000000..f08373de40 --- /dev/null +++ b/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb @@ -0,0 +1,2 @@ +class EngineController < ActionController::Base +end \ No newline at end of file diff --git a/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb b/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb new file mode 100644 index 0000000000..e265712185 --- /dev/null +++ b/railties/test/fixtures/plugins/engines/engine/app/models/engine_model.rb @@ -0,0 +1,2 @@ +class EngineModel +end \ No newline at end of file diff --git a/railties/test/fixtures/plugins/engines/engine/config/routes.rb b/railties/test/fixtures/plugins/engines/engine/config/routes.rb new file mode 100644 index 0000000000..cca8d1b146 --- /dev/null +++ b/railties/test/fixtures/plugins/engines/engine/config/routes.rb @@ -0,0 +1,3 @@ +ActionController::Routing::Routes.draw do |map| + map.connect '/engine', :controller => "engine" +end diff --git a/railties/test/fixtures/plugins/engines/engine/init.rb b/railties/test/fixtures/plugins/engines/engine/init.rb new file mode 100644 index 0000000000..f4b00c0fa4 --- /dev/null +++ b/railties/test/fixtures/plugins/engines/engine/init.rb @@ -0,0 +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) diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 88c267b58e..2104412c54 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -252,6 +252,7 @@ uses_mocha "Initializer plugin loading tests" do assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end + private def load_plugins! diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index 363fa27f15..5a8c651e5a 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -47,7 +47,7 @@ uses_mocha "Plugin Locator Tests" do end def test_should_return_all_plugins_found_under_the_set_plugin_paths - assert_equal ["a", "acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort + 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 -- cgit v1.2.3 From f2ee056873b84f8917e72d87181e1a9f5f653342 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 27 Nov 2008 18:59:24 +0100 Subject: Added view path support for engines [DHH] --- .../engine/app/controllers/engine_controller.rb | 2 +- railties/test/plugin_loader_test.rb | 228 +++++++++++---------- 2 files changed, 118 insertions(+), 112 deletions(-) (limited to 'railties/test') diff --git a/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb b/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb index f08373de40..323ee1c4dc 100644 --- a/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb +++ b/railties/test/fixtures/plugins/engines/engine/app/controllers/engine_controller.rb @@ -1,2 +1,2 @@ -class EngineController < ActionController::Base +class EngineController end \ No newline at end of file diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 0d3aec5fd6..23b81ddbf6 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -1,5 +1,8 @@ require 'plugin_test_helper' +$:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" +require 'action_controller' + # Mocks out the configuration module Rails def self.configuration @@ -7,149 +10,152 @@ module Rails end end -uses_mocha "Plugin Loader Tests" do - - class TestPluginLoader < Test::Unit::TestCase - ORIGINAL_LOAD_PATH = $LOAD_PATH.dup - - def setup - reset_load_path! +class TestPluginLoader < Test::Unit::TestCase + ORIGINAL_LOAD_PATH = $LOAD_PATH.dup - @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') + def setup + reset_load_path! - @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + @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') - @loader = Rails::Plugin::Loader.new(@initializer) - end + @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" - def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result - locator_1 = stub(:plugins => [:a, :b, :c]) - locator_2 = stub(:plugins => [:d, :e, :f]) - locator_class_1 = stub(:new => locator_1) - locator_class_2 = stub(:new => locator_2) - @configuration.plugin_locators = [locator_class_1, locator_class_2] - assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins) - end + @loader = Rails::Plugin::Loader.new(@initializer) + end - def test_should_memoize_the_result_of_locate_plugins_as_all_plugins - plugin_list = [:a, :b, :c] - @loader.expects(:locate_plugins).once.returns(plugin_list) - assert_equal plugin_list, @loader.all_plugins - assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again - end + def test_should_locate_plugins_by_asking_each_locator_specifed_in_configuration_for_its_plugins_result + locator_1 = stub(:plugins => [:a, :b, :c]) + locator_2 = stub(:plugins => [:d, :e, :f]) + locator_class_1 = stub(:new => locator_1) + locator_class_2 = stub(:new => locator_2) + @configuration.plugin_locators = [locator_class_1, locator_class_2] + assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins) + end - def test_should_return_empty_array_if_configuration_plugins_is_empty - @configuration.plugins = [] - assert_equal [], @loader.plugins - end + def test_should_memoize_the_result_of_locate_plugins_as_all_plugins + plugin_list = [:a, :b, :c] + @loader.expects(:locate_plugins).once.returns(plugin_list) + assert_equal plugin_list, @loader.all_plugins + assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again + end - def test_should_find_all_availble_plugins_and_return_as_all_plugins - assert_plugins [ :engine, :stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip - end + def test_should_return_empty_array_if_configuration_plugins_is_empty + @configuration.plugins = [] + assert_equal [], @loader.plugins + end - def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched - assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end + def test_should_find_all_availble_plugins_and_return_as_all_plugins + assert_plugins [ :engine, :stubby, :plugin_with_no_lib_dir, :gemlike, :acts_as_chunky_bacon, :a], @loader.all_plugins.reverse, @failure_tip + end - def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil - @configuration.plugins = nil - assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end + def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + end - def test_should_return_specific_plugins_named_in_config_plugins_array_if_set - plugin_names = [:acts_as_chunky_bacon, :stubby] - only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins - end + def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil + @configuration.plugins = nil + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + end - def test_should_respect_the_order_of_plugins_given_in_configuration - plugin_names = [:stubby, :acts_as_chunky_bacon] - only_load_the_following_plugins! plugin_names - assert_plugins plugin_names, @loader.plugins - end + def test_should_return_specific_plugins_named_in_config_plugins_array_if_set + plugin_names = [:acts_as_chunky_bacon, :stubby] + only_load_the_following_plugins! plugin_names + assert_plugins plugin_names, @loader.plugins + end - def test_should_load_all_plugins_in_natural_order_when_all_is_used - only_load_the_following_plugins! [:all] - assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip - end + def test_should_respect_the_order_of_plugins_given_in_configuration + plugin_names = [:stubby, :acts_as_chunky_bacon] + only_load_the_following_plugins! plugin_names + assert_plugins plugin_names, @loader.plugins + end - def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip - end + def test_should_load_all_plugins_in_natural_order_when_all_is_used + only_load_the_following_plugins! [:all] + assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip + end - def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all - only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] - assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip - end + def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all] + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + end - def test_should_accept_plugin_names_given_as_strings - only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] - assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip - end + def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all + only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon] + assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip + end - def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - stubbed_application_lib_index_in_LOAD_PATHS = 4 - @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS) + def test_should_accept_plugin_names_given_as_strings + only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip + end - @loader.add_plugin_load_paths + def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + stubbed_application_lib_index_in_LOAD_PATHS = 4 + @loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS) - assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS - assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS - end + @loader.add_plugin_load_paths - def test_should_add_plugin_load_paths_to_Dependencies_load_paths - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] + assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS + assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS + end - @loader.add_plugin_load_paths + def test_should_add_plugin_load_paths_to_Dependencies_load_paths + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) - end + @loader.add_plugin_load_paths + assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert ActiveSupport::Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + end - def test_should_add_engine_load_paths_to_Dependencies_load_paths - only_load_the_following_plugins! [:engine] + def test_should_add_engine_load_paths_to_Dependencies_load_paths + only_load_the_following_plugins! [:engine] - @loader.add_plugin_load_paths + @loader.add_plugin_load_paths - %w( models controllers 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" - end + %w( models controllers 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" end + end + + def test_engine_controllers_should_have_their_view_path_set_when_loaded + only_load_the_following_plugins!([ :engine ]) - def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths - only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - - @loader.add_plugin_load_paths + @loader.send :add_engine_view_paths + + assert_equal [ File.join(plugin_fixture_path('engines/engine'), 'app', 'views') ], ActionController::Base.view_paths + end - assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) - assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) - end + def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths + only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon] - def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array - plugin_load_paths = ["a", "b"] - plugin = stub(:load_paths => plugin_load_paths) - @loader.stubs(:plugins).returns([plugin]) + @loader.add_plugin_load_paths - @loader.add_plugin_load_paths + assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib')) + assert ActiveSupport::Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) + end - plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) } - end + def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array + plugin_load_paths = ["a", "b"] + plugin = stub(:load_paths => plugin_load_paths) + @loader.stubs(:plugins).returns([plugin]) - private + @loader.add_plugin_load_paths - def reset_load_path! - $LOAD_PATH.clear - ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } - end + plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) } end -end + + private + def reset_load_path! + $LOAD_PATH.clear + ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path } + end +end \ No newline at end of file -- cgit v1.2.3 From fdfcdf467387c4db3d79c1f46eadbb55a88ef814 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 29 Nov 2008 10:57:36 +0100 Subject: Enhanced Rails.root to take parameters that'll be join with the root, like Rails.root('app', 'controllers') => File.join(Rails.root, 'app', 'controllers') [#1482 state:committed] (Damian Janowski) --- railties/test/initializer_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 2104412c54..33c81bc5ad 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -311,3 +311,13 @@ uses_mocha 'i18n settings' do end end end + +class RailsRootTest < Test::Unit::TestCase + def test_rails_dot_root_equals_rails_root + assert_equal RAILS_ROOT, Rails.root + end + + def test_rails_dot_root_accepts_arguments_for_file_dot_join + assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root('app', 'controllers') + end +end \ No newline at end of file -- cgit v1.2.3 From be140e8c6be966349c6fa35a87f84d5a73995b9a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 30 Nov 2008 15:59:30 -0600 Subject: Changed Rails.root to return a Pathname object (allows for Rails.root.join("app", "controllers") => "#{RAILS_ROOT}/app/controllers") [#1482] --- railties/test/initializer_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 33c81bc5ad..99f69a1575 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -317,7 +317,7 @@ class RailsRootTest < Test::Unit::TestCase assert_equal RAILS_ROOT, Rails.root end - def test_rails_dot_root_accepts_arguments_for_file_dot_join - assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root('app', 'controllers') + def test_rails_dot_root_should_be_a_pathname + assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers') end end \ No newline at end of file -- cgit v1.2.3 From 725928854d4b6ff5dbafc2bbc95cfade243411a9 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Mon, 1 Dec 2008 12:12:57 -0600 Subject: fix failing railties test --- railties/test/initializer_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'railties/test') diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 99f69a1575..dad9e55e61 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -314,10 +314,10 @@ end class RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_equals_rails_root - assert_equal RAILS_ROOT, Rails.root + assert_equal RAILS_ROOT, Rails.root.to_s end def test_rails_dot_root_should_be_a_pathname - assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers') + assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s end end \ No newline at end of file -- cgit v1.2.3 From 3c07a8828ede3d41000513af29c293ae2e2a49d4 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 24 Nov 2008 23:07:12 -0500 Subject: handle missing dependecies in gem loading Signed-off-by: Michael Koziarski --- railties/test/gem_dependency_test.rb | 14 ++++++++ .../vendor/gems/dummy-gem-f-1.0.0/.specification | 39 ++++++++++++++++++++++ .../gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb | 1 + .../vendor/gems/dummy-gem-g-1.0.0/.specification | 39 ++++++++++++++++++++++ .../gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb | 1 + 5 files changed, 94 insertions(+) create mode 100644 railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification create mode 100644 railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb create mode 100644 railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification create mode 100644 railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb (limited to 'railties/test') diff --git a/railties/test/gem_dependency_test.rb b/railties/test/gem_dependency_test.rb index 4f9e824c9f..1d4f2b18b3 100644 --- a/railties/test/gem_dependency_test.rb +++ b/railties/test/gem_dependency_test.rb @@ -129,5 +129,19 @@ uses_mocha "Plugin Tests" do 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? + debugger + assert_equal 2, dummy_gem.dependencies.size + assert_nothing_raised do + dummy_gem.dependencies.each do |g| + g.dependencies + end + end + end + end end diff --git a/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification b/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification new file mode 100644 index 0000000000..70a36b9a8c --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-f-1.0.0/.specification @@ -0,0 +1,39 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-f +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +- !ruby/object:Gem::Dependency + name: absolutely-no-such-gem + type: :runtime + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +files: +- lib +- lib/dummy-gem-f.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem F diff --git a/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb b/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb new file mode 100644 index 0000000000..0271c8c48a --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-f-1.0.0/lib/dummy-gem-f.rb @@ -0,0 +1 @@ +DUMMY_GEM_F_VERSION="1.0.0" 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 new file mode 100644 index 0000000000..5483048c1c --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-g-1.0.0/.specification @@ -0,0 +1,39 @@ +--- !ruby/object:Gem::Specification +name: dummy-gem-g +version: !ruby/object:Gem::Version + version: 1.3.0 +platform: ruby +authors: +- "Nobody" +date: 2008-10-03 00:00:00 -04:00 +dependencies: +- !ruby/object:Gem::Dependency + name: dummy-gem-f + type: :development + version_requirement: + version_requirements: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: 1.0.0 + version: +files: +- lib +- lib/dummy-gem-g.rb +require_paths: +- lib +required_ruby_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +required_rubygems_version: !ruby/object:Gem::Requirement + requirements: + - - ">=" + - !ruby/object:Gem::Version + version: "0" + version: +requirements: [] +specification_version: 2 +summary: Dummy Gem G diff --git a/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb b/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb new file mode 100644 index 0000000000..8fc056586c --- /dev/null +++ b/railties/test/vendor/gems/dummy-gem-g-1.0.0/lib/dummy-gem-g.rb @@ -0,0 +1 @@ +DUMMY_GEM_G_VERSION="1.0.0" -- cgit v1.2.3