diff options
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/initializable_test.rb | 26 | ||||
-rw-r--r-- | railties/test/application/initializer_test.rb | 25 | ||||
-rw-r--r-- | railties/test/application/plugins_test.rb | 90 |
3 files changed, 115 insertions, 26 deletions
diff --git a/railties/test/application/initializable_test.rb b/railties/test/application/initializable_test.rb deleted file mode 100644 index 38eaec63c0..0000000000 --- a/railties/test/application/initializable_test.rb +++ /dev/null @@ -1,26 +0,0 @@ -require "isolation/abstract_unit" - -module ApplicationTests - class InitializerTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - boot_rails - end - - test "initializers only ever run once" do - class MyApp < Rails::Application - initializer :counter do - $counter += 1 - end - end - - $counter = 0 - MyApp.initializers[:counter].run - MyApp.initializers[:counter].run - - assert_equal 1, $counter - end - end -end
\ No newline at end of file diff --git a/railties/test/application/initializer_test.rb b/railties/test/application/initializer_test.rb index 9583e1606c..1b6af718c0 100644 --- a/railties/test/application/initializer_test.rb +++ b/railties/test/application/initializer_test.rb @@ -29,5 +29,30 @@ module ApplicationTests MyApp.new assert $:.include?("#{app_path}/app/models") end + + test "adding an unknown framework raises an error" do + class MyApp < Rails::Application + config.frameworks << :action_foo + end + + assert_raises RuntimeError do + MyApp.new + end + 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 + + Rails::Initializer.run do |config| + config.eager_load_paths = "#{app_path}/lib" + end + + assert Zoo + end end end
\ No newline at end of file diff --git a/railties/test/application/plugins_test.rb b/railties/test/application/plugins_test.rb new file mode 100644 index 0000000000..2a433ea016 --- /dev/null +++ b/railties/test/application/plugins_test.rb @@ -0,0 +1,90 @@ +require "isolation/abstract_unit" + +module ApplicationTests + class PluginTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def assert_plugins(list_of_names, array_of_plugins, message=nil) + assert_equal list_of_names.map { |n| n.to_s }, array_of_plugins.map { |p| p.name }, message + end + + def setup + build_app + boot_rails + @failure_tip = "It's likely someone has added a new plugin fixture without updating this list" + # Tmp hax to get tests working + FileUtils.cp_r "#{File.dirname(__FILE__)}/../fixtures/plugins", "#{app_path}/vendor" + end + + test "all plugins are loaded when registered plugin list is untouched" do + Rails::Initializer.run { } + assert_plugins [ + :a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby + ], Rails.application.config.loaded_plugins, @failure_tip + end + + test "all plugins loaded after all" do + Rails::Initializer.run do |config| + config.plugins = [:stubby, :all, :acts_as_chunky_bacon] + end + assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], Rails.application.config.loaded_plugins, @failure_tip + end + + test "plugin names may be strings" do + plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + Rails::Initializer.run do |config| + config.plugins = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir] + end + + assert_plugins plugin_names, Rails.application.config.loaded_plugins, @failure_tip + end + + test "all plugins loaded when all is used" do + Rails::Initializer.run do |config| + config.plugins = [:stubby, :acts_as_chunky_bacon, :all] + end + + assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], Rails.application.config.loaded_plugins, @failure_tip + end + + test "all loaded plugins are added to the load paths" do + Rails::Initializer.run do |config| + config.plugins = [:stubby, :acts_as_chunky_bacon] + end + + assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/stubby/lib") + assert $LOAD_PATH.include?("#{app_path}/vendor/plugins/default/acts/acts_as_chunky_bacon/lib") + end + + test "registering a plugin name that does not exist raises a load error" do + assert_raise(LoadError) do + Rails::Initializer.run do |config| + config.plugins = [:stubby, :acts_as_a_non_existant_plugin] + end + end + end + + test "load error messages mention missing plugins and no others" do + valid_plugins = [:stubby, :acts_as_chunky_bacon] + invalid_plugins = [:non_existant_plugin1, :non_existant_plugin2] + + begin + Rails::Initializer.run do |config| + config.plugins = [:stubby, :acts_as_chunky_bacon, :non_existant_plugin1, :non_existant_plugin2] + end + flunk "Expected a LoadError but did not get one" + rescue LoadError => e + assert_plugins valid_plugins, Rails.application.config.loaded_plugins, @failure_tip + + invalid_plugins.each do |plugin| + assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'") + end + + valid_plugins.each do |plugin| + assert_no_match(/#{plugin.to_s}/, e.message, "LoadError message should not mention '#{plugin}'") + end + end + end + + end +end
\ No newline at end of file |