To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / .svn / pristine / 1e / 1e6be947d792b95e6881bfbd4ea45738a1aaae9e.svn-base @ 1297:0a574315af3e
History | View | Annotate | Download (2.07 KB)
| 1 |
# Tests in this file ensure that: |
|---|---|
| 2 |
# |
| 3 |
# * the application /app/[controllers|helpers|models] and /lib |
| 4 |
# paths preceed the corresponding plugin paths |
| 5 |
# * the plugin paths are added to $LOAD_PATH in the order in which plugins are |
| 6 |
# loaded |
| 7 |
|
| 8 |
require File.dirname(__FILE__) + '/../test_helper' |
| 9 |
|
| 10 |
class LoadPathTest < Test::Unit::TestCase |
| 11 |
def setup |
| 12 |
@load_path = expand_paths($LOAD_PATH) |
| 13 |
end |
| 14 |
|
| 15 |
# Not sure if these test actually make sense as this now essentially tests |
| 16 |
# Rails core functionality. On the other hand Engines relies on this to some |
| 17 |
# extend so this will choke if something important changes in Rails. |
| 18 |
|
| 19 |
# the application app/... and lib/ directories should appear |
| 20 |
# before any plugin directories |
| 21 |
|
| 22 |
def test_application_app_libs_should_precede_all_plugin_app_libs |
| 23 |
types = %w(app/controllers app/helpers app/models lib) |
| 24 |
types.each do |t| |
| 25 |
app_index = load_path_index(File.join(RAILS_ROOT, t)) |
| 26 |
assert_not_nil app_index, "#{t} is missing in $LOAD_PATH"
|
| 27 |
Engines.plugins.each do |plugin| |
| 28 |
first_plugin_index = load_path_index(File.join(plugin.directory, t)) |
| 29 |
assert(app_index < first_plugin_index) unless first_plugin_index.nil? |
| 30 |
end |
| 31 |
end |
| 32 |
end |
| 33 |
|
| 34 |
# the engine directories should appear in the proper order based on |
| 35 |
# the order they were started |
| 36 |
|
| 37 |
def test_plugin_dirs_should_appear_in_reverse_plugin_loading_order |
| 38 |
app_paths = %w(app/controllers/ app app/models app/helpers lib) |
| 39 |
app_paths.map { |p| File.join(RAILS_ROOT, p)}
|
| 40 |
plugin_paths = Engines.plugins.reverse.collect { |plugin| plugin.load_paths.reverse }.flatten
|
| 41 |
|
| 42 |
expected_paths = expand_paths(app_paths + plugin_paths) |
| 43 |
# only look at those paths that are also present in expected_paths so |
| 44 |
# the only difference would be in the order of the paths |
| 45 |
actual_paths = @load_path & expected_paths |
| 46 |
|
| 47 |
assert_equal expected_paths, actual_paths |
| 48 |
end |
| 49 |
|
| 50 |
protected |
| 51 |
def expand_paths(paths) |
| 52 |
paths.collect { |p| File.expand_path(p) }
|
| 53 |
end |
| 54 |
|
| 55 |
def load_path_index(dir) |
| 56 |
@load_path.index(File.expand_path(dir)) |
| 57 |
end |
| 58 |
end |