Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9743: require-frameworks.diff

File require-frameworks.diff, 3.2 kB (added by mislav, 1 year ago)
  • lib/initializer.rb

    old new  
    152152    # ActionPack, ActionMailer, and ActiveResource) are loaded. 
    153153    def require_frameworks 
    154154      configuration.frameworks.each { |framework| require(framework.to_s) } 
     155    rescue LoadError => e 
     156      # re-raise because Mongrel would swallow it 
     157      raise e.to_s 
    155158    end 
    156159 
    157160    # Add the load paths used by support functions such as the info controller 
     
    545548    end 
    546549 
    547550    def framework_paths 
    548       # TODO: Don't include dirs for frameworks that are not used 
    549       %w( 
    550         railties 
    551         railties/lib 
    552         actionpack/lib 
    553         activesupport/lib 
    554         activerecord/lib 
    555         activeresource/lib 
    556         actionmailer/lib 
    557       ).map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } 
     551      paths = %w(railties railties/lib activesupport/lib) 
     552      paths << 'actionpack/lib' if frameworks.include? :action_controller or frameworks.include? :action_view 
     553       
     554      [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| 
     555        paths << "#{framework.to_s.gsub('_', '')}/lib" if frameworks.include? framework 
     556      end 
     557       
     558      paths.map { |dir| "#{framework_root_path}/#{dir}" }.select { |dir| File.directory?(dir) } 
    558559    end 
    559560 
    560561    private 
  • test/initializer_test.rb

    old new  
    8282  end 
    8383 
    8484end 
     85 
     86uses_mocha 'framework paths' do 
     87  class ConfigurationFrameworkPathsTests < Test::Unit::TestCase 
     88    def setup 
     89      @config = Rails::Configuration.new 
     90      @config.frameworks.clear 
     91       
     92      File.stubs(:directory?).returns(true) 
     93      @config.stubs(:framework_root_path).returns('') 
     94    end 
     95 
     96    def test_minimal 
     97      expected = %w( 
     98        /railties 
     99        /railties/lib 
     100        /activesupport/lib 
     101      ) 
     102      assert_equal expected, @config.framework_paths 
     103    end 
     104 
     105    def test_actioncontroller_or_actionview_add_actionpack 
     106      @config.frameworks << :action_controller 
     107      assert_framework_path '/actionpack/lib' 
     108       
     109      @config.frameworks = [:action_view] 
     110      assert_framework_path '/actionpack/lib' 
     111    end 
     112 
     113    def test_paths_for_ar_ares_and_mailer 
     114      [:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework| 
     115        @config.frameworks = [framework] 
     116        assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib" 
     117      end 
     118    end 
     119 
     120    def test_unknown_framework_raises_error 
     121      @config.frameworks << :action_foo 
     122      initializer = Rails::Initializer.new @config 
     123      initializer.expects(:require).raises(LoadError) 
     124 
     125      assert_raise RuntimeError do 
     126        initializer.send :require_frameworks 
     127      end 
     128    end 
     129 
     130    protected 
     131 
     132      def assert_framework_path(path) 
     133        assert @config.framework_paths.include?(path), 
     134          "<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>" 
     135      end 
     136  end 
     137end