diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-07-18 23:23:54 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:04 +0200 |
commit | 7cccfed5943cddd6d72ed0df0ee7291cca9025ad (patch) | |
tree | 5750097c50f8359a4a83ffce97e41d60d9d87af6 /railties | |
parent | 15f95b98ac048407a1ce6873bb02fc5fbb6c991c (diff) | |
download | rails-7cccfed5943cddd6d72ed0df0ee7291cca9025ad.tar.gz rails-7cccfed5943cddd6d72ed0df0ee7291cca9025ad.tar.bz2 rails-7cccfed5943cddd6d72ed0df0ee7291cca9025ad.zip |
Allow Engines loading its own environment file from config/environments
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/application.rb | 4 | ||||
-rw-r--r-- | railties/lib/rails/application/bootstrap.rb | 7 | ||||
-rw-r--r-- | railties/lib/rails/application/configuration.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/engine.rb | 9 | ||||
-rw-r--r-- | railties/lib/rails/engine/configuration.rb | 1 | ||||
-rw-r--r-- | railties/test/application/loading_test.rb | 17 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 29 |
7 files changed, 50 insertions, 18 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 72e5be2b9a..cbb1aad68f 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -43,10 +43,6 @@ module Rails class << self private :new - def configure(&block) - class_eval(&block) - end - def instance if self == Rails::Application if Rails.application diff --git a/railties/lib/rails/application/bootstrap.rb b/railties/lib/rails/application/bootstrap.rb index 44e26b5713..e39b3bc705 100644 --- a/railties/lib/rails/application/bootstrap.rb +++ b/railties/lib/rails/application/bootstrap.rb @@ -6,10 +6,7 @@ module Rails 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 Rails end end end -end
\ No newline at end of file +end diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a20208f8d5..c248d41e59 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -48,7 +48,6 @@ module Rails 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" diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb index a602dac5ff..efde82d1ed 100644 --- a/railties/lib/rails/engine.rb +++ b/railties/lib/rails/engine.rb @@ -129,6 +129,10 @@ module Rails @endpoint end + def configure(&block) + class_eval(&block) + end + protected def method_missing(*args, &block) @@ -249,6 +253,11 @@ module Rails # 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 diff --git a/railties/lib/rails/engine/configuration.rb b/railties/lib/rails/engine/configuration.rb index 06e7222753..bf3ad1f26b 100644 --- a/railties/lib/rails/engine/configuration.rb +++ b/railties/lib/rails/engine/configuration.rb @@ -28,6 +28,7 @@ module Rails 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" diff --git a/railties/test/application/loading_test.rb b/railties/test/application/loading_test.rb index ecf7904c39..7ea712d27a 100644 --- a/railties/test/application/loading_test.rb +++ b/railties/test/application/loading_test.rb @@ -42,6 +42,23 @@ class LoadingTest < Test::Unit::TestCase 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 diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 980265d969..09f2b5baa0 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -54,15 +54,9 @@ module RailtiesTest 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 @@ module RailtiesTest 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 |