-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New configuration option config.plugin_paths which may be a single pa…
…th like the default 'vendor/plugins' or an array of paths: ['vendor/plugins', 'lib/plugins']. Plugins are discovered in nested paths, so you can organize your plugins directory as you like. Refactor load_plugin from load_plugins. Simplify initializer unit test. Closes #2757. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2904 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
- Loading branch information
Showing
7 changed files
with
186 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
SET_FROM_ENV = "success" | ||
$initialize_test_set_from_env = "success" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'stubby_mixin' | ||
raise unless defined? StubbyMixin |
2 changes: 2 additions & 0 deletions
2
railties/test/fixtures/plugins/default/stubby/lib/stubby_mixin.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module StubbyMixin | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |