lib/refinery/tasks/testing.rake in refinerycms-testing-2.0.8 vs lib/refinery/tasks/testing.rake in refinerycms-testing-2.0.9
- old
+ new
@@ -1,19 +1,30 @@
namespace :refinery do
namespace :testing do
desc "Generates a dummy app for testing"
- task :dummy_app => [:setup_dummy_app, :setup_extension, "extension:setup"]
+ task :dummy_app do
+ unless dummy_app_path.exist?
+ Rake::Task["refinery:testing:setup_dummy_app"].invoke
+ Rake::Task["refinery:testing:setup_extension"].invoke
+ Rake::Task["refinery:testing:init_test_database"].invoke
+ end
+ end
task :setup_dummy_app do
require 'refinerycms'
params = %w(--quiet)
params << "--database=#{ENV['DB']}" if ENV['DB']
Refinery::DummyGenerator.start params
+ # Ensure the database is not there from a previous run.
+ Rake::Task['refinery:testing:drop_dummy_app_database'].invoke
+
Refinery::CmsGenerator.start %w[--quiet --fresh-installation]
+
+ Dir.chdir dummy_app_path
end
# This task is a hook to allow extensions to pass configuration
# Just define this inside your extension's Rakefile or a .rake file
# and pass arbitrary code. Example:
@@ -29,23 +40,24 @@
task :setup_extension do
end
desc "Remove the dummy app used for testing"
task :clean_dummy_app do
- path = Refinery::Testing::Railtie.target_extension_path.join('spec', 'dummy')
+ Rake::Task['refinery:testing:drop_dummy_app_database'].invoke
+ dummy_app_path.rmtree if dummy_app_path.exist?
+ end
- path.rmtree if path.exist?
+ desc "Remove the dummy app's database."
+ task :drop_dummy_app_database do
+ load 'rails/tasks/engine.rake'
+ Rake::Task['app:db:drop'].invoke
end
- namespace :extension do
- desc "Initialize the testing environment"
- task :setup => [:init_test_database]
+ task :init_test_database do
+ system "bundle exec rake -f #{dummy_app_path.join('Rakefile')} db:test:prepare"
+ end
- task :init_test_database do
- task_params = [%Q{ bundle exec rake -f #{Refinery::Testing::Railtie.target_extension_path.join('Rakefile')} }]
- task_params << %Q{ app:db:test:prepare }
-
- system task_params.join(' ')
- end
+ def dummy_app_path
+ Refinery::Testing::Railtie.target_extension_path.join('spec', 'dummy')
end
end
end