Changeset 258

Show
Ignore:
Timestamp:
01/31/06 03:54:44 (3 years ago)
Author:
lazyatom
Message:

More reworking...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • applications/engines_test/test/unit/load_path_test.rb

    r256 r258  
    33class LoadPathTest < Test::Unit::TestCase 
    44   
     5  def setup 
     6    @load_path = $LOAD_PATH.collect { |p| File.expand_path(p) } 
     7  end 
     8   
     9  def load_path_index(dir) 
     10    @load_path.index(File.expand_path(dir)) 
     11  end 
     12   
    513  def test_application_lib_path_comes_before_all_engine_libs 
    6     app_lib_index = $LOAD_PATH.index(File.join(RAILS_ROOT, 'lib')) 
     14    app_lib_index = load_path_index(File.join(RAILS_ROOT, 'lib')) 
    715    Engines.active.each { |e| 
    8       engine_index = $LOAD_PATH.index(File.join(e.root, 'lib')) 
     16      engine_index = load_path_index(File.join(e.root, 'lib')) 
    917      assert app_lib_index < engine_index 
    1018    } 
     
    1624    types = ['app/controllers', 'app/helpers', 'app/models', 'components'] 
    1725    types.each do |t| 
    18       app_index = $LOAD_PATH.index(File.join(RAILS_ROOT, t)) 
     26      app_index = load_path_index(File.join(RAILS_ROOT, t)) 
    1927      Engines.active.each do |e| 
    20         engine_index = $LOAD_PATH.index(File.join(e.root, t)) 
     28        engine_index = load_path_index(File.join(e.root, t)) 
    2129        if !engine_index.nil? 
    2230          assert app_index < engine_index 
     
    2836  # the engine directories should appear in the proper order based on 
    2937  # the order they were started 
    30   def test_application_app_libs_come_before_all_engine_app_lib
     38  def test_application_app_dirs_come_before_all_engine_app_dir
    3139    engine_indexes = {} 
    3240    types = ['app/controllers', 'app/helpers', 'app/models', 'components'] 
     
    3442      engine_indexes[e] = [] 
    3543      types.each do |t| 
    36         engine_indexes[e] << $LOAD_PATH.index(File.join(e.root, t)) 
     44        index = load_path_index(File.join(e.root, t)) 
     45        engine_indexes[e] << index if !index.nil? 
    3746      end 
    3847    end 
     48 
     49    # get the indexes, in order, of each engine with app dir paths in $LOAD_PATH 
     50    active_engines_with_paths = [] 
     51    Engines.active.length.times do |i| 
     52      active_engines_with_paths << i if !engine_indexes[Engines.active[i]].empty? 
     53    end 
    3954     
    40     puts engine_indexes.inspect 
    41      
    42     Engines.active.length.times do |i| 
    43       puts "i: #{i} of #{Engines.active.length}" 
     55    active_engines_with_paths.each do |i| 
    4456      engine = Engines.active[i] 
    45       puts "#{engine}" 
    4657      next_engine = Engines.active[i+1] 
    47       if !next_engine.nil? 
     58      if !next_engine.nil? && # if there is a next engine 
     59        !engine_indexes[engine].empty? && # if there were any paths for 
     60        !engine_indexes[next_engine].empty? 
    4861        assert engine_indexes[engine].max < engine_indexes[next_engine].min 
    4962      end 
    5063    end 
    51      
    5264  end 
    5365 
  • applications/engines_test/test/unit/model_and_lib_test.rb

    r256 r258  
    33class ModelAndLibTest < Test::Unit::TestCase 
    44   
     5  # The Account model is only present in the alpha engine 
    56  def test_loading_model_from_engine 
    67    assert_not_nil Account.new 
     
    89  end 
    910   
    10   # this is a 'negative' test - it would be great if models didn't behave 
    11   # like this 
     11  # Banjo model is present in both the alpha and beta engines, but 
     12  # since the beta engine has higher precidence, it will be loaded rather 
     13  # than the alpha version 
    1214  def test_model_loads_from_last_active_engine 
    1315    assert_not_nil Banjo.new 
     
    1618  end 
    1719   
     20  # The Clown model is present in the application and the alpha engine, 
     21  # but since the application should take precidence over ANY engine, 
     22  # the application version will be loaded 
    1823  def test_model_loads_from_application_rather_than_engine 
    1924    assert_not_nil Clown.new 
     
    2227  end 
    2328   
     29  # The Apple class is only present in the alpha engine, and it should 
     30  # be loaded from that successfully. 
    2431  def test_loading_class_from_engine_lib 
    2532    assert_not_nil Apple.new 
    2633  end 
    2734   
     35  # The Banana class is present in the application and the alpha engine, 
     36  # so it should be loaded from the application 
    2837  def test_loading_lib_from_application_rather_than_engine 
    2938    assert_not_nil Banana.new