TODO - subclass this out to handle different versions of rails Also… this is the nastiest duck punch ever. Clean this up.
# File lib/spork/app_framework/rails.rb, line 6
6: def self.included(klass)
7: klass.class_eval do
8: unless method_defined?(:load_environment_without_spork)
9: alias :load_environment_without_spork :load_environment
10: alias :load_environment :load_environment_with_spork
11: end
12:
13: def self.run_with_spork(*args, &block) # it's all fun and games until someone gets an eye poked out
14: if ENV['RAILS_ENV']
15: Object.send(:remove_const, :RAILS_ENV)
16: Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
17: end
18: run_without_spork(*args, &block)
19: end
20:
21: class << self
22: unless method_defined?(:run_without_spork)
23: alias :run_without_spork :run
24: alias :run :run_with_spork
25: end
26: end
27: end
28: end
# File lib/spork/app_framework/rails.rb, line 13
13: def self.run_with_spork(*args, &block) # it's all fun and games until someone gets an eye poked out
14: if ENV['RAILS_ENV']
15: Object.send(:remove_const, :RAILS_ENV)
16: Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
17: end
18: run_without_spork(*args, &block)
19: end
# File lib/spork/app_framework/rails.rb, line 81
81: def auto_reestablish_db_connection
82: if Object.const_defined?(:ActiveRecord)
83: Spork.each_run do
84: # rails lib/test_help.rb is very aggressive about overriding RAILS_ENV and will switch it back to test after the cucumber env was loaded
85: reset_rails_env
86: ActiveRecord::Base.establish_connection
87: end
88: end
89: end
# File lib/spork/app_framework/rails.rb, line 61
61: def delay_app_preload
62: if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:load_application_classes)
63: Spork.trap_method(::Rails::Initializer, :load_application_classes)
64: end
65: end
# File lib/spork/app_framework/rails.rb, line 67
67: def delay_application_controller_loading
68: if application_controller_source = ["#{Dir.pwd}/app/controllers/application.rb", "#{Dir.pwd}/app/controllers/application_controller.rb"].find { |f| File.exist?(f) }
69: application_helper_source = "#{Dir.pwd}/app/helpers/application_helper.rb"
70: load_paths = (::ActiveSupport.const_defined?(:Dependencies) ? ::ActiveSupport::Dependencies : ::Dependencies).load_paths
71: load_paths.unshift(File.expand_path('rails_stub_files', File.dirname(__FILE__)))
72: Spork.each_run do
73: require application_controller_source
74: require application_helper_source if File.exist?(application_helper_source)
75: # update the rails magic to refresh the module
76: ApplicationController.send(:helper, ApplicationHelper)
77: end
78: end
79: end
# File lib/spork/app_framework/rails.rb, line 97
97: def delay_eager_view_loading
98: # So, in testing mode it seems it would be optimal to not eager load
99: # views (as your may only run a test that uses one or two views).
100: # However, I decided to delay eager loading rather than force it to
101: # disable because you may wish to eager load your views (I.E. you're
102: # testing concurrency)
103:
104: # Rails 2.3.x +
105: if defined?(::ActionView::Template::EagerPath)
106: Spork.trap_method(::ActionView::Template::EagerPath, :load!)
107: end
108: # Rails 2.2.x
109: if defined?(::ActionView::PathSet::Path)
110: Spork.trap_method(::ActionView::PathSet::Path, :load)
111: end
112: # Rails 2.0.5 - 2.1.x don't appear to eager cache views.
113: end
# File lib/spork/app_framework/rails.rb, line 51
51: def delay_observer_loading
52: if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:load_observers)
53: Spork.trap_method(::Rails::Initializer, :load_observers)
54: end
55: if Object.const_defined?(:ActionController)
56: require "action_controller/dispatcher.rb"
57: Spork.trap_class_method(::ActionController::Dispatcher, :define_dispatcher_callbacks) if ActionController::Dispatcher.respond_to?(:define_dispatcher_callbacks)
58: end
59: end
# File lib/spork/app_framework/rails.rb, line 91
91: def delay_route_loading
92: if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:initialize_routing)
93: Spork.trap_method(::Rails::Initializer, :initialize_routing)
94: end
95: end
# File lib/spork/app_framework/rails.rb, line 36
36: def install_hooks
37: auto_reestablish_db_connection
38: delay_observer_loading
39: delay_app_preload
40: delay_application_controller_loading
41: delay_route_loading
42: delay_eager_view_loading
43: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.