0
@@ -36,75 +36,129 @@ namespace :test do
0
File.join(File.dirname(__FILE__), 'test_app')
0
- def mirror_test_files(src, dest=nil)
0
- destination_dir = File.join(*([test_app_dir, dest].compact))
0
- FileUtils.cp_r(File.join(File.dirname(__FILE__), 'test', src), destination_dir)
0
+ FileUtils.rm_r(test_app_dir) if File.exist?(test_app_dir)
0
- def append_engines_test_helper
0
- File.open(File.join(test_app_dir, *%w[test test_helper.rb]), 'a') do |f|
0
- f.puts "require 'engines_test_helper'"
0
+ # vendor_dir = File.join(test_app_dir, 'vendor')
0
+ # FileUtils.mkdir_p vendor_dir
0
+ # system "cd #{vendor_dir} && git clone --depth 1 git://github.com/rails/rails.git"
0
+ # system "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
+ # system "rails #{test_app_dir}"
0
+ # offline fix for getting rails
0
+ vendor_dir = File.join(test_app_dir, 'vendor')
0
+ FileUtils.mkdir_p vendor_dir
0
+ system "cd #{vendor_dir} && ln -s /Users/james/Code/rails/git/rails rails"
0
+ system "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
+ # get the database config and schema in place
0
+ File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
+ "development" => {"adapter" => "sqlite3", "database" => "engines_development.sqlite3"},
0
+ "test" => {"adapter" => "sqlite3", "database" => "engines_test.sqlite3"}
0
+ FileUtils.cp(File.join(File.dirname(__FILE__), *%w[test schema.rb]),
0
+ File.join(test_app_dir, 'db'))
0
- def link_engines_plugin
0
- system "ln -s #{File.expand_path(File.dirname(__FILE__))} #{test_app_dir}/vendor/plugins/engines"
0
- def insert_engines_boot_loader_line
0
- environment_rb_file = File.join(test_app_dir, 'config', 'environment.rb')
0
- environment_rb_lines = File.readlines(environment_rb_file)
0
- first_initializer_line = environment_rb_lines.find { |line| line =~ /\ARails::Initializer/ }
0
- index = environment_rb_lines.index(first_initializer_line)
0
- environment_rb_lines.insert(index, "require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')\n")
0
- File.open(environment_rb_file, 'w') { |f| f.write environment_rb_lines.join("\n") }
0
- def create_database_yml
0
- File.open(File.join(test_app_dir, 'config', 'database.yml'), 'w') do |f|
0
- database: engines_development.sqlite3
0
- database: engines_test.sqlite3
0
+ # We can't link the plugin, as it needs to be present for script/generate to find
0
+ # the plugin generator.
0
+ # TODO: find and +1/create issue for loading generators from symlinked plugins
0
+ desc 'Mirror the engines plugin into the test application'
0
+ task :copy_engines_plugin do
0
+ engines_plugin = File.join(test_app_dir, "vendor", "plugins", "engines")
0
+ FileUtils.rm_r(engines_plugin) if File.exist?(engines_plugin)
0
+ FileUtils.mkdir_p(engines_plugin)
0
+ FileList["*"].exclude("test_app").each do |file|
0
+ FileUtils.cp_r(file, engines_plugin)
0
- FileUtils.rm_r(test_app_dir) if File.exist?(test_app_dir)
0
+ # desc 'Ensure helper methods used by the engines plugin test suite are available'
0
+ # task :append_engines_test_helper do
0
+ # engines_test_helper_line = "require 'engines_test_helper'"
0
+ # test_helper_rb = File.join(test_app_dir, "test", "test_helper.rb")
0
+ # test_helper_lines = File.readlines(test_helper_rb)
0
+ # return if test_helper_lines.include?(engines_test_helper_line)
0
+ # test_helper_lines << engines_test_helper_line
0
+ # File.open(test_helper_rb, 'w') { |f| f.write test_helper_lines }
0
+ # desc 'Add the engines bootstrap line to the environment.rb file if it is missing'
0
+ # task :insert_engines_boot_loader_line do
0
+ # engines_boot_line = "require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')"
0
+ # environment_rb_file = File.join(test_app_dir, 'config', 'environment.rb')
0
+ # environment_rb_lines = File.readlines(environment_rb_file)
0
+ # return if environment_rb_lines.include?(engines_boot_line)
0
+ # first_initializer_line = environment_rb_lines.find { |line| line =~ /\ARails::Initializer/ }
0
+ # index = environment_rb_lines.index(first_initializer_line)
0
+ # environment_rb_lines.insert(index, engines_boot_line + "\n\n")
0
+ # File.open(environment_rb_file, 'w') { |f| f.write environment_rb_lines }
0
- vendor_dir = File.join(test_app_dir, 'vendor')
0
- FileUtils.mkdir_p vendor_dir
0
- system "cd #{vendor_dir} && git clone --depth 1 git://github.com/rails/rails.git"
0
- system "ruby #{File.join(vendor_dir, 'rails', 'railties', 'bin', 'rails')} #{test_app_dir}"
0
+ def insert_line(line, options)
0
+ target_file = File.join(test_app_dir, options[:into])
0
+ lines = File.readlines(target_file)
0
+ return if lines.include?(line)
0
+ if options[:after].is_a?(String)
0
+ after_line = options[:after] + "\n"
0
+ after_line = lines.find { |l| l =~ options[:after] }
0
+ raise "couldn't find a line matching #{options[:after].inspect} in #{target_file}" unless after_line
0
+ index = lines.index(after_line)
0
+ raise "couldn't find line '#{after_line}' in #{target_file}" unless index
0
+ lines.insert(index + 1, line)
0
-
system "rails #{test_app_dir}"0
+ File.open(target_file, 'w') { |f| f.write lines.join }
0
+ def mirror_test_files(src, dest=nil)
0
+ destination_dir = File.join(*([test_app_dir, dest].compact))
0
+ FileUtils.cp_r(File.join(File.dirname(__FILE__), 'test', src), destination_dir)
0
+ desc 'Update the plugin and tests files in the test application from the plugin'
0
+ task :mirror_engine_files => [:copy_engines_plugin] do
0
+ insert_line("require File.join(File.dirname(__FILE__), '../vendor/plugins/engines/boot')",
0
+ :into => 'config/environment.rb',
0
+ :after => "require File.join(File.dirname(__FILE__), 'boot')")
0
+ insert_line('map.from_plugin :test_routing', :into => 'config/routes.rb',
0
+ :after => /\AActionController::Routing::Routes/)
0
+ insert_line("require 'engines_test_helper'", :into => 'test/test_helper.rb')
0
mirror_test_files('app')
0
mirror_test_files('lib')
0
mirror_test_files('plugins', 'vendor')
0
mirror_test_files('unit', 'test')
0
mirror_test_files('functional', 'test')
0
- append_engines_test_helper
0
- insert_engines_boot_loader_line
0
- FileUtils.cp(File.join(File.dirname(__FILE__), *%w[test schema.rb]),
0
- File.join(test_app_dir, 'db'))
0
- system "cd #{test_app_dir} && rake db:schema:load"
0
desc 'Prepare the engines test environment'
0
- task :prepare => [:clean, :generate_app, :prepare_app]
0
\ No newline at end of file
0
+ task :prepare => [:clean, :generate_app, :mirror_engine_files]
0
+task :test => "test:prepare" do
0
+ exec("cd #{test_app_dir} && rake db:schema:load && rake")
Comments
No one has commented yet.