Skip to content
Browse files

Load rake tasks defined in superclasses in context of railties

  • Loading branch information...
1 parent 8636f64 commit b417cfbf01a17be7216d09e447f37bf1c19e4cb2 @drogus drogus committed Oct 9, 2010
Showing with 31 additions and 0 deletions.
  1. +7 −0 railties/lib/rails/railtie.rb
  2. +24 −0 railties/test/railties/railtie_test.rb
View
7 railties/lib/rails/railtie.rb
@@ -191,6 +191,13 @@ def load_console
def load_tasks
self.class.rake_tasks.each(&:call)
+
+ # load also tasks from all superclasses
+ klass = self.class.superclass
+ while klass.respond_to?(:rake_tasks)
+ klass.rake_tasks.each { |t| self.instance_exec(&t) }
+ klass = klass.superclass
+ end
end
def load_generators
View
24 railties/test/railties/railtie_test.rb
@@ -103,6 +103,30 @@ class MyTie < Rails::Railtie
assert $ran_block
end
+ test "rake_tasks block defined in superclass of railtie is also executed" do
+ $ran_block = []
+
+ class Rails::Railtie
+ rake_tasks do
+ $ran_block << railtie_name
+ end
+ end
+
+ class MyTie < Rails::Railtie
+ railtie_name "my_tie"
+ end
+
+ require "#{app_path}/config/environment"
+
+ assert_equal [], $ran_block
+ require 'rake'
+ require 'rake/testtask'
+ require 'rake/rdoctask'
+
+ AppTemplate::Application.load_tasks
+ assert $ran_block.include?("my_tie")
+ end
+
test "generators block is executed when MyApp.load_generators is called" do
$ran_block = false

0 comments on commit b417cfb

Please sign in to comment.
Something went wrong with that request. Please try again.