annotate .svn/pristine/1e/1e6be947d792b95e6881bfbd4ea45738a1aaae9e.svn-base @ 1628:9c5f8e24dadc live tip

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