annotate vendor/plugins/engines/test/unit/load_path_test.rb @ 929:5f33065ddc4b redmine-1.3

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