1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add the ability to have plugins load rake tasks.

This commit is contained in:
Carl Lerche 2009-12-28 16:21:48 -08:00
parent 9a650a6547
commit c02f278263
3 changed files with 42 additions and 0 deletions

View file

@ -72,7 +72,12 @@ module Rails
def load_tasks def load_tasks
require "rails/tasks" require "rails/tasks"
# Load all extension rake tasks
plugins.each(&:load_tasks)
# Load all plugin tasks
Dir["#{root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext } Dir["#{root}/vendor/plugins/*/**/tasks/**/*.rake"].sort.each { |ext| load ext }
# Load all application tasks
# TODO: extract out the path to the rake tasks
Dir["#{root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext } Dir["#{root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
task :environment do task :environment do
$rails_rake_task = true $rails_rake_task = true

View file

@ -25,6 +25,16 @@ module Rails
Configuration.default Configuration.default
end end
def self.rake_tasks(&blk)
@rake_tasks ||= []
@rake_tasks << blk
end
def self.load_tasks
return unless @rake_tasks
@rake_tasks.each { |blk| blk.call }
end
# Creates an initializer which includes all given modules to the given class. # Creates an initializer which includes all given modules to the given class.
# #
# module Rails # module Rails

View file

@ -2,6 +2,33 @@ require "isolation/abstract_unit"
module PluginsTest module PluginsTest
class FrameworkExtensionTest < Test::Unit::TestCase class FrameworkExtensionTest < Test::Unit::TestCase
def setup
build_app
boot_rails
require "rails"
end
test "rake_tasks block is executed when MyApp.load_tasks is called" do
$ran_block = false
class MyPlugin < Rails::Plugin
rake_tasks do
$ran_block = true
end
end
require "#{app_path}/config/environment"
assert !$ran_block
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
AppTemplate::Application.load_tasks
assert $ran_block
end
end
class ActiveRecordExtensionTest < Test::Unit::TestCase
def setup def setup
build_app build_app
boot_rails boot_rails