diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-26 13:57:11 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-26 13:57:11 +0100 |
commit | 1dca7ebc93ebf067a73d23ddc33d97229a0b482f (patch) | |
tree | 6070c9418bf939427b7d1e7f1018dd0ec09ff1e3 /railties/test/application | |
parent | e6da2f651ffc24e5be3842051df73493d158a6b4 (diff) | |
download | rails-1dca7ebc93ebf067a73d23ddc33d97229a0b482f.tar.gz rails-1dca7ebc93ebf067a73d23ddc33d97229a0b482f.tar.bz2 rails-1dca7ebc93ebf067a73d23ddc33d97229a0b482f.zip |
Refactor railties test, break huge files in smaller chunks and move initializers to application folder.
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/configuration_test.rb | 23 | ||||
-rw-r--r-- | railties/test/application/generators_test.rb | 13 | ||||
-rw-r--r-- | railties/test/application/initializer_test.rb | 196 | ||||
-rw-r--r-- | railties/test/application/initializers/boot_test.rb | 16 | ||||
-rw-r--r-- | railties/test/application/initializers/check_ruby_version_test.rb | 33 | ||||
-rw-r--r-- | railties/test/application/initializers/frameworks_test.rb | 80 | ||||
-rw-r--r-- | railties/test/application/initializers/i18n_test.rb | 55 | ||||
-rw-r--r-- | railties/test/application/initializers/initializers_test.rb | 55 | ||||
-rw-r--r-- | railties/test/application/initializers/load_path_test.rb | 62 | ||||
-rw-r--r-- | railties/test/application/initializers/notifications_test.rb (renamed from railties/test/application/notifications_test.rb) | 0 | ||||
-rw-r--r-- | railties/test/application/paths_test.rb | 99 | ||||
-rw-r--r-- | railties/test/application/rackup_test.rb (renamed from railties/test/application/load_test.rb) | 2 | ||||
-rw-r--r-- | railties/test/application/routing_test.rb | 78 |
13 files changed, 441 insertions, 271 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index d3ba54a668..666c47af67 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1,7 +1,7 @@ require "isolation/abstract_unit" module ApplicationTests - class InitializerTest < Test::Unit::TestCase + class ConfigurationTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation def new_app @@ -59,21 +59,12 @@ module ApplicationTests end end - test "if there's no config.active_support.bare, all of ActiveSupport is required" do - use_frameworks [] + test "Rails.root should be a Pathname" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY require "#{app_path}/config/environment" - assert_nothing_raised { [1,2,3].rand } - end - - test "config.active_support.bare does not require all of ActiveSupport" do - add_to_config "config.active_support.bare = true" - - use_frameworks [] - - Dir.chdir("#{app_path}/app") do - require "#{app_path}/config/environment" - assert_raises(NoMethodError) { [1,2,3].rand } - end + assert_instance_of Pathname, Rails.root end test "marking the application as threadsafe sets the correct config variables" do @@ -136,7 +127,7 @@ module ApplicationTests value = value.reverse if key =~ /baz/ }] RUBY - + assert_nothing_raised do require "#{app_path}/config/application" end diff --git a/railties/test/application/generators_test.rb b/railties/test/application/generators_test.rb index e1e51c318c..1e6e30e9c3 100644 --- a/railties/test/application/generators_test.rb +++ b/railties/test/application/generators_test.rb @@ -92,18 +92,5 @@ module ApplicationTests assert_equal({ :plugin => { :generator => "-g" } }, c.generators.aliases) end end - - test "generators with hashes are deep merged" do - with_config do |c| - c.generators do |g| - g.orm :datamapper, :migration => false - g.plugin :aliases => { :generator => "-g" }, - :generator => true - end - end - - assert Rails::Generators.aliases.size >= 1 - assert Rails::Generators.options.size >= 1 - end end end diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb deleted file mode 100644 index 053757979b..0000000000 --- a/railties/test/application/initializer_test.rb +++ /dev/null @@ -1,196 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class InitializerTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf "#{app_path}/config/environments" - end - - test "initializing an application adds the application paths to the load path" do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - - require "#{app_path}/config/environment" - assert $:.include?("#{app_path}/app/models") - end - - test "eager loading loads parent classes before children" do - app_file "lib/zoo.rb", <<-ZOO - class Zoo ; include ReptileHouse ; end - ZOO - app_file "lib/zoo/reptile_house.rb", <<-ZOO - module Zoo::ReptileHouse ; end - ZOO - - add_to_config <<-RUBY - config.root = "#{app_path}" - config.eager_load_paths << "#{app_path}/lib" - RUBY - - require "#{app_path}/config/environment" - - assert Zoo - end - - test "load environment with global" do - app_file "config/environments/development.rb", <<-RUBY - $initialize_test_set_from_env = 'success' - AppTemplate::Application.configure do - config.cache_classes = true - config.time_zone = "Brasilia" - end - RUBY - - assert_nil $initialize_test_set_from_env - add_to_config <<-RUBY - config.root = "#{app_path}" - config.time_zone = "UTC" - RUBY - - require "#{app_path}/config/environment" - assert_equal "success", $initialize_test_set_from_env - assert AppTemplate::Application.config.cache_classes - assert_equal "Brasilia", AppTemplate::Application.config.time_zone - end - - test "action_controller load paths set only if action controller in use" do - assert_nothing_raised NameError do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - - use_frameworks [] - require "#{app_path}/config/environment" - end - end - - test "after_initialize block works correctly" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.after_initialize { $test_after_initialize_block1 = "success" } - config.after_initialize { $test_after_initialize_block2 = "congratulations" } - RUBY - require "#{app_path}/config/environment" - - assert_equal "success", $test_after_initialize_block1 - assert_equal "congratulations", $test_after_initialize_block2 - end - - test "after_initialize block works correctly when no block is passed" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.after_initialize { $test_after_initialize_block1 = "success" } - config.after_initialize # don't pass a block, this is what we're testing! - config.after_initialize { $test_after_initialize_block2 = "congratulations" } - RUBY - require "#{app_path}/config/environment" - - assert_equal "success", $test_after_initialize_block1 - assert_equal "congratulations", $test_after_initialize_block2 - end - - test "after_initialize runs after frameworks have been initialized" do - $activerecord_configurations = nil - add_to_config <<-RUBY - config.after_initialize { $activerecord_configurations = ActiveRecord::Base.configurations } - RUBY - - require "#{app_path}/config/environment" - assert $activerecord_configurations - assert $activerecord_configurations['development'] - end - - # i18n - test "setting another default locale" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.i18n.default_locale = :de - RUBY - require "#{app_path}/config/environment" - - assert_equal :de, I18n.default_locale - end - - test "no config locales dir present should return empty load path" do - FileUtils.rm_rf "#{app_path}/config/locales" - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - require "#{app_path}/config/environment" - - assert_equal [], Rails.application.config.i18n.load_path - end - - test "config locales dir present should be added to load path" do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - - require "#{app_path}/config/environment" - assert_equal ["#{app_path}/config/locales/en.yml"], Rails.application.config.i18n.load_path - end - - test "config defaults should be added with config settings" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.i18n.load_path << "my/other/locale.yml" - RUBY - require "#{app_path}/config/environment" - - assert_equal [ - "#{app_path}/config/locales/en.yml", "my/other/locale.yml" - ], Rails.application.config.i18n.load_path - end - - # DB middleware - test "database middleware doesn't initialize when session store is not active_record" do - add_to_config <<-RUBY - config.root = "#{app_path}" - config.action_controller.session_store = :cookie_store - RUBY - require "#{app_path}/config/environment" - - assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) - end - - test "database middleware initializes when session store is active record" do - add_to_config "config.action_controller.session_store = :active_record_store" - - require "#{app_path}/config/environment" - - expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] - middleware = Rails.application.config.middleware.map { |m| m.klass } - assert_equal expects, middleware & expects - end - - test "Rails.root should be a Pathname" do - add_to_config <<-RUBY - config.root = "#{app_path}" - RUBY - require "#{app_path}/config/environment" - assert_instance_of Pathname, Rails.root - end - end - - class InitializerCustomFrameworkExtensionsTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf "#{app_path}/config/environments" - end - - test "database middleware doesn't initialize when activerecord is not in frameworks" do - use_frameworks [] - require "#{app_path}/config/environment" - - assert_nil defined?(ActiveRecord) - end - end -end diff --git a/railties/test/application/initializers/boot_test.rb b/railties/test/application/initializers/boot_test.rb new file mode 100644 index 0000000000..5ec562f12f --- /dev/null +++ b/railties/test/application/initializers/boot_test.rb @@ -0,0 +1,16 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class GemBooting < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + # build_app + # boot_rails + end + + test "booting rails sets the load paths correctly" do + # This test is pending reworking the boot process + end + end +end
\ No newline at end of file diff --git a/railties/test/application/initializers/check_ruby_version_test.rb b/railties/test/application/initializers/check_ruby_version_test.rb new file mode 100644 index 0000000000..58782b2511 --- /dev/null +++ b/railties/test/application/initializers/check_ruby_version_test.rb @@ -0,0 +1,33 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class CheckRubyVersionTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + end + + test "rails initializes with ruby 1.8.7 or later" do + if RUBY_VERSION < '1.8.7' + assert_rails_does_not_boot + else + assert_rails_boots + end + end + + def assert_rails_boots + assert_nothing_raised "It appears that rails does not boot" do + require "rails/all" + end + end + + def assert_rails_does_not_boot + $stderr = File.open("/dev/null", "w") + assert_raises(SystemExit) do + require "rails/all" + end + end + end +end diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb new file mode 100644 index 0000000000..ea052320ef --- /dev/null +++ b/railties/test/application/initializers/frameworks_test.rb @@ -0,0 +1,80 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class FrameworlsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + # AC & AM + test "set load paths set only if action controller or action mailer are in use" do + assert_nothing_raised NameError do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + use_frameworks [] + require "#{app_path}/config/environment" + end + end + + test "sets action_controller and action_mailer load paths" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + require "#{app_path}/config/environment" + ActionController::Base.view_paths.include?(File.expand_path("app/views", app_path)) + ActionMailer::Base.view_paths.include?(File.expand_path("app/views", app_path)) + end + + # AS + test "if there's no config.active_support.bare, all of ActiveSupport is required" do + use_frameworks [] + require "#{app_path}/config/environment" + assert_nothing_raised { [1,2,3].rand } + end + + test "config.active_support.bare does not require all of ActiveSupport" do + add_to_config "config.active_support.bare = true" + + use_frameworks [] + + Dir.chdir("#{app_path}/app") do + require "#{app_path}/config/environment" + assert_raises(NoMethodError) { [1,2,3].rand } + end + end + + # AR + test "database middleware doesn't initialize when session store is not active_record" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.action_controller.session_store = :cookie_store + RUBY + require "#{app_path}/config/environment" + + assert !Rails.application.config.middleware.include?(ActiveRecord::SessionStore) + end + + test "database middleware initializes when session store is active record" do + add_to_config "config.action_controller.session_store = :active_record_store" + + require "#{app_path}/config/environment" + + expects = [ActiveRecord::ConnectionAdapters::ConnectionManagement, ActiveRecord::QueryCache, ActiveRecord::SessionStore] + middleware = Rails.application.config.middleware.map { |m| m.klass } + assert_equal expects, middleware & expects + end + + test "database middleware doesn't initialize when activerecord is not in frameworks" do + use_frameworks [] + require "#{app_path}/config/environment" + assert_nil defined?(ActiveRecord) + end + end +end diff --git a/railties/test/application/initializers/i18n_test.rb b/railties/test/application/initializers/i18n_test.rb new file mode 100644 index 0000000000..99b2d86013 --- /dev/null +++ b/railties/test/application/initializers/i18n_test.rb @@ -0,0 +1,55 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class I18nTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + # i18n + test "setting another default locale" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.i18n.default_locale = :de + RUBY + require "#{app_path}/config/environment" + + assert_equal :de, I18n.default_locale + end + + test "no config locales dir present should return empty load path" do + FileUtils.rm_rf "#{app_path}/config/locales" + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + require "#{app_path}/config/environment" + + assert_equal [], Rails.application.config.i18n.load_path + end + + test "config locales dir present should be added to load path" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + require "#{app_path}/config/environment" + assert_equal ["#{app_path}/config/locales/en.yml"], Rails.application.config.i18n.load_path + end + + test "config defaults should be added with config settings" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.i18n.load_path << "my/other/locale.yml" + RUBY + require "#{app_path}/config/environment" + + assert_equal [ + "#{app_path}/config/locales/en.yml", "my/other/locale.yml" + ], Rails.application.config.i18n.load_path + end + end +end
\ No newline at end of file diff --git a/railties/test/application/initializers/initializers_test.rb b/railties/test/application/initializers/initializers_test.rb new file mode 100644 index 0000000000..0c3de7ce33 --- /dev/null +++ b/railties/test/application/initializers/initializers_test.rb @@ -0,0 +1,55 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class InitializersTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + test "load initializers" do + app_file "config/initializers/foo.rb", "$foo = true" + require "#{app_path}/config/environment" + assert $foo + end + + test "after_initialize block works correctly" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.after_initialize { $test_after_initialize_block1 = "success" } + config.after_initialize { $test_after_initialize_block2 = "congratulations" } + RUBY + require "#{app_path}/config/environment" + + assert_equal "success", $test_after_initialize_block1 + assert_equal "congratulations", $test_after_initialize_block2 + end + + test "after_initialize block works correctly when no block is passed" do + add_to_config <<-RUBY + config.root = "#{app_path}" + config.after_initialize { $test_after_initialize_block1 = "success" } + config.after_initialize # don't pass a block, this is what we're testing! + config.after_initialize { $test_after_initialize_block2 = "congratulations" } + RUBY + require "#{app_path}/config/environment" + + assert_equal "success", $test_after_initialize_block1 + assert_equal "congratulations", $test_after_initialize_block2 + end + + test "after_initialize runs after frameworks have been initialized" do + $activerecord_configurations = nil + add_to_config <<-RUBY + config.after_initialize { $activerecord_configurations = ActiveRecord::Base.configurations } + RUBY + + require "#{app_path}/config/environment" + assert $activerecord_configurations + assert $activerecord_configurations['development'] + end + end +end diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb new file mode 100644 index 0000000000..714b6114a2 --- /dev/null +++ b/railties/test/application/initializers/load_path_test.rb @@ -0,0 +1,62 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class LoadPathTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf "#{app_path}/config/environments" + end + + # General + test "initializing an application adds the application paths to the load path" do + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + require "#{app_path}/config/environment" + assert $:.include?("#{app_path}/app/models") + end + + test "eager loading loads parent classes before children" do + app_file "lib/zoo.rb", <<-ZOO + class Zoo ; include ReptileHouse ; end + ZOO + app_file "lib/zoo/reptile_house.rb", <<-ZOO + module Zoo::ReptileHouse ; end + ZOO + + add_to_config <<-RUBY + config.root = "#{app_path}" + config.eager_load_paths << "#{app_path}/lib" + RUBY + + require "#{app_path}/config/environment" + + assert Zoo + end + + test "load environment with global" do + app_file "config/environments/development.rb", <<-RUBY + $initialize_test_set_from_env = 'success' + AppTemplate::Application.configure do + config.cache_classes = true + config.time_zone = "Brasilia" + end + RUBY + + assert_nil $initialize_test_set_from_env + add_to_config <<-RUBY + config.root = "#{app_path}" + config.time_zone = "UTC" + RUBY + + require "#{app_path}/config/environment" + assert_equal "success", $initialize_test_set_from_env + assert AppTemplate::Application.config.cache_classes + assert_equal "Brasilia", AppTemplate::Application.config.time_zone + end + end +end diff --git a/railties/test/application/notifications_test.rb b/railties/test/application/initializers/notifications_test.rb index 061bb34c19..061bb34c19 100644 --- a/railties/test/application/notifications_test.rb +++ b/railties/test/application/initializers/notifications_test.rb diff --git a/railties/test/application/paths_test.rb b/railties/test/application/paths_test.rb new file mode 100644 index 0000000000..ac0aa27c64 --- /dev/null +++ b/railties/test/application/paths_test.rb @@ -0,0 +1,99 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class PathsTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + app_file "config/environments/development.rb", "" + add_to_config <<-RUBY + config.root = "#{app_path}" + config.after_initialize do + ActionController::Base.session_store = nil + end + RUBY + use_frameworks [:action_controller, :action_view, :action_mailer, :active_record] + require "#{app_path}/config/environment" + @paths = Rails.application.config.paths + end + + def root(*path) + app_path(*path).to_s + end + + def assert_path(paths, *dir) + assert_equal [root(*dir)], paths.paths + end + + def assert_in_load_path(*path) + assert $:.any? { |p| File.expand_path(p) == root(*path) }, "Load path does not include '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + + def assert_not_in_load_path(*path) + assert !$:.any? { |p| File.expand_path(p) == root(*path) }, "Load path includes '#{root(*path)}'. They are:\n-----\n #{$:.join("\n")}\n-----" + end + + test "booting up Rails yields a valid paths object" do + assert_path @paths.app.models, "app", "models" + assert_path @paths.app.metals, "app", "metal" + assert_path @paths.app.helpers, "app", "helpers" + assert_path @paths.app.views, "app", "views" + assert_path @paths.lib, "lib" + assert_path @paths.vendor, "vendor" + assert_path @paths.vendor.plugins, "vendor", "plugins" + assert_path @paths.tmp, "tmp" + assert_path @paths.tmp.cache, "tmp", "cache" + assert_path @paths.config, "config" + assert_path @paths.config.locales, "config", "locales", "en.yml" + assert_path @paths.config.environment, "config", "environments", "development.rb" + + assert_equal root("app", "controllers"), @paths.app.controllers.to_a.first + assert_equal Pathname.new(File.dirname(__FILE__)).join("..", "..", "builtin", "rails_info").expand_path, + Pathname.new(@paths.app.controllers.to_a[1]).expand_path + end + + test "booting up Rails yields a list of paths that are eager" do + assert @paths.app.eager_load? + assert @paths.app.controllers.eager_load? + assert @paths.app.helpers.eager_load? + end + + test "environments has a glob equal to the current environment" do + assert_equal "#{Rails.env}.rb", @paths.config.environment.glob + end + + test "load path includes each of the paths in config.paths as long as the directories exist" do + assert_in_load_path "app", "controllers" + assert_in_load_path "app", "models" + assert_in_load_path "app", "helpers" + assert_in_load_path "lib" + assert_in_load_path "vendor" + + assert_not_in_load_path "app", "metal" + assert_not_in_load_path "config" + assert_not_in_load_path "config", "locales" + assert_not_in_load_path "config", "environments" + assert_not_in_load_path "tmp" + assert_not_in_load_path "tmp", "cache" + end + + test "controller paths include builtin in development mode" do + Rails.env.replace "development" + assert Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in test mode" do + Rails.env.replace "test" + assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + test "controller paths does not have builtin_directories in production mode" do + Rails.env.replace "production" + assert !Rails::Application::Configuration.new("/").paths.app.controllers.paths.any? { |p| p =~ /builtin/ } + end + + end +end diff --git a/railties/test/application/load_test.rb b/railties/test/application/rackup_test.rb index 1c5811b07a..f909c1b282 100644 --- a/railties/test/application/load_test.rb +++ b/railties/test/application/rackup_test.rb @@ -1,7 +1,7 @@ require "isolation/abstract_unit" module ApplicationTests - class LoadTest < Test::Unit::TestCase + class RackupTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation def rackup diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 50cb9e3acc..b93e349a46 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -14,7 +14,6 @@ module ApplicationTests def app @app ||= begin require "#{app_path}/config/environment" - Rails.application end end @@ -26,7 +25,7 @@ module ApplicationTests test "simple controller" do controller :foo, <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "foo" end @@ -43,9 +42,36 @@ module ApplicationTests assert_equal 'foo', last_response.body end + test "simple controller with helper" do + controller :foo, <<-RUBY + class FooController < ApplicationController + def index + render :inline => "<%= foo_or_bar? %>" + end + end + RUBY + + app_file 'app/helpers/bar_helper.rb', <<-RUBY + module BarHelper + def foo_or_bar? + "bar" + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do |map| + match ':controller(/:action)' + end + RUBY + + get '/foo' + assert_equal 'bar', last_response.body + end + test "multiple controllers" do controller :foo, <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "foo" end @@ -75,7 +101,7 @@ module ApplicationTests test "nested controller" do controller 'foo', <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "foo" end @@ -84,7 +110,7 @@ module ApplicationTests controller 'admin/foo', <<-RUBY module Admin - class FooController < ActionController::Base + class FooController < ApplicationController def index render :text => "admin::foo" end @@ -105,47 +131,9 @@ module ApplicationTests assert_equal 'admin::foo', last_response.body end - test "merges with plugin routes" do - controller 'foo', <<-RUBY - class FooController < ActionController::Base - def index - render :text => "foo" - end - end - RUBY - - app_file 'config/routes.rb', <<-RUBY - AppTemplate::Application.routes.draw do |map| - match 'foo', :to => 'foo#index' - end - RUBY - - plugin 'bar', 'require File.dirname(__FILE__) + "/app/controllers/bar"' do |plugin| - plugin.write 'app/controllers/bar.rb', <<-RUBY - class BarController < ActionController::Base - def index - render :text => "bar" - end - end - RUBY - - plugin.write 'config/routes.rb', <<-RUBY - AppTemplate::Application.routes.draw do |map| - match 'bar', :to => 'bar#index' - end - RUBY - end - - get '/foo' - assert_equal 'foo', last_response.body - - get '/bar' - assert_equal 'bar', last_response.body - end - test "reloads routes when configuration is changed" do controller :foo, <<-RUBY - class FooController < ActionController::Base + class FooController < ApplicationController def bar render :text => "bar" end @@ -191,7 +179,7 @@ module ApplicationTests RUBY controller 'yazilar', <<-RUBY - class YazilarController < ActionController::Base + class YazilarController < ApplicationController def index render :text => 'yazilar#index' end |