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