mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure that generators can be invoked from any directory.
Signed-off-by: Engine Yard <engineyard@Engine-Yards-MacBook-Pro.local>
This commit is contained in:
parent
2378085023
commit
d226f17507
3 changed files with 28 additions and 6 deletions
|
@ -12,6 +12,16 @@ module Rails
|
|||
|
||||
add_runtime_options!
|
||||
|
||||
# Always move to rails source root.
|
||||
#
|
||||
def initialize(*args) #:nodoc:
|
||||
if !invoked?(args) && defined?(Rails.root) && Rails.root
|
||||
self.destination_root = Rails.root
|
||||
FileUtils.cd(destination_root)
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
# Automatically sets the source root based on the class name.
|
||||
#
|
||||
def self.source_root
|
||||
|
@ -247,6 +257,13 @@ module Rails
|
|||
end
|
||||
end
|
||||
|
||||
# Check if this generator was invoked from another one by inspecting
|
||||
# parameters.
|
||||
#
|
||||
def invoked?(args)
|
||||
args.last.is_a?(Hash) && args.last.key?(:invocations)
|
||||
end
|
||||
|
||||
# Use Rails default banner.
|
||||
#
|
||||
def self.banner
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
# TODO: Fix this RAILS_ENV stuff
|
||||
RAILS_ENV = 'test'
|
||||
|
||||
RAILS_ENV = 'test' unless defined?(RAILS_ENV)
|
||||
require 'abstract_unit'
|
||||
Rails.application.config.root = File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
|
||||
|
||||
module Rails
|
||||
def self.root
|
||||
@root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'fixtures'))
|
||||
end
|
||||
end
|
||||
Rails.application.config.root = Rails.root
|
||||
|
||||
require 'rails/generators'
|
||||
require 'rubygems'
|
||||
require 'active_record'
|
||||
|
@ -15,8 +21,7 @@ class GeneratorsTestCase < Test::Unit::TestCase
|
|||
include FileUtils
|
||||
|
||||
def destination_root
|
||||
@destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
|
||||
'..', 'fixtures', 'tmp'))
|
||||
File.join(Rails.root, "tmp")
|
||||
end
|
||||
|
||||
def setup
|
||||
|
|
|
@ -105,7 +105,7 @@ class GeneratorsTest < GeneratorsTestCase
|
|||
end
|
||||
|
||||
def test_warning_is_shown_if_generator_cant_be_loaded
|
||||
Rails::Generators.load_paths << File.expand_path("../fixtures/vendor/gems/gems/wrong", __FILE__)
|
||||
Rails::Generators.load_paths << File.join(Rails.root, "vendor", "gems", "gems", "wrong")
|
||||
output = capture(:stderr){ Rails::Generators.find_by_namespace(:wrong) }
|
||||
assert_match /\[WARNING\] Could not load generator at/, output
|
||||
assert_match /Error: uninitialized constant Rails::Generator/, output
|
||||
|
|
Loading…
Reference in a new issue