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:
parent
9a650a6547
commit
c02f278263
3 changed files with 42 additions and 0 deletions
|
@ -72,7 +72,12 @@ module Rails
|
|||
|
||||
def load_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 }
|
||||
# Load all application tasks
|
||||
# TODO: extract out the path to the rake tasks
|
||||
Dir["#{root}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
|
||||
task :environment do
|
||||
$rails_rake_task = true
|
||||
|
|
|
@ -25,6 +25,16 @@ module Rails
|
|||
Configuration.default
|
||||
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.
|
||||
#
|
||||
# module Rails
|
||||
|
|
|
@ -2,6 +2,33 @@ require "isolation/abstract_unit"
|
|||
|
||||
module PluginsTest
|
||||
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
|
||||
build_app
|
||||
boot_rails
|
||||
|
|
Loading…
Reference in a new issue