Chris@909: # Tests in this file ensure that: Chris@909: # Chris@909: # * the application /app/[controllers|helpers|models] and /lib Chris@909: # paths preceed the corresponding plugin paths Chris@909: # * the plugin paths are added to $LOAD_PATH in the order in which plugins are Chris@909: # loaded Chris@909: Chris@909: require File.dirname(__FILE__) + '/../test_helper' Chris@909: Chris@909: class LoadPathTest < Test::Unit::TestCase Chris@909: def setup Chris@909: @load_path = expand_paths($LOAD_PATH) Chris@909: end Chris@909: Chris@909: # Not sure if these test actually make sense as this now essentially tests Chris@909: # Rails core functionality. On the other hand Engines relies on this to some Chris@909: # extend so this will choke if something important changes in Rails. Chris@909: Chris@909: # the application app/... and lib/ directories should appear Chris@909: # before any plugin directories Chris@909: Chris@909: def test_application_app_libs_should_precede_all_plugin_app_libs Chris@909: types = %w(app/controllers app/helpers app/models lib) Chris@909: types.each do |t| Chris@909: app_index = load_path_index(File.join(RAILS_ROOT, t)) Chris@909: assert_not_nil app_index, "#{t} is missing in $LOAD_PATH" Chris@909: Engines.plugins.each do |plugin| Chris@909: first_plugin_index = load_path_index(File.join(plugin.directory, t)) Chris@909: assert(app_index < first_plugin_index) unless first_plugin_index.nil? Chris@909: end Chris@909: end Chris@909: end Chris@909: Chris@909: # the engine directories should appear in the proper order based on Chris@909: # the order they were started Chris@909: Chris@909: def test_plugin_dirs_should_appear_in_reverse_plugin_loading_order Chris@909: app_paths = %w(app/controllers/ app app/models app/helpers lib) Chris@909: app_paths.map { |p| File.join(RAILS_ROOT, p)} Chris@909: plugin_paths = Engines.plugins.reverse.collect { |plugin| plugin.load_paths.reverse }.flatten Chris@909: Chris@909: expected_paths = expand_paths(app_paths + plugin_paths) Chris@909: # only look at those paths that are also present in expected_paths so Chris@909: # the only difference would be in the order of the paths Chris@909: actual_paths = @load_path & expected_paths Chris@909: Chris@909: assert_equal expected_paths, actual_paths Chris@909: end Chris@909: Chris@909: protected Chris@909: def expand_paths(paths) Chris@909: paths.collect { |p| File.expand_path(p) } Chris@909: end Chris@909: Chris@909: def load_path_index(dir) Chris@909: @load_path.index(File.expand_path(dir)) Chris@909: end Chris@909: end