diff options
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application.rb | 4 | ||||
-rw-r--r-- | railties/test/application/configuration_test.rb | 11 | ||||
-rw-r--r-- | railties/test/application/initializers/frameworks_test.rb | 6 | ||||
-rw-r--r-- | railties/test/application/initializers/load_path_test.rb | 16 | ||||
-rw-r--r-- | railties/test/railties/configuration_test.rb | 45 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 4 | ||||
-rw-r--r-- | railties/test/railties/framework_extension_test.rb | 82 | ||||
-rw-r--r-- | railties/test/railties/plugin_test.rb | 11 | ||||
-rw-r--r-- | railties/test/railties/railtie_test.rb | 132 | ||||
-rw-r--r-- | railties/test/railties/shared_tests.rb | 9 |
10 files changed, 190 insertions, 130 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 3ed34f21a6..9384492486 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -31,6 +31,10 @@ module Rails Rails.application = base.instance end + def respond_to?(*args) + super || instance.respond_to?(*args) + end + protected def method_missing(*args, &block) diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index 50d6ba2855..57bd797ef0 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -17,12 +17,15 @@ module ApplicationTests end def setup - FileUtils.rm_rf(new_app) if File.directory?(new_app) build_app boot_rails FileUtils.rm_rf("#{app_path}/config/environments") end + def teardown + FileUtils.rm_rf(new_app) if File.directory?(new_app) + end + test "Rails::Application.instance is nil until app is initialized" do require 'rails' assert_nil Rails::Application.instance @@ -30,6 +33,12 @@ module ApplicationTests assert_equal AppTemplate::Application.instance, Rails::Application.instance end + test "Rails::Application responds to all instance methods" do + require "#{app_path}/config/environment" + assert_respond_to Rails::Application, :routes_reloader + assert_equal Rails::Application.routes_reloader, Rails.application.routes_reloader + end + test "the application root is set correctly" do require "#{app_path}/config/environment" assert_equal Pathname.new(app_path), Rails.application.root diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index ea052320ef..1e7b9c9997 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -71,6 +71,12 @@ module ApplicationTests assert_equal expects, middleware & expects end + test "active_record extensions are applied to ActiveRecord" do + add_to_config "config.active_record.table_name_prefix = 'tbl_'" + require "#{app_path}/config/environment" + assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix + end + test "database middleware doesn't initialize when activerecord is not in frameworks" do use_frameworks [] require "#{app_path}/config/environment" diff --git a/railties/test/application/initializers/load_path_test.rb b/railties/test/application/initializers/load_path_test.rb index 714b6114a2..b39b9ecaae 100644 --- a/railties/test/application/initializers/load_path_test.rb +++ b/railties/test/application/initializers/load_path_test.rb @@ -10,7 +10,6 @@ module ApplicationTests 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}" @@ -20,10 +19,24 @@ module ApplicationTests assert $:.include?("#{app_path}/app/models") end + test "initializing an application eager load any path under app" do + app_file "app/anything/foo.rb", <<-RUBY + module Foo; end + RUBY + + add_to_config <<-RUBY + config.root = "#{app_path}" + RUBY + + require "#{app_path}/config/environment" + assert Foo + 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 @@ -34,7 +47,6 @@ module ApplicationTests RUBY require "#{app_path}/config/environment" - assert Zoo end diff --git a/railties/test/railties/configuration_test.rb b/railties/test/railties/configuration_test.rb deleted file mode 100644 index 17ea526bbf..0000000000 --- a/railties/test/railties/configuration_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "isolation/abstract_unit" - -module RailtiesTest - class ConfigurationTest < Test::Unit::TestCase - def setup - build_app - boot_rails - require "rails/all" - end - - test "config is available to plugins" do - class Foo < Rails::Railtie ; end - assert_nil Foo.config.action_controller.foo - end - - test "a config name is available for the plugin" do - class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end - assert_equal "hello", Foo.config.foo.greetings - end - - test "railtie configurations are available in the application" do - class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end - require "#{app_path}/config/application" - assert_equal "hello", AppTemplate::Application.config.foo.greetings - end - - test "railtie config merges are deep" do - class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end - class Bar < Rails::Railtie - config.foo.bar = "bar" - end - assert_equal "hello", Bar.config.foo.greetings - assert_equal "bar", Bar.config.foo.bar - end - - test "railtie can add subscribers" do - begin - class Foo < Rails::Railtie; subscriber(Rails::Subscriber.new); end - assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo] - ensure - Rails::Subscriber.subscribers.clear - end - end - end -end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 6f49ebcf1b..2f886dcd66 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -23,5 +23,9 @@ module RailtiesTest def reload_config :reload_engines end + + test "Rails::Engine itself does not respond to config" do + assert !Rails::Engine.respond_to?(:config) + end end end diff --git a/railties/test/railties/framework_extension_test.rb b/railties/test/railties/framework_extension_test.rb deleted file mode 100644 index 48e513cf01..0000000000 --- a/railties/test/railties/framework_extension_test.rb +++ /dev/null @@ -1,82 +0,0 @@ -require "isolation/abstract_unit" - -module RailtiesTest - class FrameworkExtensionTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf("#{app_path}/config/environments") - require "rails/all" - end - - test "rake_tasks block is executed when MyApp.load_tasks is called" do - $ran_block = false - - class MyTie < Rails::Railtie - rake_tasks do - $ran_block = true - end - end - - require "#{app_path}/config/environment" - - assert !$ran_block - require 'rake' - require 'rake/testtask' - require 'rake/rdoctask' - - AppTemplate::Application.load_tasks - assert $ran_block - end - - test "generators block is executed when MyApp.load_generators is called" do - $ran_block = false - - class MyTie < Rails::Railtie - generators do - $ran_block = true - end - end - - require "#{app_path}/config/environment" - - assert !$ran_block - AppTemplate::Application.load_generators - assert $ran_block - end - - test "railtie initializer" do - $ran_block = false - - class MyTie < Rails::Railtie - initializer :something_nice do - $ran_block = true - end - end - - assert !$ran_block - require "#{app_path}/config/environment" - assert $ran_block - end - end - - class ActiveRecordExtensionTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - FileUtils.rm_rf("#{app_path}/config/environments") - end - - test "active_record extensions are applied to ActiveRecord" do - add_to_config "config.active_record.table_name_prefix = 'tbl_'" - - require "#{app_path}/config/environment" - - assert_equal 'tbl_', ActiveRecord::Base.table_name_prefix - end - end -end
\ No newline at end of file diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb index a29186f14a..a3cccba3af 100644 --- a/railties/test/railties/plugin_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -19,6 +19,17 @@ module RailtiesTest :reload_plugins end + test "Rails::Plugin itself does not respond to config" do + assert !Rails::Plugin.respond_to?(:config) + end + + test "cannot inherit from Rails::Plugin" do + boot_rails + assert_raise RuntimeError do + class Foo < Rails::Plugin; end + end + end + test "plugin can load the file with the same name in lib" do boot_rails require "bukkits" diff --git a/railties/test/railties/railtie_test.rb b/railties/test/railties/railtie_test.rb new file mode 100644 index 0000000000..b723e08281 --- /dev/null +++ b/railties/test/railties/railtie_test.rb @@ -0,0 +1,132 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class RailtieTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + boot_rails + FileUtils.rm_rf("#{app_path}/config/environments") + require "rails/all" + end + + def app + @app ||= Rails.application + end + + test "Rails::Railtie itself does not respond to config" do + assert !Rails::Railtie.respond_to?(:config) + end + + test "cannot inherit from a railtie" do + class Foo < Rails::Railtie ; end + assert_raise RuntimeError do + class Bar < Foo; end + end + end + + test "config is available to railtie" do + class Foo < Rails::Railtie ; end + assert_nil Foo.config.action_controller.foo + end + + test "config name is available for the railtie" do + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end + assert_equal "hello", Foo.config.foo.greetings + end + + test "railtie configurations are available in the application" do + class Foo < Rails::Railtie ; config.foo.greetings = "hello" ; end + require "#{app_path}/config/application" + assert_equal "hello", AppTemplate::Application.config.foo.greetings + end + + test "railtie config merges are deep" do + class Foo < Rails::Railtie ; config.foo.greetings = 'hello' ; end + class Bar < Rails::Railtie + config.foo.bar = "bar" + end + assert_equal "hello", Bar.config.foo.greetings + assert_equal "bar", Bar.config.foo.bar + end + + test "railtie can add subscribers" do + begin + class Foo < Rails::Railtie ; subscriber(Rails::Subscriber.new) ; end + assert_kind_of Rails::Subscriber, Rails::Subscriber.subscribers[:foo] + ensure + Rails::Subscriber.subscribers.clear + end + end + + test "railtie can add to_prepare callbacks" do + $to_prepare = false + class Foo < Rails::Railtie ; config.to_prepare { $to_prepare = true } ; end + assert !$to_prepare + require "#{app_path}/config/environment" + require "rack/test" + extend Rack::Test::Methods + get "/" + assert $to_prepare + end + + test "railtie can add after_initialize callbacks" do + $after_initialize = false + class Foo < Rails::Railtie ; config.after_initialize { $after_initialize = true } ; end + assert !$after_initialize + require "#{app_path}/config/environment" + assert $after_initialize + end + + test "rake_tasks block is executed when MyApp.load_tasks is called" do + $ran_block = false + + class MyTie < Rails::Railtie + rake_tasks do + $ran_block = true + end + end + + require "#{app_path}/config/environment" + + assert !$ran_block + require 'rake' + require 'rake/testtask' + require 'rake/rdoctask' + + AppTemplate::Application.load_tasks + assert $ran_block + end + + test "generators block is executed when MyApp.load_generators is called" do + $ran_block = false + + class MyTie < Rails::Railtie + generators do + $ran_block = true + end + end + + require "#{app_path}/config/environment" + + assert !$ran_block + AppTemplate::Application.load_generators + assert $ran_block + end + + test "railtie can add initializers" do + $ran_block = false + + class MyTie < Rails::Railtie + initializer :something_nice do + $ran_block = true + end + end + + assert !$ran_block + require "#{app_path}/config/environment" + assert $ran_block + end + end +end diff --git a/railties/test/railties/shared_tests.rb b/railties/test/railties/shared_tests.rb index 2483fa47fd..d51a0d153c 100644 --- a/railties/test/railties/shared_tests.rb +++ b/railties/test/railties/shared_tests.rb @@ -116,6 +116,15 @@ module RailtiesTest assert_equal "Hello bukkits\n", response[2].body end + def test_plugin_eager_load_any_path_under_app + @plugin.write "app/anything/foo.rb", <<-RUBY + module Foo; end + RUBY + + boot_rails + assert Foo + end + def test_routes_are_added_to_router @plugin.write "config/routes.rb", <<-RUBY class Sprokkit |