Permalink
Browse files

Allow Engines loading its own environment file from config/environments

  • Loading branch information...
1 parent 15f95b9 commit 7cccfed5943cddd6d72ed0df0ee7291cca9025ad @drogus drogus committed Jul 18, 2010
@@ -43,10 +43,6 @@ class Application < Engine
class << self
private :new
- def configure(&block)
- class_eval(&block)
- end
-
def instance
if self == Rails::Application
if Rails.application
@@ -6,10 +6,7 @@ class Application
module Bootstrap
include Initializable
- initializer :load_environment_config do
- environment = config.paths.config.environments.to_a.first
- require environment if environment
- end
+ initializer :load_environment_hook do end
initializer :load_active_support do
require 'active_support/dependencies'
@@ -73,4 +70,4 @@ module Bootstrap
end
end
end
-end
+end
@@ -48,7 +48,6 @@ def paths
paths.app.controllers << builtin_controller if builtin_controller
paths.config.database "config/database.yml"
paths.config.environment "config/environment.rb"
- paths.config.environments "config/environments", :glob => "#{Rails.env}.rb"
paths.lib.templates "lib/templates"
paths.log "log/#{Rails.env}.log"
paths.tmp "tmp"
@@ -129,6 +129,10 @@ def endpoint(endpoint = nil)
@endpoint
end
+ def configure(&block)
+ class_eval(&block)
+ end
+
protected
def method_missing(*args, &block)
@@ -249,6 +253,11 @@ def initializers
# consistently executed after all the initializers above across all engines.
end
+ initializer :load_environment_config, :before => :load_environment_hook do
+ environment = config.paths.config.environments.to_a.first
+ require environment if environment
+ end
+
protected
def default_middleware_stack
ActionDispatch::MiddlewareStack.new
@@ -28,6 +28,7 @@ def paths
paths.config.initializers "config/initializers", :glob => "**/*.rb"
paths.config.locales "config/locales", :glob => "*.{rb,yml}"
paths.config.routes "config/routes.rb"
+ paths.config.environments "config/environments", :glob => "#{Rails.env}.rb"
paths.public "public"
paths.public.javascripts "public/javascripts"
paths.public.stylesheets "public/stylesheets"
@@ -42,6 +42,23 @@ class User < ActiveRecord::Base
User
end
+ test "load config/environments/environment before Bootstrap initializers" do
+ app_file "config/environments/development.rb", <<-RUBY
+ AppTemplate::Application.configure do
+ config.development_environment_loaded = true
+ end
+ RUBY
+
+ add_to_config <<-RUBY
+ config.before_initialize do
+ config.loaded = config.development_environment_loaded
+ end
+ RUBY
+
+ require "#{app_path}/config/environment"
+ assert ::AppTemplate::Application.config.loaded
+ end
+
def test_descendants_are_cleaned_on_each_request_without_cache_classes
add_to_config <<-RUBY
config.cache_classes = false
@@ -54,15 +54,9 @@ class Engine < ::Rails::Engine
initializers = Rails.application.initializers.tsort
index = initializers.index { |i| i.name == "dummy_initializer" }
- selection = initializers[(index-3)..(index)].map(&:name).map(&:to_s)
-
- assert_equal %w(
- load_config_initializers
- load_config_initializers
- engines_blank_point
- dummy_initializer
- ), selection
+ assert index > initializers.index { |i| i.name == :load_config_initializers }
+ assert index > initializers.index { |i| i.name == :engines_blank_point }
assert index < initializers.index { |i| i.name == :build_middleware_stack }
end
@@ -164,5 +158,24 @@ class Engine < ::Rails::Engine
assert !Bukkits::Engine.config.respond_to?(:engine_yaffle_loaded)
assert Rails.application.config.app_yaffle_loaded
end
+
+ test "it loads its environment file" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ class Bukkits
+ class Engine < ::Rails::Engine
+ end
+ end
+ RUBY
+
+ @plugin.write "config/environments/development.rb", <<-RUBY
+ Bukkits::Engine.configure do
+ config.environment_loaded = true
+ end
+ RUBY
+
+ boot_rails
+
+ assert Bukkits::Engine.config.environment_loaded
+ end
end
end

0 comments on commit 7cccfed

Please sign in to comment.