Permalink
Browse files

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

  • Loading branch information...
1 parent d94aa10 commit ee8a37c7347b9d57d9cb8d7e2073abea176098d2 @josevalim josevalim committed Oct 2, 2011
View
2 actionpack/lib/sprockets/railtie.rb
@@ -13,7 +13,7 @@ class Railtie < ::Rails::Railtie
load "sprockets/assets.rake"
end
- initializer "sprockets.environment", :group => :assets do |app|
+ initializer "sprockets.environment", :group => :all do |app|
config = app.config
next unless config.assets.enabled
View
2 railties/lib/rails/application.rb
@@ -91,7 +91,7 @@ def routes_reloader
@routes_reloader ||= RoutesReloader.new
end
- def initialize!(group=nil)
+ def initialize!(group=:default)
raise "Application has been already initialized." if @initialized
run_initializers(group, self)
@initialized = true
View
2 railties/lib/rails/engine.rb
@@ -539,7 +539,7 @@ def load_seed
require environment if environment
end
- initializer :append_assets_path, :group => :assets do |app|
+ initializer :append_assets_path, :group => :all do |app|
app.config.assets.paths.unshift(*paths["vendor/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["lib/assets"].existent_directories)
app.config.assets.paths.unshift(*paths["app/assets"].existent_directories)
View
5 railties/lib/rails/initializable.rb
@@ -10,6 +10,7 @@ class Initializer
attr_reader :name, :block
def initialize(name, context, options, &block)
+ options[:group] ||= :default
@name, @context, @options, @block = name, context, options, block
end
@@ -48,10 +49,10 @@ def +(other)
end
end
- def run_initializers(group=nil, *args)
+ def run_initializers(group=:default, *args)
return if instance_variable_defined?(:@ran)
initializers.tsort.each do |initializer|
- initializer.run(*args) if group.nil? || initializer.belongs_to?(group)
+ initializer.run(*args) if initializer.belongs_to?(group)
end
@ran = true
end
View
4 railties/test/initializable_test.rb
@@ -209,7 +209,7 @@ class InstanceTest < ActiveSupport::TestCase
$arr = []
instance = Instance.new
instance.run_initializers
- assert_equal [1, 2, 3, 4], $arr
+ assert_equal [2, 3, 4], $arr
end
test "running locals with groups" do
@@ -223,7 +223,7 @@ class InstanceTest < ActiveSupport::TestCase
class WithArgsTest < ActiveSupport::TestCase
test "running initializers with args" do
$with_arg = nil
- WithArgs.new.run_initializers(nil, 'foo')
+ WithArgs.new.run_initializers(:default, 'foo')
assert_equal 'foo', $with_arg
end
end

0 comments on commit ee8a37c

Please sign in to comment.