Skip to content
This repository
Browse code

Add config.to_prepare back and add tests for it.

Signed-off-by: Carl Lerche <carllerche@mac.com>
  • Loading branch information...
commit d3d487479a6d4a5ba6977fb0075e7937eb19718a 1 parent 226d8e7
José Valim authored January 27, 2010 Carl Lerche committed January 28, 2010
8  railties/lib/rails/application/finisher.rb
@@ -15,6 +15,12 @@ module Finisher
15 15
         end
16 16
       end
17 17
 
  18
+      initializer :add_to_prepare_blocks do
  19
+        config.to_prepare_blocks.each do |block|
  20
+          ActionDispatch::Callbacks.to_prepare(&block)
  21
+        end
  22
+      end
  23
+
18 24
       initializer :add_builtin_route do |app|
19 25
         if Rails.env.development?
20 26
           app.routes_reloader.paths << File.join(RAILTIES_PATH, 'builtin', 'routes.rb')
@@ -25,7 +31,7 @@ module Finisher
25 31
         app
26 32
       end
27 33
 
28  
-      # Fires the user-supplied after_initialize block (config#after_initialize)
  34
+      # Fires the user-supplied after_initialize block (config.after_initialize)
29 35
       initializer :after_initialize do
30 36
         config.after_initialize_blocks.each do |block|
31 37
           block.call(self)
8  railties/lib/rails/configuration.rb
@@ -52,6 +52,14 @@ def after_initialize(&blk)
52 52
         after_initialize_blocks << blk if blk
53 53
       end
54 54
 
  55
+      def to_prepare_blocks
  56
+        @@to_prepare_blocks ||= []
  57
+      end
  58
+
  59
+      def to_prepare(&blk)
  60
+        to_prepare_blocks << blk if blk
  61
+      end
  62
+
55 63
       def respond_to?(name)
56 64
         super || name.to_s =~ config_key_regexp
57 65
       end
23  railties/test/application/configuration_test.rb
@@ -12,6 +12,10 @@ def copy_app
12 12
       FileUtils.cp_r(app_path, new_app)
13 13
     end
14 14
 
  15
+    def app
  16
+      @app ||= Rails.application
  17
+    end
  18
+
15 19
     def setup
16 20
       FileUtils.rm_rf(new_app) if File.directory?(new_app)
17 21
       build_app
@@ -132,5 +136,24 @@ def setup
132 136
         require "#{app_path}/config/application"
133 137
       end
134 138
     end
  139
+
  140
+    test "config.to_prepare is forwarded to ActionDispatch" do
  141
+      $prepared = false
  142
+
  143
+      add_to_config <<-RUBY
  144
+        config.to_prepare do
  145
+          $prepared = true
  146
+        end
  147
+      RUBY
  148
+
  149
+      assert !$prepared
  150
+
  151
+      require "#{app_path}/config/environment"
  152
+      require 'rack/test'
  153
+      extend Rack::Test::Methods
  154
+
  155
+      get "/"
  156
+      assert $prepared
  157
+    end
135 158
   end
136 159
 end

0 notes on commit d3d4874

Please sign in to comment.
Something went wrong with that request. Please try again.