Class: LoadPathTest

Inherits:
Test::Unit::TestCase
  • Object
show all
Defined in:
vendor/plugins/engines/test/unit/load_path_test.rb

Instance Method Summary

Instance Method Details

- (Object) expand_paths(paths)



51
52
53
# File 'vendor/plugins/engines/test/unit/load_path_test.rb', line 51

def expand_paths(paths)
  paths.collect { |p| File.expand_path(p) }
end

- (Object) load_path_index(dir)



55
56
57
# File 'vendor/plugins/engines/test/unit/load_path_test.rb', line 55

def load_path_index(dir)
  @load_path.index(File.expand_path(dir))
end

- (Object) setup



11
12
13
# File 'vendor/plugins/engines/test/unit/load_path_test.rb', line 11

def setup
  @load_path = expand_paths($LOAD_PATH)
end

- (Object) test_application_app_libs_should_precede_all_plugin_app_libs

the application app/… and lib/ directories should appear before any plugin directories



22
23
24
25
26
27
28
29
30
31
32
# File 'vendor/plugins/engines/test/unit/load_path_test.rb', line 22

def test_application_app_libs_should_precede_all_plugin_app_libs
  types = %w(app/controllers app/helpers app/models lib)
  types.each do |t|
    app_index = load_path_index(File.join(RAILS_ROOT, t))
    assert_not_nil app_index, "#{t} is missing in $LOAD_PATH"
    Engines.plugins.each do |plugin|
      first_plugin_index = load_path_index(File.join(plugin.directory, t))
      assert(app_index < first_plugin_index) unless first_plugin_index.nil?
    end
  end
end

- (Object) test_plugin_dirs_should_appear_in_reverse_plugin_loading_order

the engine directories should appear in the proper order based on the order they were started



37
38
39
40
41
42
43
44
45
46
47
48
# File 'vendor/plugins/engines/test/unit/load_path_test.rb', line 37

def test_plugin_dirs_should_appear_in_reverse_plugin_loading_order
  app_paths = %w(app/controllers/ app app/models app/helpers lib)
  app_paths.map { |p| File.join(RAILS_ROOT, p)}
  plugin_paths = Engines.plugins.reverse.collect { |plugin| plugin.load_paths.reverse }.flatten    
  
  expected_paths = expand_paths(app_paths + plugin_paths)    
  # only look at those paths that are also present in expected_paths so
  # the only difference would be in the order of the paths
  actual_paths = @load_path & expected_paths 
  
  assert_equal expected_paths, actual_paths
end