Calling rake task within other rake tasks

and blocking non-test environments for safety…

namespace :db do
  desc 'Rebuild test database and load seeds'
  task rebuild: [:environment] do
    fail ArgumentError, 'Test Environment required' unless Rails.env.test?
    Rake::Task['db:drop'].invoke
    Rake::Task['db:create'].invoke
    Rake::Task['db:schema:load'].invoke
    Rake::Task['db:migrate'].invoke
    Rake::Task['db:seed'].invoke
  end
end