diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/initializer/path_test.rb | 1 | ||||
-rw-r--r-- | railties/test/railties/configuration_test.rb (renamed from railties/test/plugins/configuration_test.rb) | 2 | ||||
-rw-r--r-- | railties/test/railties/framework_extension_test.rb (renamed from railties/test/plugins/framework_extension_test.rb) | 2 | ||||
-rw-r--r-- | railties/test/railties/plugin_ordering_test.rb | 72 | ||||
-rw-r--r-- | railties/test/railties/plugin_test.rb (renamed from railties/test/plugins/vendored_test.rb) | 77 |
5 files changed, 103 insertions, 51 deletions
diff --git a/railties/test/initializer/path_test.rb b/railties/test/initializer/path_test.rb index 7a40d7fa6e..2048dc57bb 100644 --- a/railties/test/initializer/path_test.rb +++ b/railties/test/initializer/path_test.rb @@ -37,6 +37,7 @@ module InitializerTests 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" diff --git a/railties/test/plugins/configuration_test.rb b/railties/test/railties/configuration_test.rb index c59040c712..c5ff6dad9c 100644 --- a/railties/test/plugins/configuration_test.rb +++ b/railties/test/railties/configuration_test.rb @@ -1,6 +1,6 @@ require "isolation/abstract_unit" -module PluginsTest +module RailtiesTest class ConfigurationTest < Test::Unit::TestCase def setup build_app diff --git a/railties/test/plugins/framework_extension_test.rb b/railties/test/railties/framework_extension_test.rb index d57fd4e635..84bd6ed16b 100644 --- a/railties/test/plugins/framework_extension_test.rb +++ b/railties/test/railties/framework_extension_test.rb @@ -1,6 +1,6 @@ require "isolation/abstract_unit" -module PluginsTest +module RailtiesTest class FrameworkExtensionTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation diff --git a/railties/test/railties/plugin_ordering_test.rb b/railties/test/railties/plugin_ordering_test.rb new file mode 100644 index 0000000000..f6ca493fdf --- /dev/null +++ b/railties/test/railties/plugin_ordering_test.rb @@ -0,0 +1,72 @@ +require "isolation/abstract_unit" + +module RailtiesTest + class PluginOrderingTest < Test::Unit::TestCase + include ActiveSupport::Testing::Isolation + + def setup + build_app + $arr = [] + plugin "a_plugin", "$arr << :a" + plugin "b_plugin", "$arr << :b" + plugin "c_plugin", "$arr << :c" + end + + def boot_rails + super + require "#{app_path}/config/environment" + end + + test "plugins are loaded alphabetically by default" do + boot_rails + assert_equal [:a, :b, :c], $arr + end + + test "if specified, only those plugins are loaded" do + add_to_config "config.plugins = [:b_plugin]" + boot_rails + assert_equal [:b], $arr + end + + test "the plugins are initialized in the order they are specified" do + add_to_config "config.plugins = [:b_plugin, :a_plugin]" + boot_rails + assert_equal [:b, :a], $arr + end + + test "if :all is specified, the remaining plugins are loaded in alphabetical order" do + add_to_config "config.plugins = [:c_plugin, :all]" + boot_rails + assert_equal [:c, :a, :b], $arr + end + + test "if :all is at the beginning, it represents the plugins not otherwise specified" do + add_to_config "config.plugins = [:all, :b_plugin]" + boot_rails + assert_equal [:a, :c, :b], $arr + end + + test "plugin order array is strings" do + add_to_config "config.plugins = %w( c_plugin all )" + boot_rails + assert_equal [:c, :a, :b], $arr + end + + test "can require lib file from a different plugin" do + plugin "foo", "require 'bar'" do |plugin| + plugin.write "lib/foo.rb", "$foo = true" + end + + plugin "bar", "require 'foo'" do |plugin| + plugin.write "lib/bar.rb", "$bar = true" + end + + add_to_config "config.plugins = [:foo, :bar]" + + boot_rails + + assert $foo + assert $bar + end + end +end
\ No newline at end of file diff --git a/railties/test/plugins/vendored_test.rb b/railties/test/railties/plugin_test.rb index 05c01846e1..65d057383c 100644 --- a/railties/test/plugins/vendored_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -1,7 +1,7 @@ require "isolation/abstract_unit" -module PluginsTest - class VendoredTest < Test::Unit::TestCase +module RailtiesTest + class PluginTest < Test::Unit::TestCase include ActiveSupport::Testing::Isolation def setup @@ -37,6 +37,20 @@ module PluginsTest assert_equal "Bukkits", Bukkits.name end + test "plugin init is ran before application initializers" do + plugin "foo", "$foo = true" do |plugin| + plugin.write "lib/foo.rb", "module Foo; end" + end + + app_file 'config/initializers/foo.rb', <<-RUBY + raise "no $foo" unless $foo + raise "no Foo" unless Foo + RUBY + + boot_rails + assert $foo + end + test "plugin paths get added to the AS::Dependency list" do boot_rails assert_equal "Bukkits", Bukkits.name @@ -299,57 +313,22 @@ YAML assert rescued, "Expected boot rails to fail" end - end - - class VendoredOrderingTest < Test::Unit::TestCase - include ActiveSupport::Testing::Isolation - - def setup - build_app - $arr = [] - plugin "a_plugin", "$arr << :a" - plugin "b_plugin", "$arr << :b" - plugin "c_plugin", "$arr << :c" - end - - def boot_rails - super - require "#{app_path}/config/environment" - end - test "plugins are loaded alphabetically by default" do - boot_rails - assert_equal [:a, :b, :c], $arr - end - - test "if specified, only those plugins are loaded" do - add_to_config "config.plugins = [:b_plugin]" - boot_rails - assert_equal [:b], $arr - end - - test "the plugins are initialized in the order they are specified" do - add_to_config "config.plugins = [:b_plugin, :a_plugin]" - boot_rails - assert_equal [:b, :a], $arr - end - - test "if :all is specified, the remaining plugins are loaded in alphabetical order" do - add_to_config "config.plugins = [:c_plugin, :all]" - boot_rails - assert_equal [:c, :a, :b], $arr - end + test "use plugin middleware in application config" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + def initialize(app) + @app = app + end - test "if :all is at the beginning, it represents the plugins not otherwise specified" do - add_to_config "config.plugins = [:all, :b_plugin]" - boot_rails - assert_equal [:a, :c, :b], $arr - end + def call(env) + @app.call(env) + end + end + RUBY - test "plugin order array is strings" do - add_to_config "config.plugins = %w( c_plugin all )" + add_to_config "config.middleware.use \"Bukkits\"" boot_rails - assert_equal [:c, :a, :b], $arr end end end |