diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-03 16:28:33 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-03 16:28:33 -0300 |
commit | 66c9d31c2b9a58db03668fb0840669e4d4374123 (patch) | |
tree | b63d6d914e6d2ec25551949e88a03960abbde7b7 | |
parent | 0942100ce1128235b1bbc06120b7409c9e77c79b (diff) | |
parent | 435e8d719cadb045cf7b194e2aafa766a67cd4bf (diff) | |
download | rails-66c9d31c2b9a58db03668fb0840669e4d4374123.tar.gz rails-66c9d31c2b9a58db03668fb0840669e4d4374123.tar.bz2 rails-66c9d31c2b9a58db03668fb0840669e4d4374123.zip |
Merge pull request #16756 from huoxito/dont-mess-railties-default-order
Dont mess with default order engines load (4.1.6.rc1 regression)
-rw-r--r-- | railties/lib/rails/application.rb | 17 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 36 |
2 files changed, 45 insertions, 8 deletions
diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index 6a4660bad0..67d5bac700 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -414,8 +414,14 @@ module Rails end end + # Return an array of railties respecting the order they're loaded + # and the order specified by the +railties_order+ config. + # + # While when running initializers we need engines in reverse + # order here when copying migrations from railties we need then in the same + # order as given by +railties_order+ def migration_railties # :nodoc: - (ordered_railties & railties_without_main_app).reverse + ordered_railties.flatten - [self] end protected @@ -448,11 +454,6 @@ module Rails super end - def railties_without_main_app # :nodoc: - @railties_without_main_app ||= Rails::Railtie.subclasses.map(&:instance) + - Rails::Engine.subclasses.map(&:instance) - end - # Returns the ordered railties for this application considering railties_order. def ordered_railties #:nodoc: @ordered_railties ||= begin @@ -472,13 +473,13 @@ module Rails index = order.index(:all) order[index] = all - order.reverse.flatten + order end end def railties_initializers(current) #:nodoc: initializers = [] - ordered_railties.each do |r| + ordered_railties.reverse.flatten.each do |r| if r == self initializers += current else diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index ec64ce5941..1976466229 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -144,6 +144,42 @@ module RailtiesTest end end + test "dont reverse default railties order" do + @api = engine "api" do |plugin| + plugin.write "lib/api.rb", <<-RUBY + module Api + class Engine < ::Rails::Engine; end + end + RUBY + end + + # added last but here is loaded before api engine + @core = engine "core" do |plugin| + plugin.write "lib/core.rb", <<-RUBY + module Core + class Engine < ::Rails::Engine; end + end + RUBY + end + + @core.write "db/migrate/1_create_users.rb", <<-RUBY + class CreateUsers < ActiveRecord::Migration; end + RUBY + + @api.write "db/migrate/2_create_keys.rb", <<-RUBY + class CreateKeys < ActiveRecord::Migration; end + RUBY + + boot_rails + + Dir.chdir(app_path) do + output = `bundle exec rake railties:install:migrations`.split("\n") + + assert_match(/Copied migration \d+_create_users.core_engine.rb from core_engine/, output.first) + assert_match(/Copied migration \d+_create_keys.api_engine.rb from api_engine/, output.last) + end + end + test "mountable engine should copy migrations within engine_path" do @plugin.write "lib/bukkits.rb", <<-RUBY module Bukkits |