diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-12-04 17:12:57 +0100 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-12-09 01:59:54 +0100 |
commit | 5df72a238e9fcb18daf6ab6e6dc9051c9106d7bb (patch) | |
tree | 6b94712c8b82f77bf663f0ffa429a8197ca98b0c /railties/lib | |
parent | 2dc3342f75577fa521d9d0c54260da75450126a2 (diff) | |
download | rails-5df72a238e9fcb18daf6ab6e6dc9051c9106d7bb.tar.gz rails-5df72a238e9fcb18daf6ab6e6dc9051c9106d7bb.tar.bz2 rails-5df72a238e9fcb18daf6ab6e6dc9051c9106d7bb.zip |
Rake tasks for managing database while development and testing of engines
Some of the engines needs database. As engine needs to be run inside
Rails application, migrations and other database operations are run
from dummy application. To make that process simple I changed db
tasks to look for migrations in both engine's and application's
db/migrate directory. You can run all of the database tasks from
test/dummy or directly from engine with prefix app, like:
rake app:db:migrate
rake app:db:migrate:redo
Diffstat (limited to 'railties/lib')
3 files changed, 22 insertions, 5 deletions
diff --git a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb index 9c54b98238..77497f9e44 100644 --- a/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb +++ b/railties/lib/rails/generators/rails/plugin_new/plugin_new_generator.rb @@ -70,6 +70,16 @@ task :default => :test if mountable? template "rails/routes.rb", "#{dummy_path}/config/routes.rb", :force => true end + + if full? && !options[:skip_active_record] + append_file "#{dummy_path}/Rakefile", <<-EOF + +task :"db:load_config" do + ActiveRecord::Migrator.migrations_paths = Rails.application.config.paths["db/migrate"].to_a + + <%= camelized %>::Engine.config.paths["db/migrate"].to_a +end + EOF + end end def test_dummy_clean diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile index 12350309bf..b7cab3859a 100755 --- a/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile +++ b/railties/lib/rails/generators/rails/plugin_new/templates/Rakefile @@ -14,3 +14,15 @@ Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.rdoc_files.include('README.rdoc') rdoc.rdoc_files.include('lib/**/*.rb') end + +<% if full? && !options[:skip_active_record] -%> +namespace :app do + load File.expand_path("../<%= dummy_path -%>/Rakefile", __FILE__) + + task :"db:load_config" do + ActiveRecord::Migrator.migrations_paths = Rails.application.config.paths["db/migrate"].to_a + + <%= camelized %>::Engine.config.paths["db/migrate"].to_a + end +end +<% end -%> + diff --git a/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb b/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb index 7b61047e77..791b901593 100644 --- a/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb +++ b/railties/lib/rails/generators/rails/plugin_new/templates/test/test_helper.rb @@ -6,10 +6,5 @@ require "rails/test_help" Rails.backtrace_cleaner.remove_silencers! -<% if full? && !options[:skip_active_record] -%> -# Run any available migration from application -ActiveRecord::Migrator.migrate File.expand_path("../dummy/db/migrate/", __FILE__) -<% end -%> - # Load support files Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } |