Skip to content
This repository
Browse code

:group => :assets should only run in the assets environment.

  • Loading branch information...
commit ee8a37c7347b9d57d9cb8d7e2073abea176098d2 1 parent d94aa10
José Valim authored October 02, 2011
2  actionpack/lib/sprockets/railtie.rb
@@ -13,7 +13,7 @@ class Railtie < ::Rails::Railtie
13 13
       load "sprockets/assets.rake"
14 14
     end
15 15
 
16  
-    initializer "sprockets.environment", :group => :assets do |app|
  16
+    initializer "sprockets.environment", :group => :all do |app|
17 17
       config = app.config
18 18
       next unless config.assets.enabled
19 19
 
2  railties/lib/rails/application.rb
@@ -91,7 +91,7 @@ def routes_reloader
91 91
       @routes_reloader ||= RoutesReloader.new
92 92
     end
93 93
 
94  
-    def initialize!(group=nil)
  94
+    def initialize!(group=:default)
95 95
       raise "Application has been already initialized." if @initialized
96 96
       run_initializers(group, self)
97 97
       @initialized = true
2  railties/lib/rails/engine.rb
@@ -539,7 +539,7 @@ def load_seed
539 539
       require environment if environment
540 540
     end
541 541
 
542  
-    initializer :append_assets_path, :group => :assets do |app|
  542
+    initializer :append_assets_path, :group => :all do |app|
543 543
       app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
544 544
       app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
545 545
       app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
5  railties/lib/rails/initializable.rb
@@ -10,6 +10,7 @@ class Initializer
10 10
       attr_reader :name, :block
11 11
 
12 12
       def initialize(name, context, options, &block)
  13
+        options[:group] ||= :default
13 14
         @name, @context, @options, @block = name, context, options, block
14 15
       end
15 16
 
@@ -48,10 +49,10 @@ def +(other)
48 49
       end
49 50
     end
50 51
 
51  
-    def run_initializers(group=nil, *args)
  52
+    def run_initializers(group=:default, *args)
52 53
       return if instance_variable_defined?(:@ran)
53 54
       initializers.tsort.each do |initializer|
54  
-        initializer.run(*args) if group.nil? || initializer.belongs_to?(group)
  55
+        initializer.run(*args) if initializer.belongs_to?(group)
55 56
       end
56 57
       @ran = true
57 58
     end
4  railties/test/initializable_test.rb
@@ -209,7 +209,7 @@ class InstanceTest < ActiveSupport::TestCase
209 209
       $arr = []
210 210
       instance = Instance.new
211 211
       instance.run_initializers
212  
-      assert_equal [1, 2, 3, 4], $arr
  212
+      assert_equal [2, 3, 4], $arr
213 213
     end
214 214
 
215 215
     test "running locals with groups" do
@@ -223,7 +223,7 @@ class InstanceTest < ActiveSupport::TestCase
223 223
   class WithArgsTest < ActiveSupport::TestCase
224 224
     test "running initializers with args" do
225 225
       $with_arg = nil
226  
-      WithArgs.new.run_initializers(nil, 'foo')
  226
+      WithArgs.new.run_initializers(:default, 'foo')
227 227
       assert_equal 'foo', $with_arg
228 228
     end
229 229
   end

0 notes on commit ee8a37c

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