Skip to content

Commit

Permalink
temporary fix for db:migrate:all rake task which broke with rake 0.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Fuchs committed Sep 20, 2008
1 parent 3e491c7 commit 556d894
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
46 changes: 23 additions & 23 deletions vendor/plugins/engines/Rakefile
Expand Up @@ -28,13 +28,13 @@ task :cruise do
puts "Running all tests in test harness"
['db:migrate', 'test', 'test:plugins'].each do |t|
Rake::Task[t].invoke
end
end
end

task :clean => [:clobber_doc, "test:clean"]

namespace :test do

# Yields a block with STDOUT and STDERR silenced. If you *really* want
# to output something, the block is yielded with the original output
# streams, i.e.
Expand All @@ -50,39 +50,39 @@ namespace :test do
streams = [STDOUT, STDERR]
actual_stdout = STDOUT.dup
actual_stderr = STDERR.dup
streams.each do |s|
s.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
streams.each do |s|
s.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
s.sync = true
end
yield actual_stdout, actual_stderr
ensure
STDOUT.reopen(actual_stdout)
STDERR.reopen(actual_stderr)
end

def test_app_dir
File.join(File.dirname(__FILE__), 'test_app')
end

def run(cmd)
system(cmd) || raise("failed running '#{cmd}'")
end

desc 'Remove the test application'
task :clean do
FileUtils.rm_r(test_app_dir) if File.exist?(test_app_dir)
end

desc 'Build the test rails application (use RAILS=[edge,<directory>] to test against specific version)'
task :generate_app do
silence do |out, err|

out.puts "> Creating test application at #{test_app_dir}"

if ENV['RAILS']
vendor_dir = File.join(test_app_dir, 'vendor')
FileUtils.mkdir_p vendor_dir

if ENV['RAILS'] == 'edge'
out.puts " Cloning rails from GitHub"
run "cd #{vendor_dir} && git clone --depth 1 git://github.com/rails/rails.git"
Expand All @@ -92,26 +92,26 @@ namespace :test do
else
raise "Couldn't build test application from '#{ENV['RAILS']}'"
end

out.puts " generating rails default directory structure"
run "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
else
version = `rails --version`.chomp.split.last
out.puts " building rails using the 'rails' command (rails version: #{version})"
run "rails #{test_app_dir}"
end

# get the database config and schema in place
out.puts " writing database.yml"
require 'yaml'
File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
f.write(%w(development test).inject({}) do |h, env|
f.write(%w(development test).inject({}) do |h, env|
h[env] = {"adapter" => "sqlite3", "database" => "engines_#{env}.sqlite3"} ; h
end.to_yaml)
end
end
end

# We can't link the plugin, as it needs to be present for script/generate to find
# the plugin generator.
# TODO: find and +1/create issue for loading generators from symlinked plugins
Expand All @@ -125,13 +125,13 @@ namespace :test do
FileUtils.cp_r(file, engines_plugin)
end
end

def insert_line(line, options)
line = line + "\n"
target_file = File.join(test_app_dir, options[:into])
lines = File.readlines(target_file)
return if lines.include?(line)

if options[:after]
if options[:after].is_a?(String)
after_line = options[:after] + "\n"
Expand All @@ -147,32 +147,32 @@ namespace :test do
end
File.open(target_file, 'w') { |f| f.write lines.join }
end

def mirror_test_files(src, dest=nil)
destination_dir = File.join(*([test_app_dir, dest].compact))
FileUtils.cp_r(File.join(File.dirname(__FILE__), 'test', src), destination_dir)
end

desc 'Update the plugin and tests files in the test application from the plugin'
task :mirror_engine_files => [:test_app, :copy_engines_plugin] do
puts "> Modifying default config files to load engines plugin"
insert_line("require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')",
:into => 'config/environment.rb',
:after => "require File.join(File.dirname(__FILE__), 'boot')")
insert_line('map.from_plugin :test_routing', :into => 'config/routes.rb',

insert_line('map.from_plugin :test_routing', :into => 'config/routes.rb',
:after => /\AActionController::Routing::Routes/)

insert_line("require 'engines_test_helper'", :into => 'test/test_helper.rb')

puts "> Mirroring test application files into #{test_app_dir}"
mirror_test_files('app')
mirror_test_files('lib')
mirror_test_files('plugins', 'vendor')
mirror_test_files('unit', 'test')
mirror_test_files('functional', 'test')
end

desc 'Prepare the engines test environment'
file :test_app do
puts "> Recreating test application"
Expand Down
38 changes: 19 additions & 19 deletions vendor/plugins/engines/tasks/engines.rake
Expand Up @@ -5,7 +5,7 @@
unless Rake::TaskManager.methods.include?(:redefine_task)
module Rake
module TaskManager

def redefine_task(task_class, args, &block)
task_name, deps = resolve_args([args])
task_name = task_class.scope_name(@scope, task_name)
Expand All @@ -18,7 +18,7 @@ unless Rake::TaskManager.methods.include?(:redefine_task)
task.enhance(deps, &block)
task
end

end
class Task
class << self
Expand All @@ -34,9 +34,9 @@ namespace :db do
namespace :migrate do
desc 'Migrate database and plugins to current status.'
task :all => [ 'db:migrate', 'db:migrate:plugins' ]

desc 'Migrate plugins to current status.'
task({:plugins => :environment}, :version) do |task, args|
task({:plugins => :environment}) do |task, args|
version = args[:version] || ENV['VERSION']
Engines.plugins.each do |plugin|
next unless File.exists? plugin.migration_directory
Expand All @@ -46,7 +46,7 @@ namespace :db do
end

desc 'Migrate a specified plugin.'
task({:plugin => :environment}, :name, :version) do |task, args|
task({:plugin => :environment}) do |task, args|
name = args[:name] || ENV['NAME']
if plugin = Engines.plugins[name]
version = args[:version] || ENV['VERSION']
Expand All @@ -55,30 +55,30 @@ namespace :db do
else
puts "Plugin #{name} does not exist."
end
end
end
end
end


namespace :db do
namespace :db do
namespace :fixtures do
namespace :plugins do

desc "Load plugin fixtures into the current environment's database."
task :load => :environment do
require 'active_record/fixtures'
ActiveRecord::Base.establish_connection(RAILS_ENV.to_sym)
Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', ENV['PLUGIN'] || '**',
Dir.glob(File.join(RAILS_ROOT, 'vendor', 'plugins', ENV['PLUGIN'] || '**',
'test', 'fixtures', '*.yml')).each do |fixture_file|
Fixtures.create_fixtures(File.dirname(fixture_file), File.basename(fixture_file, '.*'))
end
end

end
end
end

# this is just a modification of the original task in railties/lib/tasks/documentation.rake,
# this is just a modification of the original task in railties/lib/tasks/documentation.rake,
# because the default task doesn't support subdirectories like <plugin>/app or
# <plugin>/component. These tasks now include every file under a plugin's code paths (see
# Plugin#code_paths).
Expand All @@ -105,7 +105,7 @@ namespace :doc do
files.include("#{plugin_base}/{#{Engines.plugins[plugin].code_paths.join(",")}}/**/*.rb")
end
if File.exists?("#{plugin_base}/README")
files.include("#{plugin_base}/README")
files.include("#{plugin_base}/README")
options << "--main '#{plugin_base}/README'"
end
files.include("#{plugin_base}/CHANGELOG") if File.exists?("#{plugin_base}/CHANGELOG")
Expand Down Expand Up @@ -144,25 +144,25 @@ Report any issues on http://dev.rails-engines.org. Thanks!
-~===============( ... as you were ... )============================~-}
end

namespace :plugins do

desc "Run the plugin tests in vendor/plugins/**/test (or specify with PLUGIN=name)"
task :all => [:warn_about_multiple_plugin_testing_with_engines,
task :all => [:warn_about_multiple_plugin_testing_with_engines,
:units, :functionals, :integration]

desc "Run all plugin unit tests"
Rake::TestTask.new(:units => :setup_plugin_fixtures) do |t|
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/unit/**/*_test.rb"
t.verbose = true
end

desc "Run all plugin functional tests"
Rake::TestTask.new(:functionals => :setup_plugin_fixtures) do |t|
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/functional/**/*_test.rb"
t.verbose = true
end

desc "Integration test engines"
Rake::TestTask.new(:integration => :setup_plugin_fixtures) do |t|
t.pattern = "vendor/plugins/#{ENV['PLUGIN'] || "**"}/test/integration/**/*_test.rb"
Expand All @@ -173,8 +173,8 @@ Report any issues on http://dev.rails-engines.org. Thanks!
task :setup_plugin_fixtures => :environment do
Engines::Testing.setup_plugin_fixtures
end

# Patch the default plugin testing task to have setup_plugin_fixtures as a prerequisite
Rake::Task["test:plugins"].prerequisites << "test:plugins:setup_plugin_fixtures"
end
end
end

0 comments on commit 556d894

Please sign in to comment.