mirror of https://github.com/rails/rails
Make console and generators blocks works at Application instance level
Like rake tasks and runner blocks these blocks should also being shared between applications since they are stored at the classes. Fixes #14748
This commit is contained in:
parent
e8c66288d6
commit
43f525031a
|
@ -1,3 +1,9 @@
|
|||
* Fix `console` and `generators` blocks defined at different environments.
|
||||
|
||||
Fixes #14748.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Move configuration of asset precompile list and version to an initializer.
|
||||
|
||||
*Matthew Draper*
|
||||
|
|
|
@ -231,6 +231,18 @@ module Rails
|
|||
self.class.runner(&blk)
|
||||
end
|
||||
|
||||
# Sends any console called in the instance of a new application up
|
||||
# to the +console+ method defined in Rails::Railtie.
|
||||
def console(&blk)
|
||||
self.class.console(&blk)
|
||||
end
|
||||
|
||||
# Sends any generators called in the instance of a new application up
|
||||
# to the +generators+ method defined in Rails::Railtie.
|
||||
def generators(&blk)
|
||||
self.class.generators(&blk)
|
||||
end
|
||||
|
||||
# Sends the +isolate_namespace+ method up to the class method.
|
||||
def isolate_namespace(mod)
|
||||
self.class.isolate_namespace(mod)
|
||||
|
|
|
@ -803,5 +803,81 @@ module ApplicationTests
|
|||
|
||||
assert_not_nil SourceAnnotationExtractor::Annotation.extensions[/\.(coffee)$/]
|
||||
end
|
||||
|
||||
test "rake_tasks block works at instance level" do
|
||||
$ran_block = false
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
rake_tasks do
|
||||
$ran_block = true
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
|
||||
assert !$ran_block
|
||||
require 'rake'
|
||||
require 'rake/testtask'
|
||||
require 'rdoc/task'
|
||||
|
||||
Rails.application.load_tasks
|
||||
assert $ran_block
|
||||
end
|
||||
|
||||
test "generators block works at instance level" do
|
||||
$ran_block = false
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
generators do
|
||||
$ran_block = true
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
|
||||
assert !$ran_block
|
||||
Rails.application.load_generators
|
||||
assert $ran_block
|
||||
end
|
||||
|
||||
test "console block works at instance level" do
|
||||
$ran_block = false
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
console do
|
||||
$ran_block = true
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
|
||||
assert !$ran_block
|
||||
Rails.application.load_console
|
||||
assert $ran_block
|
||||
end
|
||||
|
||||
test "runner block works at instance level" do
|
||||
$ran_block = false
|
||||
|
||||
app_file "config/environments/development.rb", <<-RUBY
|
||||
Rails.application.configure do
|
||||
runner do
|
||||
$ran_block = true
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
|
||||
require "#{app_path}/config/environment"
|
||||
|
||||
assert !$ran_block
|
||||
Rails.application.load_runner
|
||||
assert $ran_block
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -122,6 +122,26 @@ module ApplicationTests
|
|||
assert_equal 3, $run_count, "There should have been three initializers that incremented the count"
|
||||
end
|
||||
|
||||
def test_consoles_run_on_different_applications_go_to_the_same_class
|
||||
$run_count = 0
|
||||
AppTemplate::Application.console { $run_count += 1 }
|
||||
AppTemplate::Application.new.console { $run_count += 1 }
|
||||
|
||||
assert_equal 0, $run_count, "Without loading the consoles, the count should be 0"
|
||||
Rails.application.load_console
|
||||
assert_equal 2, $run_count, "There should have been two consoles that increment the count"
|
||||
end
|
||||
|
||||
def test_generators_run_on_different_applications_go_to_the_same_class
|
||||
$run_count = 0
|
||||
AppTemplate::Application.generators { $run_count += 1 }
|
||||
AppTemplate::Application.new.generators { $run_count += 1 }
|
||||
|
||||
assert_equal 0, $run_count, "Without loading the generators, the count should be 0"
|
||||
Rails.application.load_generators
|
||||
assert_equal 2, $run_count, "There should have been two generators that increment the count"
|
||||
end
|
||||
|
||||
def test_runners_run_on_different_applications_go_to_the_same_class
|
||||
$run_count = 0
|
||||
AppTemplate::Application.runner { $run_count += 1 }
|
||||
|
|
Loading…
Reference in New Issue