aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-05-03 22:47:29 -0700
committerPiotr Sarnacki <drogus@gmail.com>2012-05-03 22:47:29 -0700
commit4f77f956a8458c611c58975fb54094dea05a83e3 (patch)
treec178eecdd9db047970c58dc36c65655e02ee7a77 /railties
parent7a3e43cc58a2d5d00d3e9fa8c9ab5583ffa5cf00 (diff)
parent0e49ef433093c0ed08c7df8609b0b9e3dae5150c (diff)
downloadrails-4f77f956a8458c611c58975fb54094dea05a83e3.tar.gz
rails-4f77f956a8458c611c58975fb54094dea05a83e3.tar.bz2
rails-4f77f956a8458c611c58975fb54094dea05a83e3.zip
Merge pull request #5821 from Deradon/fix-engine-tasks
Provided fix for calling rake tasks within mountable engines
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/engine.rb7
-rw-r--r--railties/test/railties/engine_test.rb31
2 files changed, 37 insertions, 1 deletions
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index c9654fc63d..9bf9cbe022 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -608,7 +608,12 @@ module Rails
desc "Copy migrations from #{railtie_name} to application"
task :migrations do
ENV["FROM"] = railtie_name
- Rake::Task["railties:install:migrations"].invoke
+ if Rake::Task.task_defined?("railties:install:migrations")
+ Rake::Task["railties:install:migrations"].invoke
+ else
+ Rake::Task["app:railties:install:migrations"].invoke
+ end
+
end
end
end
diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb
index 9d9565e5f3..9a6b2b66ca 100644
--- a/railties/test/railties/engine_test.rb
+++ b/railties/test/railties/engine_test.rb
@@ -111,6 +111,37 @@ module RailtiesTest
end
end
+ test "mountable engine should copy migrations within engine_path" do
+ @plugin.write "lib/bukkits.rb", <<-RUBY
+ module Bukkits
+ class Engine < ::Rails::Engine
+ isolate_namespace Bukkits
+ end
+ end
+ RUBY
+
+ @plugin.write "db/migrate/0_add_first_name_to_users.rb", <<-RUBY
+ class AddFirstNameToUsers < ActiveRecord::Migration
+ end
+ RUBY
+
+ @plugin.write "Rakefile", <<-RUBY
+ APP_RAKEFILE = '#{app_path}/Rakefile'
+ load 'rails/tasks/engine.rake'
+ RUBY
+
+ add_to_config "ActiveRecord::Base.timestamped_migrations = false"
+
+ boot_rails
+
+ Dir.chdir(@plugin.path) do
+ output = `bundle exec rake app:bukkits:install:migrations`
+ assert File.exists?("#{app_path}/db/migrate/0_add_first_name_to_users.bukkits.rb")
+ assert_match(/Copied migration 0_add_first_name_to_users.bukkits.rb from bukkits/, output)
+ assert_equal 1, Dir["#{app_path}/db/migrate/*.rb"].length
+ end
+ end
+
test "no rake task without migrations" do
boot_rails
require 'rake'