Skip to content
This repository
Browse code

Merge pull request #5821 from Deradon/fix-engine-tasks

Provided fix for calling rake tasks within mountable engines
  • Loading branch information...
commit 4f77f956a8458c611c58975fb54094dea05a83e3 2 parents 7a3e43c + 0e49ef4
Piotr Sarnacki authored May 03, 2012
7  railties/lib/rails/engine.rb
@@ -608,7 +608,12 @@ def load_seed
608 608
           desc "Copy migrations from #{railtie_name} to application"
609 609
           task :migrations do
610 610
             ENV["FROM"] = railtie_name
611  
-            Rake::Task["railties:install:migrations"].invoke
  611
+            if Rake::Task.task_defined?("railties:install:migrations")
  612
+              Rake::Task["railties:install:migrations"].invoke
  613
+            else
  614
+              Rake::Task["app:railties:install:migrations"].invoke
  615
+            end
  616
+
612 617
           end
613 618
         end
614 619
       end
31  railties/test/railties/engine_test.rb
@@ -111,6 +111,37 @@ def up
111 111
       end
112 112
     end
113 113
 
  114
+    test "mountable engine should copy migrations within engine_path" do
  115
+      @plugin.write "lib/bukkits.rb", <<-RUBY
  116
+        module Bukkits
  117
+          class Engine < ::Rails::Engine
  118
+            isolate_namespace Bukkits
  119
+          end
  120
+        end
  121
+      RUBY
  122
+
  123
+      @plugin.write "db/migrate/0_add_first_name_to_users.rb", <<-RUBY
  124
+        class AddFirstNameToUsers < ActiveRecord::Migration
  125
+        end
  126
+      RUBY
  127
+
  128
+      @plugin.write "Rakefile", <<-RUBY
  129
+        APP_RAKEFILE = '#{app_path}/Rakefile'
  130
+        load 'rails/tasks/engine.rake'
  131
+      RUBY
  132
+
  133
+      add_to_config "ActiveRecord::Base.timestamped_migrations = false"
  134
+
  135
+      boot_rails
  136
+
  137
+      Dir.chdir(@plugin.path) do
  138
+        output = `bundle exec rake app:bukkits:install:migrations`
  139
+        assert File.exists?("#{app_path}/db/migrate/0_add_first_name_to_users.bukkits.rb")
  140
+        assert_match(/Copied migration 0_add_first_name_to_users.bukkits.rb from bukkits/, output)
  141
+        assert_equal 1, Dir["#{app_path}/db/migrate/*.rb"].length
  142
+      end
  143
+    end
  144
+
114 145
     test "no rake task without migrations" do
115 146
       boot_rails
116 147
       require 'rake'

0 notes on commit 4f77f95

Please sign in to comment.
Something went wrong with that request. Please try again.