diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/fixtures/environment_with_constant.rb | 2 | ||||
-rw-r--r-- | railties/test/fixtures/plugins/default/stubby/init.rb | 2 | ||||
-rw-r--r-- | railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb | 2 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 21 | ||||
-rw-r--r-- | railties/test/plugin_test.rb | 72 |
5 files changed, 86 insertions, 13 deletions
diff --git a/railties/test/fixtures/environment_with_constant.rb b/railties/test/fixtures/environment_with_constant.rb index 96efe9c23a..1c7120655e 100644 --- a/railties/test/fixtures/environment_with_constant.rb +++ b/railties/test/fixtures/environment_with_constant.rb @@ -1 +1 @@ -SET_FROM_ENV = "success"
\ No newline at end of file +$initialize_test_set_from_env = "success" diff --git a/railties/test/fixtures/plugins/default/stubby/init.rb b/railties/test/fixtures/plugins/default/stubby/init.rb new file mode 100644 index 0000000000..fc9470fd97 --- /dev/null +++ b/railties/test/fixtures/plugins/default/stubby/init.rb @@ -0,0 +1,2 @@ +require 'stubby_mixin' +raise unless defined? StubbyMixin diff --git a/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb b/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb new file mode 100644 index 0000000000..2d569e5002 --- /dev/null +++ b/railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb @@ -0,0 +1,2 @@ +module StubbyMixin +end diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index 4c25ad8a0a..86f7569c50 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -15,22 +15,19 @@ class InitializerTest < Test::Unit::TestCase def environment_path @envpath end - end - def setup - Object.const_set(:RAILS_ROOT, "") rescue nil - end - - def teardown - Object.remove_const(:RAILS_ROOT) rescue nil + protected + def root_path + File.dirname(__FILE__) + end end - + def test_load_environment_with_constant config = ConfigurationMock.new("#{File.dirname(__FILE__)}/fixtures/environment_with_constant.rb") + assert_nil $initialize_test_set_from_env Rails::Initializer.run(:load_environment, config) - assert Object.const_defined?(:SET_FROM_ENV) - assert_equal "success", SET_FROM_ENV + assert_equal "success", $initialize_test_set_from_env ensure - Object.remove_const(:SET_FROM_ENV) rescue nil + $initialize_test_set_from_env = nil end -end
\ No newline at end of file +end diff --git a/railties/test/plugin_test.rb b/railties/test/plugin_test.rb new file mode 100644 index 0000000000..54eea13538 --- /dev/null +++ b/railties/test/plugin_test.rb @@ -0,0 +1,72 @@ +$:.unshift File.dirname(__FILE__) + "/../lib" +$:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" + +require 'test/unit' +require 'active_support' +require 'initializer' + +class PluginTest < Test::Unit::TestCase + class TestConfig < Rails::Configuration + protected + def root_path + File.dirname(__FILE__) + end + end + + def setup + @init = Rails::Initializer.new(TestConfig.new) + end + + def test_plugin_path? + assert @init.send(:plugin_path?, "#{File.dirname(__FILE__)}/fixtures/plugins/default/stubby") + assert !@init.send(:plugin_path?, "#{File.dirname(__FILE__)}/fixtures/plugins/default/empty") + assert !@init.send(:plugin_path?, "#{File.dirname(__FILE__)}/fixtures/plugins/default/jalskdjflkas") + end + + def test_find_plugins + base = "#{File.dirname(__FILE__)}/fixtures/plugins" + default = "#{base}/default" + alt = "#{base}/alternate" + acts = "#{default}/acts" + assert_equal ["#{acts}/acts_as_chunky_bacon"], @init.send(:find_plugins, acts) + assert_equal ["#{acts}/acts_as_chunky_bacon", "#{default}/stubby"], @init.send(:find_plugins, default).sort + assert_equal ["#{alt}/a", "#{acts}/acts_as_chunky_bacon", "#{default}/stubby"], @init.send(:find_plugins, base).sort + end + + def test_load_plugin + stubby = "#{File.dirname(__FILE__)}/fixtures/plugins/default/stubby" + expected = Set.new(['stubby']) + + assert @init.send(:load_plugin, stubby) + assert_equal expected, @init.loaded_plugins + + assert !@init.send(:load_plugin, stubby) + assert_equal expected, @init.loaded_plugins + + assert_raise(LoadError) { @init.send(:load_plugin, 'lakjsdfkasljdf') } + assert_equal expected, @init.loaded_plugins + end + + def test_load_default_plugins + assert_loaded_plugins %w(stubby acts_as_chunky_bacon), 'default' + end + + def test_load_alternate_plugins + assert_loaded_plugins %w(a), 'alternate' + end + + def test_load_plugins_from_two_sources + assert_loaded_plugins %w(a stubby acts_as_chunky_bacon), ['default', 'alternate'] + end + + protected + def assert_loaded_plugins(plugins, path) + assert_equal Set.new(plugins), load_plugins(path) + end + + def load_plugins(*paths) + @init.configuration.plugin_paths = paths.flatten.map { |p| "#{File.dirname(__FILE__)}/fixtures/plugins/#{p}" } + @init.load_plugins + @init.loaded_plugins + end +end |